Skip to content

Commit

Permalink
Updates for Edge.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Nov 21, 2018
1 parent 77fea87 commit 60fa5c2
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 34 deletions.
48 changes: 40 additions & 8 deletions app/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@
var ms = window.mediasoupClient;
var stream;

var showResolutionInterval;
function showResolution(video) {
if (showResolutionInterval) {
clearInterval(showResolutionInterval);
showResolutionInterval = undefined;
}

var res = document.querySelector('#res');
if (!video || !res) {
if (res) {
res.innerHTML = '0x0';
}
return;
}

function doShowResolution() {
res.innerHTML = video.videoWidth + 'x' + video.videoHeight;
};
doShowResolution();
showResolutionInterval = setInterval(doShowResolution, 1000);
}

var onActiveTimeout;
function setVideoSource(video, streamOrUrl) {
if (stream) {
Expand All @@ -22,10 +44,8 @@ function setVideoSource(video, streamOrUrl) {
stream = undefined;
}

var res = document.querySelector('#res');
if (res) {
res.innerHTML = '?x?';
}
// Cancel the timer.
showResolution();

if (onActiveTimeout) {
clearTimeout(onActiveTimeout);
Expand Down Expand Up @@ -78,9 +98,8 @@ function setVideoSource(video, streamOrUrl) {
}

video.oncanplay = function canPlay() {
if (res) {
res.innerHTML = video.videoWidth + 'x' + video.videoHeight;
}
// Prime the pump.
showResolution(video);
};
}

Expand Down Expand Up @@ -111,9 +130,22 @@ function pubsubClient(channel, password, isPublisher) {
ws.onopen = function onOpen() {
connected = true;
pending[++reqid] = function onPubsub(payload) {
var turnServers = payload.turnServers || [];
if (window.navigator && window.navigator.userAgent.match(/\sEdge\//)) {
// On Edge, having any secure turn (turns:...) URLs
// cause an InvalidAccessError, preventing connections.
turnServers = turnServers.map(function modServer(srv) {
var urls = srv.urls.filter(function modUrl(url) {
// Remove the turns: url.
return !url.match(/^turns:/);
});
return Object.assign({}, srv, {urls: urls});
});
}

room = new ms.Room({
requestTimeout: 8000,
turnServers: payload.turnServers || [],
turnServers: turnServers,
});

room.on('request', function onRequest(request, callback, errback) {
Expand Down
2 changes: 1 addition & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<tr>
<th>Channel:</th>
<td><input type="text" value="test" id="subChannel"/>
<span id="res">?x?</span></td>
<span id="res">0x0</span></td>
<td><input type="radio" name="prof" id="profHigh" value="high" checked="checked" /><label for="profHigh">High</label></td>
</tr>
<tr>
Expand Down
4 changes: 2 additions & 2 deletions app/mediasoup-client.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/publish.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<tr>
<th>Channel:</th>
<td><input type="text" value="test" id="pubChannel"/>
<span id="res">?x?</span></td>
<span id="res">0x0</span></td>
</tr>
<tr>
<th>Password:</th>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mediasoup-broadcast-example",
"version": "1.2.4",
"version": "1.2.5",
"description": "Sample WebRTC broadcast client/server for the Mediasoup SFU.",
"main": "server/index.js",
"scripts": {
Expand Down
48 changes: 27 additions & 21 deletions server/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,34 @@ const RECV_PASSWORD = process.env.RECV_PASSWORD || 'NotSecret';
const TURN_SERVERS = process.env.TURN_SERVERS ? process.env.TURN_SERVERS.split(',') : [];
const PASSWORD_EXPIRY_SECONDS = 300;

function getPayload(kind) {
const turnServers = TURN_SERVERS.map(
function addUserPassword(server) {
const key = process.env.TURN_AUTH_KEY;
if (key) {
// Return the TURN REST API credential.
const timestamp = Math.floor(Date.now() / 1000) + PASSWORD_EXPIRY_SECONDS;
const temporary_username = String(timestamp) + ':msbe';
const hmac = crypto.createHmac('sha1', key).update(temporary_username).digest('base64');
return {urls: [server],
username: temporary_username,
credential: hmac,
credentialType: 'password',
};
}
else {
// No credentials;
return {urls: [server]};
}
});

return {kind, turnServers};
function getTurnServers(urls, key) {
if (!urls.length) {
return [];
}
if (key) {
// Return the TURN REST API credential.
const timestamp = Math.floor(Date.now() / 1000) + PASSWORD_EXPIRY_SECONDS;
const temporary_username = String(timestamp) + ':msbe';
const hmac = crypto.createHmac('sha1', key).update(temporary_username).digest('base64');
return [{urls: urls,
username: temporary_username,
credential: hmac,
credentialType: 'password',
}];
}
else {
// No credentials;
return [{urls: urls}];
}
};


function getPayload(kind) {
return {
kind: kind,
turnServers: getTurnServers(TURN_SERVERS, process.env.TURN_AUTH_KEY)
};
}

function authorize(addr, channel, request) {
Expand Down

0 comments on commit 60fa5c2

Please sign in to comment.