Created
March 7, 2014 17:12
-
-
Save colinmacdonald/9415537 to your computer and use it in GitHub Desktop.
GoRTC Turn server configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<script src="https://cdn.goinstant.net/v1/platform.min.js"></script> | |
<script type="text/javascript" src="https://cdn.goinstant.net/integrations/gortc/latest/gortc.min.js"></script> | |
<script src="example.js"></script> | |
</head> | |
<body onload="onLoad();"> | |
<div id="localVideoContainer"></div> | |
<div id="videoContainer"></div> | |
</body> | |
<html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* jshint browser: true */ | |
/* global goinstant */ | |
(function() { | |
'use strict'; | |
window.onLoad = function() { | |
var url = "https://goinstant.net/YOURACCOUNT/YOURAPP"; | |
goinstant.connect(url, function(err, conn, room) { | |
if (err) throw err; | |
window.room = room; | |
if (!goinstant.integrations.GoRTC.support) { | |
window.alert('Your browser does not support webrtc'); | |
return; | |
} | |
// Google's public STUN server | |
var stun = { | |
url: 'stun:stun.l.google.com:19302' | |
}; | |
// A free TURN server from http://numb.viagenie.ca | |
// Be careful with this kind of auth on the client as the username and password is exposed to EVERYONE! | |
// I set up this turn server just using a bogus email and password as you can see below | |
var turn = { | |
url: 'turn:numb.viagenie.ca', | |
username: 'webrtc-test@email.com', | |
credential: 'abcd1234' | |
}; | |
var goRTC = new goinstant.integrations.GoRTC({ | |
room: room, | |
autoStart: true, | |
peerConnectionConfig: { | |
iceServers: [stun, turn] | |
} | |
}); | |
goRTC.on('localStream', function() { | |
document.getElementById('localVideoContainer').appendChild(goRTC.localVideo); | |
}); | |
goRTC.on('localStreamStopped', function() { | |
if (gortc.localVideo.parentNode) { | |
gortc.localVideo.parentNode.removeChild(goRTC.localVideo); | |
} | |
}); | |
goRTC.on('peerStreamAdded', function(peer) { | |
document.getElementById('videoContainer').appendChild(peer.video); | |
}); | |
goRTC.on('peerStreamRemoved', function(peer) { | |
if (peer.video.parentNode) { | |
peer.video.parentNode.removeChild(peer.video); | |
} | |
}); | |
}); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment