Commit 04ea4e50 authored by Moritz Langenstein's avatar Moritz Langenstein
Browse files

(ml5717) Send temporary TURN servers on offer, join and clients

parent 95e2da85
......@@ -27,8 +27,9 @@ function signalbuddy(server, config) {
io.on('connection', function (client) {
client.resources = {
screen: false,
video: true,
audio: false
video: false,
audio: false,
data: true
};
// pass a message to another id
......@@ -37,6 +38,9 @@ function signalbuddy(server, config) {
var otherClient = io.to(details.to);
if (!otherClient) return;
details.from = client.id;
if (details.type === 'offer') {
details.turnservers = getTurnServers(details.to + ".." + client.id);
}
otherClient.emit('message', details);
});
......@@ -82,7 +86,7 @@ function signalbuddy(server, config) {
describeRoom(roomName).then(function (description) {
var obj = { clients: {} };
description.forEach(function (k) {
obj.clients[k] = client.resources;
obj.clients[k] = Object.assign({}, client.resources, { turnservers: getTurnServers(client.id + ".." + k) });
});
(0, _util.safeCb)(callback)(null, obj);
}).catch(function (err) {
......@@ -133,9 +137,9 @@ function signalbuddy(server, config) {
return [(0, _normalice2.default)('stun:' + config.ice.stun.username + ':' + config.ice.stun.password + '@' + config.ice.host + ':' + config.ice.port)];
}
function getTurnServers() {
function getTurnServers(username) {
// See https://github.com/coturn/coturn/wiki/turnserver#turn-rest-api for details
var acting_ice_turn_username = Math.floor(Date.now() / 1000) + config.ice.turn.timeout + "-" + config.ice.stun.username;
var acting_ice_turn_username = Math.floor(Date.now() / 1000) + config.ice.turn.timeout + "-" + username;
var acting_ice_turn_password = _crypto2.default.createHmac('sha1', config.ice.turn.secret).update(acting_ice_turn_username).digest('base64');
return [(0, _normalice2.default)('turn:' + acting_ice_turn_username + ':' + acting_ice_turn_password + '@' + config.ice.host + ':' + config.ice.port)];
......@@ -145,8 +149,8 @@ function signalbuddy(server, config) {
(0, _util.safeCb)(cb)(null, getStunServers());
});
client.on('turnservers', function (cb) {
(0, _util.safeCb)(cb)(null, getTurnServers());
client.on('turnservers', function (username, cb) {
(0, _util.safeCb)(cb)(null, getTurnServers(username));
});
client.emit('stunservers', getStunServers());
......
......@@ -9,8 +9,9 @@ function signalbuddy(server, config) {
io.on('connection', (client) => {
client.resources = {
screen: false,
video: true,
audio: false
video: false,
audio: false,
data: true,
};
// pass a message to another id
......@@ -19,6 +20,9 @@ function signalbuddy(server, config) {
const otherClient = io.to(details.to);
if (!otherClient) return;
details.from = client.id;
if (details.type === 'offer') {
details.turnservers = getTurnServers(details.to + ".." + client.id)
}
otherClient.emit('message', details);
});
......@@ -64,7 +68,7 @@ function signalbuddy(server, config) {
.then((description) => {
const obj = { clients: {} };
description.forEach((k) => {
obj.clients[k] = client.resources;
obj.clients[k] = Object.assign({}, client.resources, { turnservers: getTurnServers(client.id + ".." + k) });
});
safeCb(callback)(null, obj);
})
......@@ -115,9 +119,9 @@ function signalbuddy(server, config) {
return [normalice(`stun:${config.ice.stun.username}:${config.ice.stun.password}@${config.ice.host}:${config.ice.port}`)]
}
function getTurnServers() {
function getTurnServers(username) {
// See https://github.com/coturn/coturn/wiki/turnserver#turn-rest-api for details
const acting_ice_turn_username = (Math.floor(Date.now() / 1000) + config.ice.turn.timeout) + "-" + config.ice.stun.username
const acting_ice_turn_username = (Math.floor(Date.now() / 1000) + config.ice.turn.timeout) + "-" + username
const acting_ice_turn_password = crypto.createHmac('sha1', config.ice.turn.secret).update(acting_ice_turn_username).digest('base64')
return [normalice(`turn:${acting_ice_turn_username}:${acting_ice_turn_password}@${config.ice.host}:${config.ice.port}`)]
......@@ -127,8 +131,8 @@ function signalbuddy(server, config) {
safeCb(cb)(null, getStunServers())
});
client.on('turnservers', (cb) => {
safeCb(cb)(null, getTurnServers())
client.on('turnservers', (username, cb) => {
safeCb(cb)(null, getTurnServers(username))
});
client.emit('stunservers', getStunServers())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment