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

Method _onMessage

server/index.js:52–79  ·  view source on GitHub ↗
(sender, message)

Source from the content-addressed store, hash-verified

50 }
51
52 _onMessage(sender, message) {
53 // Try to parse message
54 try {
55 message = JSON.parse(message);
56 } catch (e) {
57 return; // TODO: handle malformed JSON
58 }
59
60 switch (message.type) {
61 case 'disconnect':
62 this._leaveRoom(sender);
63 break;
64 case 'pong':
65 sender.lastBeat = Date.now();
66 break;
67 }
68
69 // relay message to recipient
70 if (message.to && this._rooms[sender.ip]) {
71 const recipientId = message.to; // TODO: sanitize
72 const recipient = this._rooms[sender.ip][recipientId];
73 delete message.to;
74 // add sender id
75 message.sender = sender.id;
76 this._send(recipient, message);
77 return;
78 }
79 }
80
81 _joinRoom(peer) {
82 // if room doesn't exist, create it

Callers 1

_onConnectionMethod · 0.95

Calls 2

_leaveRoomMethod · 0.95
_sendMethod · 0.95

Tested by

no test coverage detected