-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocketAPI.js
More file actions
29 lines (25 loc) · 730 Bytes
/
Copy pathsocketAPI.js
File metadata and controls
29 lines (25 loc) · 730 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
var socket_io = require('socket.io');
var io = socket_io();
var socketApi = {};
socketApi.io = io;
io.path('/socket');
io.on('connection', function(socket){
socket.on('join_room', function(room) {
console.log('joinging room', room);
socket.join(room);
});
socket.on('leave_room', function(room) {
console.log('leaving room', room);
socket.leave(room);
});
});
socketApi.sendNotification = function(event, payload, recipients = null) {
if(recipients && recipients.length) {
recipients.forEach(recipient => {
io.sockets.in(recipient).emit(event, payload);
})
} else {
io.sockets.emit(event, payload);
}
}
module.exports = socketApi;