Migrating Apprtc to use new TURN service which supports time-limited TURN credentials.
Review URL: https://webrtc-codereview.appspot.com/1291004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3773 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@@ -315,6 +315,7 @@ class MainPage(webapp2.RequestHandler):
|
|||||||
min_re = self.request.get('minre')
|
min_re = self.request.get('minre')
|
||||||
max_re = self.request.get('maxre')
|
max_re = self.request.get('maxre')
|
||||||
hd_video = self.request.get('hd')
|
hd_video = self.request.get('hd')
|
||||||
|
turn_url = 'https://computeengineondemand.appspot.com/'
|
||||||
if hd_video.lower() == 'true':
|
if hd_video.lower() == 'true':
|
||||||
min_re = '1280x720'
|
min_re = '1280x720'
|
||||||
ts_pwd = self.request.get('tp')
|
ts_pwd = self.request.get('tp')
|
||||||
@@ -374,6 +375,7 @@ class MainPage(webapp2.RequestHandler):
|
|||||||
|
|
||||||
room_link = base_url + '?r=' + room_key
|
room_link = base_url + '?r=' + room_key
|
||||||
room_link = append_url_arguments(self.request, room_link)
|
room_link = append_url_arguments(self.request, room_link)
|
||||||
|
turn_url = turn_url + 'turn?' + 'username=' + user + '&key=4080218913'
|
||||||
token = create_channel(room, user, token_timeout)
|
token = create_channel(room, user, token_timeout)
|
||||||
pc_config = make_pc_config(stun_server, turn_server, ts_pwd)
|
pc_config = make_pc_config(stun_server, turn_server, ts_pwd)
|
||||||
pc_constraints = make_pc_constraints(compat)
|
pc_constraints = make_pc_constraints(compat)
|
||||||
@@ -387,7 +389,8 @@ class MainPage(webapp2.RequestHandler):
|
|||||||
'pc_config': json.dumps(pc_config),
|
'pc_config': json.dumps(pc_config),
|
||||||
'pc_constraints': json.dumps(pc_constraints),
|
'pc_constraints': json.dumps(pc_constraints),
|
||||||
'offer_constraints': json.dumps(offer_constraints),
|
'offer_constraints': json.dumps(offer_constraints),
|
||||||
'media_constraints': json.dumps(media_constraints)
|
'media_constraints': json.dumps(media_constraints),
|
||||||
|
'turn_url': turn_url
|
||||||
}
|
}
|
||||||
if unittest:
|
if unittest:
|
||||||
target_page = 'test/test_' + unittest + '.html'
|
target_page = 'test/test_' + unittest + '.html'
|
||||||
|
@@ -112,10 +112,13 @@
|
|||||||
var remoteStream;
|
var remoteStream;
|
||||||
var channel;
|
var channel;
|
||||||
var channelReady = false;
|
var channelReady = false;
|
||||||
|
var turnReady = false;
|
||||||
var pc;
|
var pc;
|
||||||
var socket;
|
var socket;
|
||||||
var initiator = {{ initiator }};
|
var initiator = {{ initiator }};
|
||||||
var started = false;
|
var started = false;
|
||||||
|
var pc_config = {{ pc_config|safe }};
|
||||||
|
var pc_constraints = {{ pc_constraints|safe }};
|
||||||
// Set up audio and video regardless of what devices are present.
|
// Set up audio and video regardless of what devices are present.
|
||||||
var sdpConstraints = {'mandatory': {
|
var sdpConstraints = {'mandatory': {
|
||||||
'OfferToReceiveAudio':true,
|
'OfferToReceiveAudio':true,
|
||||||
@@ -133,6 +136,7 @@
|
|||||||
// NOTE: AppRTCClient.java searches & parses this line; update there when
|
// NOTE: AppRTCClient.java searches & parses this line; update there when
|
||||||
// changing here.
|
// changing here.
|
||||||
openChannel('{{ token }}');
|
openChannel('{{ token }}');
|
||||||
|
requestTurn('{{ turn_url }}');
|
||||||
doGetUserMedia();
|
doGetUserMedia();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,6 +152,35 @@
|
|||||||
socket = channel.open(handler);
|
socket = channel.open(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function requestTurn(turn_url) {
|
||||||
|
var turnExists = false;
|
||||||
|
for (var i in pc_config.iceServers) {
|
||||||
|
if (pc_config.iceServers[i].url.substr(0, 5) == 'turn:') {
|
||||||
|
turnExists = true;
|
||||||
|
turnReady = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!turnExists) {
|
||||||
|
// No turn server. Get one from computeengineondemand.appspot.com:
|
||||||
|
xmlhttp = new XMLHttpRequest();
|
||||||
|
xmlhttp.onreadystatechange = onTurnResult;
|
||||||
|
xmlhttp.open("GET", turn_url, true);
|
||||||
|
xmlhttp.send();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onTurnResult() {
|
||||||
|
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||||
|
var turnServer = JSON.parse(xmlhttp.responseText);
|
||||||
|
pc_config.iceServers.push({
|
||||||
|
"url": "turn:" + turnServer.username + "@" + turnServer.turn,
|
||||||
|
"credential": turnServer.password
|
||||||
|
});
|
||||||
|
turnReady = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function resetStatus() {
|
function resetStatus() {
|
||||||
if (!initiator) {
|
if (!initiator) {
|
||||||
setStatus("Waiting for someone to join: <a href=\"{{ room_link }}\">{{ room_link }}</a>");
|
setStatus("Waiting for someone to join: <a href=\"{{ room_link }}\">{{ room_link }}</a>");
|
||||||
@@ -170,13 +203,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createPeerConnection() {
|
function createPeerConnection() {
|
||||||
var pc_config = {{ pc_config|safe }};
|
|
||||||
var pc_constraints = {{ pc_constraints|safe }};
|
|
||||||
// Force the use of a number IP STUN server for Firefox.
|
// Force the use of a number IP STUN server for Firefox.
|
||||||
if (webrtcDetectedBrowser == "firefox") {
|
if (webrtcDetectedBrowser == "firefox") {
|
||||||
pc_config = {"iceServers":[{"url":"stun:23.21.150.121"}]};
|
pc_config = {"iceServers":[{"url":"stun:23.21.150.121"}]};
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// Create an RTCPeerConnection via the polyfill (adapter.js).
|
// Create an RTCPeerConnection via the polyfill (adapter.js).
|
||||||
pc = new RTCPeerConnection(pc_config, pc_constraints);
|
pc = new RTCPeerConnection(pc_config, pc_constraints);
|
||||||
@@ -189,13 +220,12 @@
|
|||||||
alert("Cannot create RTCPeerConnection object; WebRTC is not supported by this browser.");
|
alert("Cannot create RTCPeerConnection object; WebRTC is not supported by this browser.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pc.onaddstream = onRemoteStreamAdded;
|
pc.onaddstream = onRemoteStreamAdded;
|
||||||
pc.onremovestream = onRemoteStreamRemoved;
|
pc.onremovestream = onRemoteStreamRemoved;
|
||||||
}
|
}
|
||||||
|
|
||||||
function maybeStart() {
|
function maybeStart() {
|
||||||
if (!started && localStream && channelReady) {
|
if (!started && localStream && channelReady && turnReady) {
|
||||||
setStatus("Connecting...");
|
setStatus("Connecting...");
|
||||||
console.log("Creating PeerConnection.");
|
console.log("Creating PeerConnection.");
|
||||||
createPeerConnection();
|
createPeerConnection();
|
||||||
|
Reference in New Issue
Block a user