فهرست منبع

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 سال پیش
والد
کامیت
65de489025
4فایلهای تغییر یافته به همراه34 افزوده شده و 3 حذف شده
  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,
     CHROME: 45,
     OPERA: 32,
-    SAFARI: 11,
+    SAFARI: 10,
 })
 
 // Set default route

+ 8 - 2
src/services/browser.ts

@@ -99,11 +99,11 @@ export class BrowserService {
 
             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.ie      = (/msie/.test(uagent) || /trident/.test(uagent)) && !/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)
                 && /chrome/.test(uagent) && /safari/.test(uagent) && /opr/.test(uagent);
 
@@ -111,6 +111,9 @@ export class BrowserService {
                 this.browser.chrome = false;
             }
 
+            // Mobile detection
+            this.browser.mobile = this.browser.safari && /mobile/.test(uagent);
+
             for (const x in this.browser) {
                 if (this.browser[x]) {
                     let b;
@@ -165,6 +168,9 @@ export class BrowserService {
                 this.browser.name = BrowserName.Opera;
                 this.browser.textInfo = 'Opera ' + this.browser.version;
             }
+            if (this.browser.textInfo && this.browser.mobile) {
+                this.browser.textInfo += ' Mobile';
+            }
         }
 
         return this.browser;

+ 1 - 0
src/threema.d.ts

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

+ 24 - 0
tests/service/browser.js

@@ -26,6 +26,7 @@ describe('BrowserService', function() {
         expect(browser.safari).toBe(false);
         expect(browser.name).toEqual('firefox');
         expect(browser.version).toEqual(59);
+        expect(browser.mobile).toBe(false);
         expect(browser.textInfo).toEqual('Firefox 59');
     });
 
@@ -41,6 +42,7 @@ describe('BrowserService', function() {
         expect(browser.safari).toBe(false);
         expect(browser.name).toEqual('chrome');
         expect(browser.version).toEqual(65);
+        expect(browser.mobile).toBe(false);
         expect(browser.textInfo).toEqual('Chrome 65');
     });
 
@@ -56,6 +58,7 @@ describe('BrowserService', function() {
         expect(browser.safari).toBe(false);
         expect(browser.name).toEqual('ie');
         expect(browser.version).toEqual(9);
+        expect(browser.mobile).toBe(false);
         expect(browser.textInfo).toEqual('Internet Explorer 9');
     });
 
@@ -71,6 +74,7 @@ describe('BrowserService', function() {
         expect(browser.safari).toBe(false);
         expect(browser.name).toEqual('ie');
         expect(browser.version).toEqual(11);
+        expect(browser.mobile).toBe(false);
         expect(browser.textInfo).toEqual('Internet Explorer 11');
     });
 
@@ -86,6 +90,7 @@ describe('BrowserService', function() {
         expect(browser.safari).toBe(false);
         expect(browser.name).toEqual('edge');
         expect(browser.version).toEqual(12);
+        expect(browser.mobile).toBe(false);
         expect(browser.textInfo).toEqual('Edge 12');
     });
 
@@ -101,6 +106,7 @@ describe('BrowserService', function() {
         expect(browser.safari).toBe(false);
         expect(browser.name).toEqual('opera');
         expect(browser.version).toEqual(51);
+        expect(browser.mobile).toBe(false);
         expect(browser.textInfo).toEqual('Opera 51');
     });
 
@@ -116,6 +122,7 @@ describe('BrowserService', function() {
         expect(browser.safari).toBe(true);
         expect(browser.name).toEqual('safari');
         expect(browser.version).toEqual(7);
+        expect(browser.mobile).toBe(false);
         expect(browser.textInfo).toEqual('Safari 7');
     });
 
@@ -131,7 +138,24 @@ describe('BrowserService', function() {
         expect(browser.safari).toBe(true);
         expect(browser.name).toEqual('safari');
         expect(browser.version).toEqual(11);
+        expect(browser.mobile).toBe(false);
         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');
+    });
+
 });