forked from LingyuCoder/SkyRTC-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
46 lines (35 loc) · 1.24 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
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var SkyRTC = require('skyrtc').listen(server);
var path = require("path");
var port = process.env.PORT || 3000;
server.listen(port);
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', function(req, res) {
res.sendfile(__dirname + '/index.html');
});
SkyRTC.rtc.on('new_connect', function(socket) {
console.log('创建新连接');
});
SkyRTC.rtc.on('remove_peer', function(socketId) {
console.log(socketId + "用户离开");
});
SkyRTC.rtc.on('new_peer', function(socket, room) {
console.log("新用户" + socket.id + "加入房间" + room);
});
SkyRTC.rtc.on('socket_message', function(socket, msg) {
console.log("接收到来自" + socket.id + "的新消息:" + msg);
});
SkyRTC.rtc.on('ice_candidate', function(socket, ice_candidate) {
console.log("接收到来自" + socket.id + "的ICE Candidate");
});
SkyRTC.rtc.on('offer', function(socket, offer) {
console.log("接收到来自" + socket.id + "的Offer");
});
SkyRTC.rtc.on('answer', function(socket, answer) {
console.log("接收到来自" + socket.id + "的Answer");
});
SkyRTC.rtc.on('error', function(error) {
console.log("发生错误:" + error.message);
});