summary refs log tree commit diff
path: root/webclient
diff options
context:
space:
mode:
authorDavid Baker <dbkr@matrix.org>2014-09-24 16:07:33 +0100
committerDavid Baker <dbkr@matrix.org>2014-09-24 16:08:31 +0100
commit7679ee7321ff588a84edab31507185d2cee80fc7 (patch)
tree512892469b5a8048bae93f7464a2497bf4bc2f9b /webclient
parentOops (diff)
downloadsynapse-7679ee7321ff588a84edab31507185d2cee80fc7.tar.xz
Hopefully implement turn in the web client (probably wrong for Firefox because Firefox is a special snowflake)
Diffstat (limited to '')
-rw-r--r--webclient/components/matrix/matrix-call.js33
-rw-r--r--webclient/components/matrix/matrix-service.js4
2 files changed, 34 insertions, 3 deletions
diff --git a/webclient/components/matrix/matrix-call.js b/webclient/components/matrix/matrix-call.js
index 7b5d9cffef..888f853472 100644
--- a/webclient/components/matrix/matrix-call.js
+++ b/webclient/components/matrix/matrix-call.js
@@ -49,6 +49,15 @@ angular.module('MatrixCall', [])
 .factory('MatrixCall', ['matrixService', 'matrixPhoneService', '$rootScope', '$timeout', function MatrixCallFactory(matrixService, matrixPhoneService, $rootScope, $timeout) {
     $rootScope.isWebRTCSupported = isWebRTCSupported();
 
+    // FIXME: we should prevent any class from being placed or accepted before this has finished
+    matrixService.getTurnServer().then(function(response) {
+        console.log("Got TURN URIs: "+response.data.uris);
+        MatrixCall.turnServer = response.data;
+    }, function(error) {
+        console.log("Failed to get TURN URIs");
+        MatrixCall.turnServer = {};
+    });
+
     var MatrixCall = function(room_id) {
         this.room_id = room_id;
         this.call_id = "c" + new Date().getTime();
@@ -69,12 +78,30 @@ angular.module('MatrixCall', [])
     MatrixCall.CALL_TIMEOUT = 60000;
 
     MatrixCall.prototype.createPeerConnection = function() {
-        var stunServer = 'stun:stun.l.google.com:19302';
         var pc;
         if (window.mozRTCPeerConnection) {
-            pc = new window.mozRTCPeerConnection({'url': stunServer});
+            var iceServers = [];
+            if (MatrixCall.turnServer) {
+                iceServers.push({
+                    'urls': MatrixCall.turnServer.uris,
+                    'username': MatrixCall.turnServer.username,
+                    'credential': MatrixCall.turnServer.password,
+                });
+            }
+          
+            pc = new window.mozRTCPeerConnection({"iceServers":iceServers});
+            //pc = new window.mozRTCPeerConnection({'url': stunServer});
         } else {
-            pc = new window.RTCPeerConnection({"iceServers":[{"urls":"stun:stun.l.google.com:19302"}]});
+            var iceServers = [];
+            if (MatrixCall.turnServer) {
+                iceServers.push({
+                    'urls': MatrixCall.turnServer.uris,
+                    'username': MatrixCall.turnServer.username,
+                    'credential': MatrixCall.turnServer.password,
+                });
+            }
+          
+            pc = new window.RTCPeerConnection({"iceServers":iceServers});
         }
         var self = this;
         pc.oniceconnectionstatechange = function() { self.onIceConnectionStateChanged(); };
diff --git a/webclient/components/matrix/matrix-service.js b/webclient/components/matrix/matrix-service.js
index 069e02e939..69e6caccd3 100644
--- a/webclient/components/matrix/matrix-service.js
+++ b/webclient/components/matrix/matrix-service.js
@@ -762,6 +762,10 @@ angular.module('matrixService', [])
             var deferred = $q.defer();
             deferred.reject({data:{error: "Invalid room: " + room_id}});
             return deferred.promise;
+        },
+
+        getTurnServer: function() {
+            return doRequest("GET", "/voip/turnServers");
         }
 
     };