-
Notifications
You must be signed in to change notification settings - Fork 27
/
rtc.js
44 lines (39 loc) · 1.08 KB
/
rtc.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
module.exports=(function(webRTC){
var sanitize= require('validator').sanitize;
webRTC.rtc.on('connect', function(rtc) {
console.log("someone connected");
//Client connected
});
webRTC.rtc.on('send answer', function(rtc) {
//answer sent
console.log("Answer sent");
});
webRTC.rtc.on('disconnect', function(rtc) {
//Client disconnect
});
webRTC.rtc.on('chat_msg', function(data, socket) {
console.log("HERE");
console.log(data);
var roomList = webRTC.rtc.rooms[data.room] || [];
console.log(roomList);
for (var i = 0; i < roomList.length; i++) {
var socketId = roomList[i];
if (socketId !== socket.id) {
var soc = webRTC.rtc.getSocket(socketId);
if (soc) {
soc.send(JSON.stringify({
"eventName": "receive_chat_msg",
"data": {
"msg": sanitize(data.msg).xss(),
"nick":sanitize(data.nick).xss()
}
}), function(error) {
if (error) {
console.log(error);
}
});
}
}
}
});
})