-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiChannel.js
38 lines (31 loc) · 958 Bytes
/
multiChannel.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
var ws = require('ws');
const token = '0123456789';
const user = { id: 123 };
// var live = {}; // { 'broadcastId': { userId: 'userId', viewers: ['userId', 'userId'] } }
// var broadcast = {}; // { 'userId': ['broadcastId', 'broadcastId'] }
module.exports = (server) => {
var wss = new ws.Server({
server: server,
path: '/init',
verifyClient: (info, cb) => {
if (info.req.headers.token === token) {
info.req.user = user;
cb(true);
} else {
cb(false, 401, 'Unauthorized');
}
}
});
wss.on('connection', (ws) => {
var user = conn.upgradeReq.user;
ws.on('error', (error) => {
console.log('Error', error);
});
ws.on('close', () => {
//
});
ws.on('message', (_message) => {
var message = JSON.parse(_message);
});
});
};