create private namespaces
This commit is contained in:
parent
1e62608188
commit
9fd8ac7969
@ -22,6 +22,20 @@ module.exports = io => {
|
|||||||
sendNamespaces()
|
sendNamespaces()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
socket.on('chat', id => {
|
||||||
|
const target = io.sockets.sockets[id]
|
||||||
|
if (!target || socket.id === target.id) {
|
||||||
|
console.log('Not starting chat.', socket, target)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
console.log(`${socket.id} wants to chat with ${target.id}`)
|
||||||
|
|
||||||
|
// create a shared namespace
|
||||||
|
const namespace = `${socket.id.substr(0, 5)}.${target.id.substr(0, 5)}`
|
||||||
|
socket.join(namespace)
|
||||||
|
target.join(namespace)
|
||||||
|
sendNamespaces()
|
||||||
|
})
|
||||||
|
|
||||||
socket.on('part', () => {
|
socket.on('part', () => {
|
||||||
console.log('part')
|
console.log('part')
|
||||||
|
19
src/App.js
19
src/App.js
@ -106,6 +106,11 @@ class App extends React.Component {
|
|||||||
this.socket.emit('join', namespace)
|
this.socket.emit('join', namespace)
|
||||||
this.setState({ namespace })
|
this.setState({ namespace })
|
||||||
}
|
}
|
||||||
|
query(user) {
|
||||||
|
console.log(`starting query with ${user}`)
|
||||||
|
this.socket.emit('chat', user)
|
||||||
|
this.setState({ namespace: user })
|
||||||
|
}
|
||||||
sendMessage(msg) {
|
sendMessage(msg) {
|
||||||
this.socket.emit('message', msg)
|
this.socket.emit('message', msg)
|
||||||
}
|
}
|
||||||
@ -152,8 +157,14 @@ class App extends React.Component {
|
|||||||
</Dropdown.Toggle>
|
</Dropdown.Toggle>
|
||||||
|
|
||||||
<Dropdown.Menu className="bg-dark">
|
<Dropdown.Menu className="bg-dark">
|
||||||
{this.state.allUsers.map(u => (
|
{this.state.allUsers
|
||||||
<Dropdown.Item key={u} className="bg-dark text-light">
|
.filter(u => u !== socket.id)
|
||||||
|
.map(u => (
|
||||||
|
<Dropdown.Item
|
||||||
|
key={u}
|
||||||
|
className="bg-dark text-light"
|
||||||
|
onClick={() => this.query(u)}
|
||||||
|
>
|
||||||
{u}
|
{u}
|
||||||
</Dropdown.Item>
|
</Dropdown.Item>
|
||||||
))}
|
))}
|
||||||
@ -165,7 +176,9 @@ class App extends React.Component {
|
|||||||
</Dropdown.Toggle>
|
</Dropdown.Toggle>
|
||||||
|
|
||||||
<Dropdown.Menu className="bg-dark">
|
<Dropdown.Menu className="bg-dark">
|
||||||
{this.state.namespaces.map(r => (
|
{this.state.namespaces
|
||||||
|
.filter(n => n.namespace[0] === '#')
|
||||||
|
.map(r => (
|
||||||
<Dropdown.Item
|
<Dropdown.Item
|
||||||
key={r.namespace}
|
key={r.namespace}
|
||||||
className="bg-dark text-light"
|
className="bg-dark text-light"
|
||||||
|
Loading…
Reference in New Issue
Block a user