forked from webRTC-io/webrtc.io-demo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
66 lines (50 loc) · 1.38 KB
/
server.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var app = require('express')();
var server = require('http').createServer(app);
var webRTC = require('webrtc.io').listen(server);
server.listen(80);
app.get('/', function(req, res) {
res.sendfile(__dirname + '/index.html');
});
app.get('/style.css', function(req, res) {
res.sendfile(__dirname + '/style.css');
});
app.get('/fullscrean.png', function(req, res) {
res.sendfile(__dirname + '/fullscrean.png');
});
app.get('/script.js', function(req, res) {
res.sendfile(__dirname + '/script.js');
});
app.get('/webrtc.io.js', function(req, res) {
res.sendfile(__dirname + '/webrtc.io.js');
});
webRTC.rtc.on('connect', function(rtc) {
//Client connected
});
webRTC.rtc.on('send answer', function(rtc) {
//answer sent
});
webRTC.rtc.on('disconnect', function(rtc) {
//Client disconnect
});
webRTC.rtc.on('chat_msg', function(data, socket) {
var roomList = webRTC.rtc.rooms[data.room] || [];
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": {
"messages": data.messages,
"color": data.color
}
}), function(error) {
if (error) {
console.log(error);
}
});
}
}
}
});