-
Notifications
You must be signed in to change notification settings - Fork 12
/
webserver.js
73 lines (60 loc) · 2.7 KB
/
webserver.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
67
68
69
70
71
72
73
// Quick web server written in order to comply
// with the Chrome extension HTTPS requirements
var express = require("express")
, app = express()
, path = require("path")
, fs = require('fs')
, io = require('socket.io')
, easyrtc = require('easyrtc')
, http = require("http").createServer(app).listen(80)
, https = require("https").createServer({
key: fs.readFileSync('server.key'),
cert: fs.readFileSync('server.crt')
}, app).listen(443)
, ioserv = io.listen(https, {"log level":1});
app.use('/', express.static(path.join(__dirname, 'WebScreen')));
console.log("Local web server launched on HTTP & HTTPS.");
var myIceServers = [
{"url":"stun:stun.l.google.com:19302"},
{"url":"stun:stun1.l.google.com:19302"},
{"url":"stun:stun2.l.google.com:19302"},
{"url":"stun:stun3.l.google.com:19302"}
// {
// "url":"turn:[ADDRESS]:[PORT]",
// "username":"[USERNAME]",
// "credential":"[CREDENTIAL]"
// },
// {
// "url":"turn:[ADDRESS]:[PORT][?transport=tcp]",
// "username":"[USERNAME]",
// "credential":"[CREDENTIAL]"
// }
];
easyrtc.setOption("appIceServers", myIceServers);
easyrtc.setOption("logLevel", "debug");
easyrtc.setOption("demosEnable", false);
// Overriding the default easyrtcAuth listener, only so we can directly access its callback
easyrtc.events.on("easyrtcAuth", function(socket, easyrtcid, msg, socketCallback, callback) {
easyrtc.events.defaultListeners.easyrtcAuth(socket, easyrtcid, msg, socketCallback, function(err, connectionObj){
if (err || !msg.msgData || !msg.msgData.credential || !connectionObj) {
callback(err, connectionObj);
return;
}
connectionObj.setField("credential", msg.msgData.credential, {"isShared":false});
console.log("["+easyrtcid+"] Credential saved!", connectionObj.getFieldValueSync("credential"));
callback(err, connectionObj);
});
});
// To test, lets print the credential to the console for every room join!
easyrtc.events.on("roomJoin", function(connectionObj, roomName, roomParameter, callback) {
console.log("["+connectionObj.getEasyrtcid()+"] Credential retrieved!", connectionObj.getFieldValueSync("credential"));
easyrtc.events.defaultListeners.roomJoin(connectionObj, roomName, roomParameter, callback);
});
// Start EasyRTC server
var rtc = easyrtc.listen(app, ioserv, null, function(err, rtcRef) {
console.log("Local WebRTC server launched!");
rtcRef.events.on("roomCreate", function(appObj, creatorConnectionObj, roomName, roomOptions, callback) {
console.log("roomCreate fired! Trying to create: " + roomName);
appObj.events.defaultListeners.roomCreate(appObj, creatorConnectionObj, roomName, roomOptions, callback);
});
});