Browse Source

Allow Safari 10 (with iOS devices)

Since we won't support the buggy Safari 10 data channel implementation
with Android for the time being, we can also add Safari 10 support for
connection with iOS devices.
Danilo Bargen 7 years ago
parent
commit
65de489025
4 changed files with 34 additions and 3 deletions
  1. 1 1
      src/app.ts
  2. 8 2
      src/services/browser.ts
  3. 1 0
      src/threema.d.ts
  4. 24 0
      tests/service/browser.js

+ 1 - 1
src/app.ts

@@ -73,7 +73,7 @@ angular.module('3ema', [
     FF: 50,
     FF: 50,
     CHROME: 45,
     CHROME: 45,
     OPERA: 32,
     OPERA: 32,
-    SAFARI: 11,
+    SAFARI: 10,
 })
 })
 
 
 // Set default route
 // Set default route

+ 8 - 2
src/services/browser.ts

@@ -99,11 +99,11 @@ export class BrowserService {
 
 
             const uagent = this.$window.navigator.userAgent.toLowerCase();
             const uagent = this.$window.navigator.userAgent.toLowerCase();
 
 
-            this.browser.chrome  = /webkit/.test(uagent)  && /chrome/.test(uagent) && !/edge/.test(uagent);
+            this.browser.chrome  = /webkit/.test(uagent) && /chrome/.test(uagent) && !/edge/.test(uagent);
             this.browser.firefox = /mozilla/.test(uagent) && /firefox/.test(uagent);
             this.browser.firefox = /mozilla/.test(uagent) && /firefox/.test(uagent);
             this.browser.ie      = (/msie/.test(uagent) || /trident/.test(uagent)) && !/edge/.test(uagent);
             this.browser.ie      = (/msie/.test(uagent) || /trident/.test(uagent)) && !/edge/.test(uagent);
             this.browser.edge    = /edge/.test(uagent);
             this.browser.edge    = /edge/.test(uagent);
-            this.browser.safari  = /safari/.test(uagent)  && /applewebkit/.test(uagent) && !/chrome/.test(uagent);
+            this.browser.safari  = /safari/.test(uagent) && /applewebkit/.test(uagent) && !/chrome/.test(uagent);
             this.browser.opera   = /mozilla/.test(uagent) && /applewebkit/.test(uagent)
             this.browser.opera   = /mozilla/.test(uagent) && /applewebkit/.test(uagent)
                 && /chrome/.test(uagent) && /safari/.test(uagent) && /opr/.test(uagent);
                 && /chrome/.test(uagent) && /safari/.test(uagent) && /opr/.test(uagent);
 
 
@@ -111,6 +111,9 @@ export class BrowserService {
                 this.browser.chrome = false;
                 this.browser.chrome = false;
             }
             }
 
 
+            // Mobile detection
+            this.browser.mobile = this.browser.safari && /mobile/.test(uagent);
+
             for (const x in this.browser) {
             for (const x in this.browser) {
                 if (this.browser[x]) {
                 if (this.browser[x]) {
                     let b;
                     let b;
@@ -165,6 +168,9 @@ export class BrowserService {
                 this.browser.name = BrowserName.Opera;
                 this.browser.name = BrowserName.Opera;
                 this.browser.textInfo = 'Opera ' + this.browser.version;
                 this.browser.textInfo = 'Opera ' + this.browser.version;
             }
             }
+            if (this.browser.textInfo && this.browser.mobile) {
+                this.browser.textInfo += ' Mobile';
+            }
         }
         }
 
 
         return this.browser;
         return this.browser;

+ 1 - 0
src/threema.d.ts

@@ -519,6 +519,7 @@ declare namespace threema {
         opera: boolean;
         opera: boolean;
         safari: boolean;
         safari: boolean;
         name?: BrowserName;
         name?: BrowserName;
+        mobile?: boolean;
         version?: number;
         version?: number;
         textInfo?: string;
         textInfo?: string;
     }
     }

+ 24 - 0
tests/service/browser.js

@@ -26,6 +26,7 @@ describe('BrowserService', function() {
         expect(browser.safari).toBe(false);
         expect(browser.safari).toBe(false);
         expect(browser.name).toEqual('firefox');
         expect(browser.name).toEqual('firefox');
         expect(browser.version).toEqual(59);
         expect(browser.version).toEqual(59);
+        expect(browser.mobile).toBe(false);
         expect(browser.textInfo).toEqual('Firefox 59');
         expect(browser.textInfo).toEqual('Firefox 59');
     });
     });
 
 
@@ -41,6 +42,7 @@ describe('BrowserService', function() {
         expect(browser.safari).toBe(false);
         expect(browser.safari).toBe(false);
         expect(browser.name).toEqual('chrome');
         expect(browser.name).toEqual('chrome');
         expect(browser.version).toEqual(65);
         expect(browser.version).toEqual(65);
+        expect(browser.mobile).toBe(false);
         expect(browser.textInfo).toEqual('Chrome 65');
         expect(browser.textInfo).toEqual('Chrome 65');
     });
     });
 
 
@@ -56,6 +58,7 @@ describe('BrowserService', function() {
         expect(browser.safari).toBe(false);
         expect(browser.safari).toBe(false);
         expect(browser.name).toEqual('ie');
         expect(browser.name).toEqual('ie');
         expect(browser.version).toEqual(9);
         expect(browser.version).toEqual(9);
+        expect(browser.mobile).toBe(false);
         expect(browser.textInfo).toEqual('Internet Explorer 9');
         expect(browser.textInfo).toEqual('Internet Explorer 9');
     });
     });
 
 
@@ -71,6 +74,7 @@ describe('BrowserService', function() {
         expect(browser.safari).toBe(false);
         expect(browser.safari).toBe(false);
         expect(browser.name).toEqual('ie');
         expect(browser.name).toEqual('ie');
         expect(browser.version).toEqual(11);
         expect(browser.version).toEqual(11);
+        expect(browser.mobile).toBe(false);
         expect(browser.textInfo).toEqual('Internet Explorer 11');
         expect(browser.textInfo).toEqual('Internet Explorer 11');
     });
     });
 
 
@@ -86,6 +90,7 @@ describe('BrowserService', function() {
         expect(browser.safari).toBe(false);
         expect(browser.safari).toBe(false);
         expect(browser.name).toEqual('edge');
         expect(browser.name).toEqual('edge');
         expect(browser.version).toEqual(12);
         expect(browser.version).toEqual(12);
+        expect(browser.mobile).toBe(false);
         expect(browser.textInfo).toEqual('Edge 12');
         expect(browser.textInfo).toEqual('Edge 12');
     });
     });
 
 
@@ -101,6 +106,7 @@ describe('BrowserService', function() {
         expect(browser.safari).toBe(false);
         expect(browser.safari).toBe(false);
         expect(browser.name).toEqual('opera');
         expect(browser.name).toEqual('opera');
         expect(browser.version).toEqual(51);
         expect(browser.version).toEqual(51);
+        expect(browser.mobile).toBe(false);
         expect(browser.textInfo).toEqual('Opera 51');
         expect(browser.textInfo).toEqual('Opera 51');
     });
     });
 
 
@@ -116,6 +122,7 @@ describe('BrowserService', function() {
         expect(browser.safari).toBe(true);
         expect(browser.safari).toBe(true);
         expect(browser.name).toEqual('safari');
         expect(browser.name).toEqual('safari');
         expect(browser.version).toEqual(7);
         expect(browser.version).toEqual(7);
+        expect(browser.mobile).toBe(false);
         expect(browser.textInfo).toEqual('Safari 7');
         expect(browser.textInfo).toEqual('Safari 7');
     });
     });
 
 
@@ -131,7 +138,24 @@ describe('BrowserService', function() {
         expect(browser.safari).toBe(true);
         expect(browser.safari).toBe(true);
         expect(browser.name).toEqual('safari');
         expect(browser.name).toEqual('safari');
         expect(browser.version).toEqual(11);
         expect(browser.version).toEqual(11);
+        expect(browser.mobile).toBe(false);
         expect(browser.textInfo).toEqual('Safari 11');
         expect(browser.textInfo).toEqual('Safari 11');
     });
     });
 
 
+    it('safari10Mobile', () => {
+        const ua = 'Mozilla/5.0 (iPad; CPU OS 10_0_1 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14A403 Safari/602.1';
+        const service = testUserAgent(ua);
+        const browser = service.getBrowser();
+        expect(browser.chrome).toBe(false);
+        expect(browser.firefox).toBe(false);
+        expect(browser.ie).toBe(false);
+        expect(browser.edge).toBe(false);
+        expect(browser.opera).toBe(false);
+        expect(browser.safari).toBe(true);
+        expect(browser.name).toEqual('safari');
+        expect(browser.version).toEqual(10);
+        expect(browser.mobile).toBe(true);
+        expect(browser.textInfo).toEqual('Safari 10 Mobile');
+    });
+
 });
 });