// Load required modules
var http = require("http"); // http server core module
var express = require("express"); // web framework external module
var io = require("socket.io"); // web socket external module var easyrtc = require("easyrtc"); // EasyRTC external module
// Setup and configure Express http server. Expect a subfolder called "static" to be the web root.
var httpApp = express();
httpApp.use(express.static(__dirname + "/static/"));
// Start Express http server on port 8080
var webServer = http.createServer(httpApp).listen(8080);
// Start Socket.io so it attaches itself to Express server
var socketServer = io.listen(webServer, {"log level":1});
// On Authenticated gets run after a peer has completed the authentication process
var onAuthenticated = function(connectionObj, next){
console.log(
"["
+ connectionObj.getEasyrtcid()
+ "]["
+ connectionObj.getUsername()
+ "] Authenticated"
);
next();
};
easyrtc.on("authenticated", onAuthenticated);
// On Disconnect is called after a peer has disconnected.
// Note this one should have the emitDefault run instead of next() (performs cleanup)
var onDisconnect = function(connectionObj, next){
console.log(
"["
+ connectionObj.getEasyrtcid()
+ "]["
+ connectionObj.getUsername()
+ "] Disconnected"
);
easyrtc.events.emitDefault("disconnect", connectionObj, next);
};
easyrtc.on("disconnect", onDisconnect);
// Start EasyRTC server
var rtc = easyrtc.listen(httpApp, socketServer);