forked from motepair/motepair-server
-
Notifications
You must be signed in to change notification settings - Fork 3
/
message_handler.js
41 lines (33 loc) · 1.07 KB
/
message_handler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Generated by CoffeeScript 1.8.0
(function() {
var MessageHandler;
MessageHandler = (function() {
MessageHandler.prototype.lastMessages = {};
function MessageHandler(conn) {
this.conn = conn;
}
MessageHandler.prototype.broadcast = function(type, data, connections) {
var senderId;
if (JSON.stringify(data) === JSON.stringify(this.lastMessages[this.conn.sessionId])) {
return;
}
this.lastMessages[this.conn.sessionId] = data;
senderId = this.conn.getId();
return connections.forEach(function(conn) {
var id;
id = conn.getId();
if (senderId !== id) {
return conn.send(JSON.stringify(data));
}
});
};
MessageHandler.prototype.handle = function(data, connections) {
var _ref;
if ((_ref = data.type) === 'open' || _ref === 'close' || _ref === 'save' || _ref === 'select' || _ref === 'cursor') {
return this.broadcast(data.type, data, connections);
}
};
return MessageHandler;
})();
module.exports = MessageHandler;
}).call(this);