1 | var _ = require("underscore");
|
2 |
|
3 | module.exports = function(io) {
|
4 | var eventQueue = {
|
5 |
|
6 | latestEvents: {},
|
7 |
|
8 | initialize: function(io) {
|
9 | var that = this;
|
10 |
|
11 | io.of("/widgets").on("connection", function(socket) {
|
12 | socket.on("resend", function (data) {
|
13 | if (that.latestEvents[data]) {
|
14 | socket.emit(data, that.latestEvents[data]);
|
15 | }
|
16 | });
|
17 | });
|
18 |
|
19 |
|
20 | io.of("/log").on("connection", function(socket) {
|
21 | socket.on("log", function (data) {
|
22 | socket.broadcast.emit('client', data);
|
23 | });
|
24 | });
|
25 |
|
26 | },
|
27 |
|
28 | send: function(id, data) {
|
29 | this.latestEvents[id] = data;
|
30 | io.of("/widgets").emit(id, data);
|
31 | io.of("/log").emit('client', {widgetId : id, data: data});
|
32 | }
|
33 | };
|
34 | eventQueue.initialize(io);
|
35 | return eventQueue;
|
36 | }; |
\ | No newline at end of file |