MCPcopy
hub / github.com/SnapDrop/snapdrop / _leaveRoom

Method _leaveRoom

server/index.js:111–129  ·  view source on GitHub ↗
(peer)

Source from the content-addressed store, hash-verified

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;

Callers 2

_onMessageMethod · 0.95
_keepAliveMethod · 0.95

Calls 2

_cancelKeepAliveMethod · 0.95
_sendMethod · 0.95

Tested by

no test coverage detected