Prechádzať zdrojové kódy

Show warning when connecting with Android on Safari

Danilo Bargen 7 rokov pred
rodič
commit
7953496157

+ 6 - 6
package-lock.json

@@ -10,9 +10,9 @@
       "integrity": "sha1-ft8+rWGG7n7a2txokugdzkPw5a0="
     },
     "@saltyrtc/client": {
-      "version": "0.11.2",
-      "resolved": "https://registry.npmjs.org/@saltyrtc/client/-/client-0.11.2.tgz",
-      "integrity": "sha512-aGY16fp54Yve9NBGUXi1FimagswXfzr0bZIf32JzQjQheEHCM2Aefy5qCywbn9diQeDFkAEC34N2zNUAtAnV7w=="
+      "version": "0.11.3",
+      "resolved": "https://registry.npmjs.org/@saltyrtc/client/-/client-0.11.3.tgz",
+      "integrity": "sha512-xyDWBAdYealKSrdO2vDhYrsGEA1bviuTcMvBnrUDp0+lnB8hROdAqeC1eBvUPJcKQ7/NpT6v3yUtr5WcwnqHGQ=="
     },
     "@saltyrtc/task-relayed-data": {
       "version": "0.2.0",
@@ -159,9 +159,9 @@
       "integrity": "sha1-7RLzlLpxqRidZkEVYk9nh6dDmvI="
     },
     "angular-messages": {
-      "version": "1.6.10",
-      "resolved": "https://registry.npmjs.org/angular-messages/-/angular-messages-1.6.10.tgz",
-      "integrity": "sha512-FpILIYqeBj2fP5U5txnO/cneeKZxdF+WqpBo7tgHXl2BmOVVWKUCEjMmByouYxwn9PFLeipBPjaaDs2/eB/m5A=="
+      "version": "1.7.0",
+      "resolved": "https://registry.npmjs.org/angular-messages/-/angular-messages-1.7.0.tgz",
+      "integrity": "sha512-77NqLV2EQgSirRcb5bUSSbyc1GJexBl5PrbpBlXp6EalAL7N27wgEOcSP59ViIusyjY0kezT7RmO2YGzzA56YQ=="
     },
     "angular-mocks": {
       "version": "1.5.11",

+ 2 - 2
package.json

@@ -26,7 +26,7 @@
   "private": true,
   "homepage": "https://threema.ch/",
   "dependencies": {
-    "@saltyrtc/client": "^0.11.2",
+    "@saltyrtc/client": "^0.11.3",
     "@saltyrtc/task-relayed-data": "^0.2.0",
     "@saltyrtc/task-webrtc": "^0.11.0",
     "@types/angular": "^1.6.45",
@@ -42,7 +42,7 @@
     "angular-animate": "~1.5.10",
     "angular-aria": "~1.5.10",
     "angular-material": "=1.1.1",
-    "angular-messages": "^1.6.10",
+    "angular-messages": "^1.7.0",
     "angular-qrcode": "~6.2.1",
     "angular-route": "~1.5.10",
     "angular-sanitize": "~1.5.10",

+ 2 - 1
public/i18n/de.json

@@ -21,7 +21,8 @@
         "FORGET_SESSION": "gespeicherte Sitzung löschen",
         "BTN_RECONNECT": "Verbindung aufbauen",
         "BROWSER_NOT_SUPPORTED": "Dieser Browser wird nicht unterst\u00fctzt",
-        "BROWSER_NOT_SUPPORTED_DETAILS": "Bitte verwenden Sie die aktuelle Version von <a href='https:\/\/www.google.com\/chrome\/browser\/desktop\/' target='_blank' rel='noopener noreferrer'>Google Chrome<\/a>, <a href='https:\/\/www.mozilla.org\/' target='_blank' rel='noopener noreferrer'>Mozilla Firefox<\/a>, <a href='https:\/\/www.opera.com\/' target='_blank' rel='noopener noreferrer'>Opera</a> oder <a href='https:\/\/www.apple.com\/safari\/' target='_blank' rel='noopener noreferrer'>Safari</a>, um den Webclient ohne Einschr\u00e4nkungen zu nutzen.",
+        "BROWSER_NOT_SUPPORTED_ANDROID": "Dieser Browser wird von Android-Geräten nicht unterst\u00fctzt",
+        "BROWSER_NOT_SUPPORTED_DETAILS": "Bitte verwenden Sie die aktuelle Version von <a href='https:\/\/www.google.com\/chrome\/browser\/desktop\/' target='_blank' rel='noopener noreferrer'>Google Chrome<\/a>, <a href='https:\/\/www.mozilla.org\/' target='_blank' rel='noopener noreferrer'>Mozilla Firefox<\/a>, <a href='https:\/\/www.opera.com\/' target='_blank' rel='noopener noreferrer'>Opera</a> oder <a href='https:\/\/www.apple.com\/safari\/' target='_blank' rel='noopener noreferrer'>Safari</a> (nur mit iOS), um den Webclient ohne Einschr\u00e4nkungen zu nutzen.",
         "SAFARI": "Safari ist nur kompatibel mit Threema Web für iOS. Android-Nutzer verwenden bitte einen anderen Browser.",
         "ANDROID_IOS_ONLY": "Kompatibel mit Threema für Android und iOS.",
         "CONNECTING": "Verbindung wird aufgebaut",

+ 2 - 1
public/i18n/en.json

@@ -21,7 +21,8 @@
         "FORGET_SESSION": "forget this session",
         "BTN_RECONNECT": "Reconnect",
         "BROWSER_NOT_SUPPORTED": "This browser is not supported",
-        "BROWSER_NOT_SUPPORTED_DETAILS": "Please use the latest version of <a href='https:\/\/www.google.com\/chrome\/browser\/desktop\/' target='_blank' rel='noopener noreferrer'>Google Chrome<\/a>, <a href='https:\/\/www.mozilla.org\/' target='_blank' rel='noopener noreferrer'>Mozilla Firefox<\/a>, <a href='https:\/\/www.opera.com\/' target='_blank' rel='noopener noreferrer'>Opera</a> or <a href='https:\/\/www.apple.com\/safari\/' target='_blank' rel='noopener noreferrer'>Safari</a>, otherwise the web client might not work properly.",
+        "BROWSER_NOT_SUPPORTED_ANDROID": "This browser is not supported on Android",
+        "BROWSER_NOT_SUPPORTED_DETAILS": "Please use the latest version of <a href='https:\/\/www.google.com\/chrome\/browser\/desktop\/' target='_blank' rel='noopener noreferrer'>Google Chrome<\/a>, <a href='https:\/\/www.mozilla.org\/' target='_blank' rel='noopener noreferrer'>Mozilla Firefox<\/a>, <a href='https:\/\/www.opera.com\/' target='_blank' rel='noopener noreferrer'>Opera</a> or <a href='https:\/\/www.apple.com\/safari\/' target='_blank' rel='noopener noreferrer'>Safari</a> (iOS only), otherwise the web client might not work properly.",
         "SAFARI": "Safari is only compatible with Threema Web for iOS.<br>If you are using Android, please use another browser.",
         "ANDROID_IOS_ONLY": "Compatible with Threema for Android and iOS.",
         "CONNECTING": "Connecting",

+ 1 - 1
src/partials/welcome.ts

@@ -376,7 +376,7 @@ class WelcomeController {
                 // do nothing
             }, () => {
                 // Redirect to Threema website
-                window.location.replace('https://threema.ch/');
+                window.location.replace('https://threema.ch/threema-web');
             });
         });
     }

+ 13 - 0
src/services/browser.ts

@@ -171,4 +171,17 @@ export class BrowserService {
     public isVisible() {
         return this.isPageVisible;
     }
+
+    /**
+     * Return whether the current browser supports the WebRTC task or not.
+     */
+    public supportsWebrtcTask() {
+        if (this.browser === undefined) {
+            this.getBrowser();
+        }
+        if (this.browser.safari) {
+            return false;
+        }
+        return true;
+    }
 }

+ 42 - 2
src/services/webclient.ts

@@ -126,6 +126,7 @@ export class WebClientService {
     private $translate: ng.translate.ITranslateService;
     private $filter: any;
     private $timeout: ng.ITimeoutService;
+    private $mdDialog: ng.material.IDialogService;
 
     // Custom services
     private batteryStatusService: BatteryStatusService;
@@ -198,7 +199,7 @@ export class WebClientService {
     private requestPromises: Map<string, threema.PromiseCallbacks> = new Map();
 
     public static $inject = [
-        '$log', '$rootScope', '$q', '$state', '$window', '$translate', '$filter', '$timeout',
+        '$log', '$rootScope', '$q', '$state', '$window', '$translate', '$filter', '$timeout', '$mdDialog',
         'Container', 'TrustedKeyStore',
         'StateService', 'NotificationService', 'MessageService', 'PushService', 'BrowserService',
         'TitleService', 'QrCodeService', 'MimeService', 'ReceiverService',
@@ -213,6 +214,7 @@ export class WebClientService {
                 $translate: ng.translate.ITranslateService,
                 $filter: ng.IFilterService,
                 $timeout: ng.ITimeoutService,
+                $mdDialog: ng.material.IDialogService,
                 container: threema.Container.Factory,
                 trustedKeyStore: TrustedKeyStoreService,
                 stateService: StateService,
@@ -237,6 +239,7 @@ export class WebClientService {
         this.$translate = $translate;
         this.$filter = $filter;
         this.$timeout = $timeout;
+        this.$mdDialog = $mdDialog;
 
         // Own services
         this.batteryStatusService = batteryStatusService;
@@ -337,12 +340,20 @@ export class WebClientService {
                 + this.config.SALTYRTC_HOST_SUFFIX;
         }
 
+        // Determine SaltyRTC tasks
+        let tasks;
+        if (this.browserService.supportsWebrtcTask()) {
+            tasks = [this.webrtcTask, this.relayedDataTask];
+        } else {
+            tasks = [this.relayedDataTask];
+        }
+
         // Create SaltyRTC client
         let builder = new saltyrtcClient.SaltyRTCBuilder()
             .connectTo(this.saltyRtcHost, this.config.SALTYRTC_PORT)
             .withServerKey(this.config.SALTYRTC_SERVER_KEY)
             .withKeyStore(keyStore)
-            .usingTasks([this.webrtcTask, this.relayedDataTask])
+            .usingTasks(tasks)
             .withPingInterval(30);
         if (keyStore !== undefined && peerTrustedKey !== undefined) {
             builder = builder.withTrustedPeerKey(peerTrustedKey);
@@ -474,6 +485,35 @@ export class WebClientService {
         this.salty.on('connection-closed', (ev) => {
             this.$log.warn('Connection closed:', ev);
         });
+        this.salty.on('no-shared-task', (ev) => {
+            this.$log.warn('No shared task found:', ev.data);
+            const requestedWebrtc = ev.data.requested.filter((t) => t.endsWith('webrtc.tasks.saltyrtc.org')).length > 0;
+            const offeredWebrtc = ev.data.offered.filter((t) => t.endsWith('webrtc.tasks.saltyrtc.org')).length > 0;
+            if (!this.browserService.supportsWebrtcTask() && offeredWebrtc) {
+                this.showWebrtcAndroidWarning();
+            } else {
+                this.$mdDialog.show(this.$mdDialog.alert()
+                    .title('Error')
+                    .htmlContent('No shared SaltyRTC task found')
+                    .ok('OK'));
+            }
+        });
+    }
+
+    /**
+     * Show a WebRTC on Android warning dialog.
+     */
+    private showWebrtcAndroidWarning(): void {
+        this.$translate.onReady().then(() => {
+            const confirm = this.$mdDialog.alert()
+                .title(this.$translate.instant('welcome.BROWSER_NOT_SUPPORTED_ANDROID'))
+                .htmlContent(this.$translate.instant('welcome.BROWSER_NOT_SUPPORTED_DETAILS'))
+                .ok(this.$translate.instant('welcome.ABORT'));
+            this.$mdDialog.show(confirm).then(() => {
+                // Redirect to Threema website
+                window.location.replace('https://threema.ch/threema-web');
+            });
+        });
     }
 
     /**