(peer)
| 79 | } |
| 80 | |
| 81 | _joinRoom(peer) { |
| 82 | // if room doesn't exist, create it |
| 83 | if (!this._rooms[peer.ip]) { |
| 84 | this._rooms[peer.ip] = {}; |
| 85 | } |
| 86 | |
| 87 | // notify all other peers |
| 88 | for (const otherPeerId in this._rooms[peer.ip]) { |
| 89 | const otherPeer = this._rooms[peer.ip][otherPeerId]; |
| 90 | this._send(otherPeer, { |
| 91 | type: 'peer-joined', |
| 92 | peer: peer.getInfo() |
| 93 | }); |
| 94 | } |
| 95 | |
| 96 | // notify peer about the other peers |
| 97 | const otherPeers = []; |
| 98 | for (const otherPeerId in this._rooms[peer.ip]) { |
| 99 | otherPeers.push(this._rooms[peer.ip][otherPeerId].getInfo()); |
| 100 | } |
| 101 | |
| 102 | this._send(peer, { |
| 103 | type: 'peers', |
| 104 | peers: otherPeers |
| 105 | }); |
| 106 | |
| 107 | // add peer to room |
| 108 | this._rooms[peer.ip][peer.id] = peer; |
| 109 | } |
| 110 | |
| 111 | _leaveRoom(peer) { |
| 112 | if (!this._rooms[peer.ip] || !this._rooms[peer.ip][peer.id]) return; |
no test coverage detected