(peer)
| 109 | } |
| 110 | |
| 111 | _leaveRoom(peer) { |
| 112 | if (!this._rooms[peer.ip] || !this._rooms[peer.ip][peer.id]) return; |
| 113 | this._cancelKeepAlive(this._rooms[peer.ip][peer.id]); |
| 114 | |
| 115 | // delete the peer |
| 116 | delete this._rooms[peer.ip][peer.id]; |
| 117 | |
| 118 | peer.socket.terminate(); |
| 119 | //if room is empty, delete the room |
| 120 | if (!Object.keys(this._rooms[peer.ip]).length) { |
| 121 | delete this._rooms[peer.ip]; |
| 122 | } else { |
| 123 | // notify all other peers |
| 124 | for (const otherPeerId in this._rooms[peer.ip]) { |
| 125 | const otherPeer = this._rooms[peer.ip][otherPeerId]; |
| 126 | this._send(otherPeer, { type: 'peer-left', peerId: peer.id }); |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | _send(peer, message) { |
| 132 | if (!peer) return; |
no test coverage detected