-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket.js
More file actions
36 lines (30 loc) · 745 Bytes
/
socket.js
File metadata and controls
36 lines (30 loc) · 745 Bytes
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
var io = require("socket.io")(3001);
var stores = require('./stores');
io.on('connection', function (socket) {
socket.emit('connect-success');
socket.on('disconnect', function () {
console.log('disconnect');
});
socket.on('crawler-token', function (token) {
if (stores.getStore(token)) {
socket.join(token);
socket.emit('join-crawler-success');
} else {
socket.emit('join-crawler-failed');
}
});
});
function emit(room, data) {
console.info("Emitter of " + room + " is emitting" + JSON.stringify(data));
io.to(room).emit("data", data);
}
function getEmitter(room) {
return {
emit: function (data) {
emit(room, data);
},
};
}
module.exports = {
getEmitter: getEmitter,
};