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

Method _joinRoom

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

Source from the content-addressed store, hash-verified

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;

Callers 1

_onConnectionMethod · 0.95

Calls 2

_sendMethod · 0.95
getInfoMethod · 0.80

Tested by

no test coverage detected