Browse Source

On Safari, disable dual-stack TURN servers

See https://bugs.webkit.org/show_bug.cgi?id=173307#c13
Danilo Bargen 7 năm trước cách đây
mục cha
commit
15a4f84295
2 tập tin đã thay đổi với 46 bổ sung4 xóa
  1. 28 1
      src/services/webclient.ts
  2. 18 3
      troubleshoot/troubleshoot.js

+ 28 - 1
src/services/webclient.ts

@@ -405,12 +405,18 @@ export class WebClientService {
 
             // If the WebRTC task was chosen, initialize handover.
             if (this.chosenTask === threema.ChosenTask.WebRTC) {
-                // Firefox <53 does not yet support TLS. Skip it, to save allocations.
                 const browser = this.browserService.getBrowser();
+
+                // Firefox <53 does not yet support TLS. Skip it, to save allocations.
                 if (browser.firefox && browser.version && browser.version < 53) {
                     this.skipIceTls();
                 }
 
+                // Safari does not support our dual-stack TURN servers.
+                if (browser.safari) {
+                    this.skipIceDs();
+                }
+
                 this.pcHelper = new PeerConnectionHelper(this.$log, this.$q, this.$timeout,
                     this.$rootScope, this.webrtcTask,
                     this.config.ICE_SERVERS,
@@ -668,6 +674,27 @@ export class WebClientService {
         }
     }
 
+    /**
+     * Safari has issues with dual-stack TURN servers:
+     * https://bugs.webkit.org/show_bug.cgi?id=173307#c13
+     * As a workaround, replace ds-turn.threema.ch servers
+     * in the ICE_SERVERS configuration with turn.threema.ch.
+     */
+    public skipIceDs(): void {
+        this.$log.debug(this.logTag, 'Requested to replace DS servers in ICE configuration');
+        const allUrls = [].concat(...this.config.ICE_SERVERS.map((conf) => conf.urls));
+        if (allUrls.some((url) => url.includes('ds-turn.threema.ch'))) {
+            for (const server of this.config.ICE_SERVERS) {
+                // Replace dual stack entries
+                server.urls = server.urls.map((url) => {
+                    return url.replace('ds-turn.threema.ch', 'turn.threema.ch');
+                });
+            }
+        } else {
+            this.$log.debug(this.logTag, 'No ds-turn ICE server present');
+        }
+    }
+
     /**
      * Mark a component as initialized
      */

+ 18 - 3
troubleshoot/troubleshoot.js

@@ -84,12 +84,27 @@ function doChecks() {
             turnFail();
         }, 10000);
         var noop = function() {};
-        var pc = new RTCPeerConnection({iceServers: [{
-            urls: [
+
+        var uagent = window.navigator.userAgent.toLowerCase();
+        var isSafari  = /safari/.test(uagent) && /applewebkit/.test(uagent) && !/chrome/.test(uagent);
+
+        if (isSafari) {
+            var iceServers = [
+                'turn:turn.threema.ch:443?transport=udp',
+                'turn:turn.threema.ch:443?transport=tcp',
+                'turns:turn.threema.ch:443',
+            ];
+        } else {
+            var iceServers = [
                 'turn:ds-turn.threema.ch:443?transport=udp',
                 'turn:ds-turn.threema.ch:443?transport=tcp',
                 'turns:ds-turn.threema.ch:443',
-            ],
+            ];
+        }
+        console.debug('Using ICE servers: ' + iceServers);
+
+        var pc = new RTCPeerConnection({iceServers: [{
+            urls: iceServers,
             username: 'threema-angular-test',
             credential: 'VaoVnhxKGt2wD20F9bTOgiew6yHQmj4P7y7SE4lrahAjTQC0dpnG32FR4fnrlpKa',
         }]});