1
0
mirror of https://github.com/dani/vroom.git synced 2024-06-23 01:59:13 +02:00

Rebase signal master to current GIT

This commit is contained in:
Daniel Berteaud 2014-05-30 12:01:34 +02:00
parent 05131716a6
commit 15ba0508fe
6 changed files with 73 additions and 27 deletions

View File

@ -6,8 +6,9 @@
"evil": true,
"white": true,
"undef": true,
"node": true,
"browser": true,
"predef": [
"app",
"$",
"FormBot",
"socket",

1
signalmaster/Procfile Normal file
View File

@ -0,0 +1 @@
web: node server.js

View File

@ -4,7 +4,9 @@ A simple signaling server for clients to connect and do signaling for WebRTC.
Specifically created as a default connection point for [SimpleWebRTC.js](https://github.com/HenrikJoreteg/SimpleWebRTC)
It also supports vending STUN/TURN servers with the shared secret mechanism as described in [this draft](http://tools.ietf.org/html/draft-uberti-behave-turn-rest-00).
Read more:
- [Introducing SimpleWebRTC and conversat.io](http://blog.andyet.com/2013/feb/22/introducing-simplewebrtcjs-and-conversatio/)
- [SimpleWebRTC.com](http://simplewebrtc.com)
- [conversat.io](http://conversat.io)
- [talky.io](https://talky.io)

View File

@ -1,8 +1,17 @@
{
"isDev": false,
"logLevel": 3,
"server": {
"port": 8888
},
/*"stunservers" : [
{"url": "stun:stun.l.google.com:19302"}
],
"turnservers" : [
{ "url": "turn:your.turn.server.here",
"secret": "turnserversharedsecret"
"expiry": 86400 }
]*/
"mysql": {
"server": "localhost",
"database": "vroom",

View File

@ -1,21 +1,17 @@
{
"name": "signal-master",
"version": "0.0.1",
"repository": {
"type": "git",
"url": "git@github.com:andyet/signal-master.git"
},
"description": "Mind-meldification for teams",
"description": "Simple signaling server for SimpleWebRTC",
"version": "0.1.0",
"dependencies": {
"async": "0.1.9",
"getconfig": "0.3.0",
"node-uuid": "1.2.0",
"redis": "",
"underscore": "",
"precommit-hook": "",
"getconfig": "",
"socket.io": "",
"mysql":"",
"cookie":""
"socket.io": "0.9.16",
"mysql": "",
"cookie": ""
},
"main": "server.js"
"main": "server.js",
"repository": {
"type": "git",
"url": "git@github.com:andyet/signal-master.git"
}
}

View File

@ -3,7 +3,9 @@ var config = require('getconfig'),
uuid = require('node-uuid'),
mysql = require('mysql'),
cookie_reader = require('cookie'),
io = require('socket.io').listen(config.server.port);
crypto = require('crypto'),
port = parseInt(process.env.PORT || config.server.port, 10),
io = require('socket.io').listen(port);
var sql = mysql.createConnection({
host : config.mysql.server,
@ -11,6 +13,11 @@ var sql = mysql.createConnection({
user : config.mysql.user,
password : config.mysql.password});
if (config.logLevel) {
// https://github.com/Automattic/socket.io/wiki/Configuring-Socket.IO
io.set('log level', config.logLevel);
}
function describeRoom(name) {
var clients = io.sockets.clients(name);
var result = {
@ -94,24 +101,30 @@ io.sockets.on('connection', function (client) {
client.on('unshareScreen', function (type) {
client.resources.screen = false;
if (client.room) removeFeed('screen');
removeFeed('screen');
});
client.on('join', join);
function removeFeed(type) {
io.sockets.in(client.room).emit('remove', {
id: client.id,
type: type
});
if (client.room) {
io.sockets.in(client.room).emit('remove', {
id: client.id,
type: type
});
if (!type) {
client.leave(client.room);
client.room = undefined;
}
}
}
function join(name, cb) {
// sanity check
if (typeof name !== 'string') return;
// leave any existing rooms
if (client.room) removeFeed();
safeCb(cb)(null, describeRoom(name))
removeFeed();
safeCb(cb)(null, describeRoom(name));
client.join(name);
client.room = name;
}
@ -121,7 +134,9 @@ io.sockets.on('connection', function (client) {
client.on('disconnect', function () {
removeFeed();
});
client.on('leave', removeFeed);
client.on('leave', function () {
removeFeed();
});
client.on('create', function (name, cb) {
if (arguments.length == 2) {
@ -139,7 +154,29 @@ io.sockets.on('connection', function (client) {
safeCb(cb)(null, name);
}
});
// tell client about stun and turn servers and generate nonces
if (config.stunservers) {
client.emit('stunservers', config.stunservers);
}
if (config.turnservers) {
// create shared secret nonces for TURN authentication
// the process is described in draft-uberti-behave-turn-rest
var credentials = [];
config.turnservers.forEach(function (server) {
var hmac = crypto.createHmac('sha1', server.secret);
// default to 86400 seconds timeout unless specified
var username = Math.floor(new Date().getTime() / 1000) + (server.expiry || 86400) + "";
hmac.update(username);
credentials.push({
username: username,
credential: hmac.digest('base64'),
url: server.url
});
});
client.emit('turnservers', credentials);
}
});
if (config.uid) process.setuid(config.uid);
console.log('signal master is running at: http://localhost:' + config.server.port);
console.log('signal master is running at: http://localhost:' + port);