Sfoglia il codice sorgente

ref(browser): Use js-utils.

dev1
hristoterezov 7 anni fa
parent
commit
a1237fb48e

+ 9
- 103
modules/browser/BrowserCapabilities.js Vedi File

@@ -1,7 +1,9 @@
1
-import BrowserDetection from './BrowserDetection';
2
-import capabilitiesDB from './capabilities.json';
1
+import { getLogger } from 'jitsi-meet-logger';
2
+import { BrowserDetection } from 'js-utils';
3 3
 
4
-// TODO: All methods should use capabilities.json when possible.
4
+const logger = getLogger(__filename);
5
+
6
+// TODO: Move this code to js-utils.
5 7
 
6 8
 // NOTE: Now we are extending BrowserDetection in order to preserve
7 9
 // RTCBrowserType interface but maybe it worth exporting BrowserCapabilities
@@ -13,52 +15,11 @@ import capabilitiesDB from './capabilities.json';
13 15
 export default class BrowserCapabilities extends BrowserDetection {
14 16
     /**
15 17
      * Creates new BrowserCapabilities instance.
16
-     *
17
-     * @param {boolean} [isUsingIFrame] - True if Jitsi Meet is loaded in iframe
18
-     * and false otherwise.
19
-     * @param {Object} [browserInfo] - Information about the browser.
20
-     * @param {string} browserInfo.name - The name of the browser.
21
-     * @param {string} browserInfo.version - The version of the browser.
22 18
      */
23
-    constructor(isUsingIFrame = false, browserInfo) {
24
-        super(browserInfo);
25
-
26
-        const browserCapabilities = capabilitiesDB[this.getName()] || [];
27
-        let capabilitiesByVersion;
28
-
29
-        for (let i = 0; i < browserCapabilities.length; i++) {
30
-            const capabilities = browserCapabilities[i];
31
-
32
-            if (typeof capabilities !== 'object') {
33
-                // eslint-disable-next-line no-continue
34
-                continue;
35
-            }
36
-
37
-            const version = capabilities.version;
38
-
39
-            if (!version || !this.isVersionGreaterThan(version)) {
40
-                capabilitiesByVersion = capabilities;
41
-                break;
42
-            }
43
-        }
44
-
45
-        if (!capabilitiesByVersion || !capabilitiesByVersion.capabilities) {
46
-            this._capabilities = { isSupported: false };
47
-        } else if (isUsingIFrame) {
48
-            this._capabilities = {
49
-                ...capabilitiesByVersion.capabilities,
50
-                ...capabilitiesByVersion.iframeCapabilities
51
-            };
52
-        } else {
53
-            this._capabilities = capabilitiesByVersion.capabilities;
54
-        }
55
-
56
-        if (typeof this._capabilities.isSupported === 'undefined') {
57
-            // we have some capabilities but isSupported property is not filled.
58
-            this._capabilities.isSupported = true;
59
-        } else if (this._capabilities.isSupported === false) {
60
-            this._capabilities = { isSupported: false };
61
-        }
19
+    constructor() {
20
+        super();
21
+        logger.info(
22
+            `This appears to be ${this.getName()}, ver: ${this.getVersion()}`);
62 23
     }
63 24
 
64 25
     /**
@@ -96,15 +57,6 @@ export default class BrowserCapabilities extends BrowserDetection {
96 57
             && !this.isVersionLessThan('11');
97 58
     }
98 59
 
99
-    /**
100
-     * Checks whether the browser is supported by Jitsi Meet.
101
-     *
102
-     * @returns {boolean}
103
-     */
104
-    isSupported() {
105
-        return this._capabilities.isSupported;
106
-    }
107
-
108 60
     /**
109 61
      * Checks if Temasys RTC plugin is used.
110 62
      * @returns {boolean}
@@ -131,25 +83,6 @@ export default class BrowserCapabilities extends BrowserDetection {
131 83
         return this.isChrome() || this.isElectron();
132 84
     }
133 85
 
134
-
135
-    /**
136
-     * Checks whether the browser supports incoming audio.
137
-     *
138
-     * @returns {boolean}
139
-     */
140
-    supportsAudioIn() {
141
-        return this._capabilities.audioIn || false;
142
-    }
143
-
144
-    /**
145
-     * Checks whether the browser supports outgoing audio.
146
-     *
147
-     * @returns {boolean}
148
-     */
149
-    supportsAudioOut() {
150
-        return this._capabilities.audioOut || false;
151
-    }
152
-
153 86
     /**
154 87
      * Checks if the current browser reports upload and download bandwidth
155 88
      * statistics.
@@ -205,15 +138,6 @@ export default class BrowserCapabilities extends BrowserDetection {
205 138
         return !this.isFirefox();
206 139
     }
207 140
 
208
-    /**
209
-     * Checks whether the browser supports screen sharing.
210
-     *
211
-     * @returns {boolean}
212
-     */
213
-    supportsScreenSharing() {
214
-        return this._capabilities.screenSharing || false;
215
-    }
216
-
217 141
     /**
218 142
      * Whether jitsi-meet supports simulcast on the current browser.
219 143
      * @returns {boolean}
@@ -241,24 +165,6 @@ export default class BrowserCapabilities extends BrowserDetection {
241 165
         return !this.isSafariWithWebrtc();
242 166
     }
243 167
 
244
-    /**
245
-     * Checks whether the browser supports incomming video.
246
-     *
247
-     * @returns {boolean}
248
-     */
249
-    supportsVideoIn() {
250
-        return this._capabilities.videoIn || false;
251
-    }
252
-
253
-    /**
254
-     * Checks whether the browser supports incomming video.
255
-     *
256
-     * @returns {boolean}
257
-     */
258
-    supportsVideoOut() {
259
-        return this._capabilities.videoOut || false;
260
-    }
261
-
262 168
     /**
263 169
      * Checks if the browser uses plan B.
264 170
      *

+ 0
- 302
modules/browser/BrowserDetection.js Vedi File

@@ -1,302 +0,0 @@
1
-import bowser from 'bowser';
2
-import { getLogger } from 'jitsi-meet-logger';
3
-
4
-import {
5
-    CHROME,
6
-    OPERA,
7
-    FIREFOX,
8
-    INTERNET_EXPLORER,
9
-    EDGE,
10
-    SAFARI,
11
-    NWJS,
12
-    ELECTRON,
13
-    REACT_NATIVE
14
-} from './browsers';
15
-
16
-const logger = getLogger(__filename);
17
-
18
-/**
19
- * Maps the names of the browsers from bowser to the internal names defined in
20
- * ./browsers.js
21
- */
22
-const bowserNameToJitsiName = {
23
-    'Chrome': CHROME,
24
-    'Chromium': CHROME,
25
-    'Opera': OPERA,
26
-    'Firefox': FIREFOX,
27
-    'Internet Explorer': INTERNET_EXPLORER,
28
-    'Microsoft Edge': EDGE,
29
-    'Safari': SAFARI
30
-};
31
-
32
-/**
33
- * Detects Electron environment.
34
- *
35
- * @returns {Object} - The name (ELECTRON) and version.
36
- */
37
-function _detectElectron() {
38
-    const userAgent = navigator.userAgent;
39
-
40
-    if (userAgent.match(/Electron/)) {
41
-        const version = userAgent.match(/Electron\/([\d.]+)/)[1];
42
-
43
-        logger.info(`This appears to be Electron, ver: ${version}`);
44
-
45
-        return {
46
-            name: ELECTRON,
47
-            version
48
-        };
49
-    }
50
-}
51
-
52
-/**
53
- * Detects NWJS environment.
54
- *
55
- * @returns {Object} - The name (NWJS) and version.
56
- */
57
-function _detectNWJS() {
58
-    const userAgent = navigator.userAgent;
59
-
60
-    if (userAgent.match(/JitsiMeetNW/)) {
61
-        const version = userAgent.match(/JitsiMeetNW\/([\d.]+)/)[1];
62
-
63
-        logger.info(`This appears to be JitsiMeetNW, ver: ${version}`);
64
-
65
-        return {
66
-            name: NWJS,
67
-            version
68
-        };
69
-    }
70
-}
71
-
72
-/**
73
- * Detects React Native environment.
74
- * @returns {Object} - The name (REACT_NATIVE) and version
75
- */
76
-function _detectReactNative() {
77
-    const match
78
-        = navigator.userAgent.match(/\b(react[ \t_-]*native)(?:\/(\S+))?/i);
79
-    let version;
80
-
81
-    // If we're remote debugging a React Native app, it may be treated as
82
-    // Chrome. Check navigator.product as well and always return some version
83
-    // even if we can't get the real one.
84
-
85
-    if (match || navigator.product === 'ReactNative') {
86
-        let name;
87
-
88
-        if (match && match.length > 2) {
89
-            name = match[1];
90
-            version = match[2];
91
-        }
92
-        name || (name = 'react-native');
93
-        version || (version = 'unknown');
94
-        logger.info(`This appears to be ${name}, ver: ${version}`);
95
-
96
-        return {
97
-            name: REACT_NATIVE,
98
-            version
99
-        };
100
-    }
101
-}
102
-
103
-/**
104
- * Returns information about the current browser.
105
- *
106
- * @returns {Object} - The name and version of the browser.
107
- */
108
-function _detect() {
109
-    let browserInfo;
110
-    const detectors = [
111
-        _detectReactNative,
112
-        _detectElectron,
113
-        _detectNWJS
114
-    ];
115
-
116
-    // Try all browser detectors
117
-    for (let i = 0; i < detectors.length; i++) {
118
-        browserInfo = detectors[i]();
119
-        if (browserInfo) {
120
-            return browserInfo;
121
-        }
122
-    }
123
-
124
-    const { name, version } = bowser;
125
-
126
-    if (name in bowserNameToJitsiName) {
127
-        logger.info(`This appears to be ${name}, ver: ${version}`);
128
-
129
-        return {
130
-            name: bowserNameToJitsiName[name],
131
-            version
132
-        };
133
-    }
134
-
135
-    logger.warn('Browser type defaults to Safari ver 1');
136
-
137
-    return {
138
-        name: SAFARI,
139
-        version: '1'
140
-    };
141
-}
142
-
143
-/**
144
- * Implements browser detection.
145
- */
146
-export default class BrowserDetection {
147
-    /**
148
-     * Creates new BrowserDetection instance.
149
-     *
150
-     * @param {Object} [browserInfo] - Information about the browser.
151
-     * @param {string} browserInfo.name - The name of the browser.
152
-     * @param {string} browserInfo.version - The version of the browser.
153
-     */
154
-    constructor(browserInfo = _detect()) {
155
-        const { name, version } = browserInfo;
156
-
157
-        this._name = name;
158
-        this._version = version;
159
-    }
160
-
161
-    /**
162
-     * Gets current browser name.
163
-     * @returns {string}
164
-     */
165
-    getName() {
166
-        return this._name;
167
-    }
168
-
169
-    /**
170
-     * Checks if current browser is Chrome.
171
-     * @returns {boolean}
172
-     */
173
-    isChrome() {
174
-        return this._name === CHROME;
175
-    }
176
-
177
-    /**
178
-     * Checks if current browser is Opera.
179
-     * @returns {boolean}
180
-     */
181
-    isOpera() {
182
-        return this._name === OPERA;
183
-    }
184
-
185
-    /**
186
-     * Checks if current browser is Firefox.
187
-     * @returns {boolean}
188
-     */
189
-    isFirefox() {
190
-        return this._name === FIREFOX;
191
-    }
192
-
193
-    /**
194
-     * Checks if current browser is Internet Explorer.
195
-     * @returns {boolean}
196
-     */
197
-    isIExplorer() {
198
-        return this._name === INTERNET_EXPLORER;
199
-    }
200
-
201
-    /**
202
-     * Checks if current browser is Microsoft Edge.
203
-     * @returns {boolean}
204
-     */
205
-    isEdge() {
206
-        return this._name === EDGE;
207
-    }
208
-
209
-    /**
210
-     * Checks if current browser is Safari.
211
-     * @returns {boolean}
212
-     */
213
-    isSafari() {
214
-        return this._name === SAFARI;
215
-    }
216
-
217
-    /**
218
-     * Checks if current environment is NWJS.
219
-     * @returns {boolean}
220
-     */
221
-    isNWJS() {
222
-        return this._name === NWJS;
223
-    }
224
-
225
-    /**
226
-     * Checks if current environment is Electron.
227
-     * @returns {boolean}
228
-     */
229
-    isElectron() {
230
-        return this._name === ELECTRON;
231
-    }
232
-
233
-    /**
234
-     * Checks if current environment is React Native.
235
-     * @returns {boolean}
236
-     */
237
-    isReactNative() {
238
-        return this._name === REACT_NATIVE;
239
-    }
240
-
241
-    /**
242
-     * Returns the version of the current browser.
243
-     * @returns {string}
244
-     */
245
-    getVersion() {
246
-        return this._version;
247
-    }
248
-
249
-    /**
250
-     * Compares the passed version with the current browser version.
251
-     * {@see https://github.com/lancedikson/bowser}
252
-     */
253
-    static compareVersions = bowser.compareVersions;
254
-
255
-    /**
256
-     * Compares the passed version with the current browser version.
257
-     *
258
-     * @param {string} version - The version to compare with.
259
-     * @returns {number|undefined} - Returns 0 if the version is equal to the
260
-     * current one, 1 if the version is greater than the current one, -1 if the
261
-     * version is lower than the current one and undefined if the current
262
-     * browser version is unknown.
263
-     */
264
-    compareVersion(version) {
265
-        if (this._version) {
266
-            return bowser.compareVersions([ version, this._version ]);
267
-        }
268
-    }
269
-
270
-    /**
271
-     * Compares the passed version with the current browser version.
272
-     *
273
-     * @param {string} version - The version to compare with.
274
-     * @returns {boolean|undefined} - Returns true if the current version is
275
-     * greater than the passed version and false otherwise.
276
-     */
277
-    isVersionGreaterThan(version) {
278
-        return this.compareVersion(version) === -1;
279
-    }
280
-
281
-    /**
282
-     * Compares the passed version with the current browser version.
283
-     *
284
-     * @param {string} version - The version to compare with.
285
-     * @returns {boolean|undefined} - Returns true if the current version is
286
-     * lower than the passed version and false otherwise.
287
-     */
288
-    isVersionLessThan(version) {
289
-        return this.compareVersion(version) === 1;
290
-    }
291
-
292
-    /**
293
-     * Compares the passed version with the current browser version.
294
-     *
295
-     * @param {string} version - The version to compare with.
296
-     * @returns {boolean|undefined} - Returns true if the current version is
297
-     * equal to the passed version and false otherwise.
298
-     */
299
-    isVersionEqualTo(version) {
300
-        return this.compareVersion(version) === 0;
301
-    }
302
-}

+ 0
- 21
modules/browser/browsers.js Vedi File

@@ -1,21 +0,0 @@
1
-// TODO: Maybe fix the values to 'Chrome', 'Internet Explorer', etc. Currently
2
-// this values needs to be as they are becuse they are going to analytics,
3
-// callstats, etc.
4
-
5
-export const CHROME = 'chrome';
6
-
7
-export const OPERA = 'opera';
8
-
9
-export const FIREFOX = 'firefox';
10
-
11
-export const INTERNET_EXPLORER = 'iexplorer';
12
-
13
-export const EDGE = 'edge';
14
-
15
-export const SAFARI = 'safari';
16
-
17
-export const NWJS = 'nwjs';
18
-
19
-export const ELECTRON = 'electron';
20
-
21
-export const REACT_NATIVE = 'react-native';

+ 0
- 1
modules/browser/index.js Vedi File

@@ -1,4 +1,3 @@
1 1
 import BrowserCapabilities from './BrowserCapabilities';
2 2
 
3
-export * as browsers from './browsers';
4 3
 export default new BrowserCapabilities();

+ 3
- 1
modules/statistics/RTPStatsCollector.js Vedi File

@@ -1,4 +1,6 @@
1
-import browser, { browsers } from '../browser';
1
+import browser from '../browser';
2
+import { browsers } from 'js-utils';
3
+
2 4
 import * as StatisticsEvents from '../../service/statistics/Events';
3 5
 
4 6
 const GlobalOnErrorHandler = require('../util/GlobalOnErrorHandler');

+ 12
- 7
package-lock.json Vedi File

@@ -1346,8 +1346,7 @@
1346 1346
     "bowser": {
1347 1347
       "version": "1.9.1",
1348 1348
       "resolved": "https://registry.npmjs.org/bowser/-/bowser-1.9.1.tgz",
1349
-      "integrity": "sha512-UXti1JB6oK8hO983AImunnV6j/fqAEeDlPXh99zhsP5g32oLbxJJ6qcOaUesR+tqqhnUVQHlRJyD0dfiV0Hxaw==",
1350
-      "dev": true
1349
+      "integrity": "sha512-UXti1JB6oK8hO983AImunnV6j/fqAEeDlPXh99zhsP5g32oLbxJJ6qcOaUesR+tqqhnUVQHlRJyD0dfiV0Hxaw=="
1351 1350
     },
1352 1351
     "brace-expansion": {
1353 1352
       "version": "1.1.8",
@@ -4017,6 +4016,12 @@
4017 4016
       "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=",
4018 4017
       "dev": true
4019 4018
     },
4019
+    "js-utils": {
4020
+      "version": "github:jitsi/js-utils#fa6eb93d1792b75e25bf84b97e51672e70d900de",
4021
+      "requires": {
4022
+        "bowser": "1.9.1"
4023
+      }
4024
+    },
4020 4025
     "js-yaml": {
4021 4026
       "version": "3.10.0",
4022 4027
       "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.10.0.tgz",
@@ -5823,7 +5828,7 @@
5823 5828
       "resolved": "https://registry.npmjs.org/rtcpeerconnection-shim/-/rtcpeerconnection-shim-1.2.5.tgz",
5824 5829
       "integrity": "sha512-2oLVHZZMk/TsU9JqgrQYwdkOsDOeIalM3STqWjI1LtXrSrInHdig6CysSoTmEublMxnuy/F2i5NXE6tiIh9tZQ==",
5825 5830
       "requires": {
5826
-        "sdp": "2.5.0"
5831
+        "sdp": "2.6.0"
5827 5832
       }
5828 5833
     },
5829 5834
     "run-async": {
@@ -5874,9 +5879,9 @@
5874 5879
       }
5875 5880
     },
5876 5881
     "sdp": {
5877
-      "version": "2.5.0",
5878
-      "resolved": "https://registry.npmjs.org/sdp/-/sdp-2.5.0.tgz",
5879
-      "integrity": "sha512-4HT7gdxA+AZHl5LDdiLpagFKBS5qAKFYE71CPSNrr+2dCFg9iKXY4JSIhHKZHVnwJAzZ/4jA+z1nam4U+LoYug=="
5882
+      "version": "2.6.0",
5883
+      "resolved": "https://registry.npmjs.org/sdp/-/sdp-2.6.0.tgz",
5884
+      "integrity": "sha512-/q5nUDSqvfh+P5pvb4Ez1IsF6F9aLLgslHrSDSltqvUuS7raTY9ROjbGJTyvGSYRs99FY59c8Od1lT7WVaiNAw=="
5880 5885
     },
5881 5886
     "sdp-interop": {
5882 5887
       "version": "0.1.12",
@@ -6881,7 +6886,7 @@
6881 6886
       "version": "github:webrtc/adapter#1eec19782b4058d186341263e7d049cea3e3290a",
6882 6887
       "requires": {
6883 6888
         "rtcpeerconnection-shim": "1.2.5",
6884
-        "sdp": "2.5.0"
6889
+        "sdp": "2.6.0"
6885 6890
       }
6886 6891
     },
6887 6892
     "which": {

+ 1
- 1
package.json Vedi File

@@ -19,6 +19,7 @@
19 19
     "async": "0.9.0",
20 20
     "current-executing-script": "0.1.3",
21 21
     "jitsi-meet-logger": "github:jitsi/jitsi-meet-logger#6fff754a77a56ab52499f3559105a15886942a1e",
22
+    "js-utils": "github:jitsi/js-utils#fa6eb93d1792b75e25bf84b97e51672e70d900de",
22 23
     "react-native-callstats": "3.27.0",
23 24
     "sdp-interop": "0.1.12",
24 25
     "sdp-simulcast": "0.2.1",
@@ -34,7 +35,6 @@
34 35
     "babel-loader": "7.1.2",
35 36
     "babel-preset-env": "1.6.1",
36 37
     "babel-preset-stage-1": "6.24.1",
37
-    "bowser": "1.9.1",
38 38
     "core-js": "2.5.1",
39 39
     "eslint": "4.12.1",
40 40
     "eslint-config-jitsi": "github:jitsi/eslint-config-jitsi#v0.1",

+ 1
- 1
webpack.config.js Vedi File

@@ -43,7 +43,7 @@ const config = {
43 43
 
44 44
             exclude: [
45 45
                 `${__dirname}/modules/RTC/adapter.screenshare.js`,
46
-                `${__dirname}/node_modules/`
46
+                new RegExp(`${__dirname}/node_modules/(?!js-utils)`)
47 47
             ],
48 48
             loader: 'babel-loader',
49 49
             options: {

Loading…
Annulla
Salva