-
Notifications
You must be signed in to change notification settings - Fork 3
/
sio_routes.js
49 lines (39 loc) · 1019 Bytes
/
sio_routes.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
42
43
44
45
46
47
48
49
/*!
* yellowtail - sio_routes.js
* Copyright(c) 2013
* Author: karen <karenpenglabs@gmail.com>
*/
'use strict';
var laptopId = [];
module.exports = function (sio) {
var pageOpen = 0;
sio.sockets.on('connection', function (socket) {
pageOpen++;
socket.emit('init', pageOpen);
socket.broadcast.emit('in', pageOpen);
socket.on('disconnect', function () {
pageOpen--;
socket.broadcast.emit('leave', pageOpen);
if (pageOpen === 0) {
laptopId = [];
}
});
socket.on('deviceData', function (data) {
if (!data.device) {
laptopId.push(socket.id);
}
});
socket.on('mobileWorm', function (data) {
laptopId.forEach(function (id) {
sio.sockets.socket(id).emit('hisMobileWorm', data);
});
});
socket.on('laptopWorm', function (data) {
laptopId.forEach(function (id) {
if (id !== socket.id) {
sio.sockets.socket(id).emit('hisLaptopWorm', data);
}
});
});
});
};