瀏覽代碼

rn,polyfills: refactor all mobile polyfills

Move all polyfills to a standalone feature, which gets imported before anything
else in the mobile entrypoint. This guarantees that any further import sees the
polyfilled environment.
master
Saúl Ibarra Corretgé 5 年之前
父節點
當前提交
caabdadf19

+ 0
- 1
react/features/base/lib-jitsi-meet/native/index.js 查看文件

@@ -1,2 +1 @@
1
-import './polyfills-browser';
2 1
 import './WiFiStats';

+ 0
- 1
react/features/base/storage/_.native.js 查看文件

@@ -1 +0,0 @@
1
-export * from './native';

+ 0
- 0
react/features/base/storage/_.web.js 查看文件


+ 0
- 1
react/features/base/storage/index.js 查看文件

@@ -1,4 +1,3 @@
1
-export * from './_';
2 1
 export { default as PersistenceRegistry } from './PersistenceRegistry';
3 2
 
4 3
 import './middleware';

+ 0
- 1
react/features/base/storage/native/index.js 查看文件

@@ -1 +0,0 @@
1
-import './polyfills-browser';

+ 0
- 19
react/features/base/storage/native/polyfills-browser.js 查看文件

@@ -1,19 +0,0 @@
1
-import Storage from './Storage';
2
-
3
-(global => {
4
-
5
-    // localStorage
6
-    if (typeof global.localStorage === 'undefined') {
7
-        global.localStorage = new Storage('@jitsi-meet/');
8
-    }
9
-
10
-    // sessionStorage
11
-    //
12
-    // Required by:
13
-    // - herment
14
-    // - Strophe
15
-    if (typeof global.sessionStorage === 'undefined') {
16
-        global.sessionStorage = new Storage();
17
-    }
18
-
19
-})(global || window || this); // eslint-disable-line no-invalid-this

react/features/base/lib-jitsi-meet/native/RTCPeerConnection.js → react/features/mobile/polyfills/RTCPeerConnection.js 查看文件

@@ -3,8 +3,6 @@
3 3
 import { NativeModules } from 'react-native';
4 4
 import { RTCPeerConnection, RTCSessionDescription } from 'react-native-webrtc';
5 5
 
6
-import logger from '../logger';
7
-
8 6
 /* eslint-disable no-unused-vars */
9 7
 
10 8
 // Address families.
@@ -87,7 +85,7 @@ _RTCPeerConnection.prototype._invokeQueuedOnaddstream = function(q) {
87 85
             // TODO Determine whether the combination of the standard
88 86
             // setRemoteDescription and onaddstream results in a similar
89 87
             // swallowing of errors.
90
-            _LOGE(e);
88
+            console.error(e);
91 89
         }
92 90
     });
93 91
 };
@@ -101,7 +99,7 @@ _RTCPeerConnection.prototype.setRemoteDescription = function(description) {
101 99
     return (
102 100
         _synthesizeIPv6Addresses(description)
103 101
             .catch(reason => {
104
-                reason && _LOGE(reason);
102
+                reason && console.error(reason);
105 103
 
106 104
                 return description;
107 105
             })
@@ -109,16 +107,6 @@ _RTCPeerConnection.prototype.setRemoteDescription = function(description) {
109 107
 
110 108
 };
111 109
 
112
-/**
113
- * Logs at error level.
114
- *
115
- * @private
116
- * @returns {void}
117
- */
118
-function _LOGE(...args) {
119
-    logger.error(...args);
120
-}
121
-
122 110
 /**
123 111
  * Adapts react-native-webrtc's {@link RTCPeerConnection#setRemoteDescription}
124 112
  * implementation which uses the deprecated, callback-based version to the

react/features/base/storage/native/Storage.js → react/features/mobile/polyfills/Storage.js 查看文件


react/features/base/lib-jitsi-meet/native/polyfills-browser.js → react/features/mobile/polyfills/browser.js 查看文件

@@ -1,7 +1,9 @@
1
+import { Platform } from 'react-native';
1 2
 import BackgroundTimer from 'react-native-background-timer';
3
+
2 4
 import '@webcomponents/url'; // Polyfill for URL constructor
3 5
 
4
-import { Platform } from '../../react';
6
+import Storage from './Storage';
5 7
 
6 8
 /**
7 9
  * Gets the first common prototype of two specified Objects (treating the
@@ -372,7 +374,7 @@ function _visitNode(node, callback) {
372 374
     }
373 375
 
374 376
     // WebRTC
375
-    require('./polyfills-webrtc');
377
+    require('./webrtc');
376 378
 
377 379
     // CallStats
378 380
     //
@@ -418,4 +420,18 @@ function _visitNode(node, callback) {
418 420
     global.setInterval = BackgroundTimer.setInterval.bind(BackgroundTimer);
419 421
     global.setTimeout = (fn, ms = 0) => BackgroundTimer.setTimeout(fn, ms);
420 422
 
423
+    // localStorage
424
+    if (typeof global.localStorage === 'undefined') {
425
+        global.localStorage = new Storage('@jitsi-meet/');
426
+    }
427
+
428
+    // sessionStorage
429
+    //
430
+    // Required by:
431
+    // - herment
432
+    // - Strophe
433
+    if (typeof global.sessionStorage === 'undefined') {
434
+        global.sessionStorage = new Storage();
435
+    }
436
+
421 437
 })(global || window || this); // eslint-disable-line no-invalid-this

react/features/base/lib-jitsi-meet/native/polyfills-bundler.js → react/features/mobile/polyfills/bundler.js 查看文件


+ 2
- 0
react/features/mobile/polyfills/index.js 查看文件

@@ -0,0 +1,2 @@
1
+import './bundler';
2
+import './browser';

react/features/base/lib-jitsi-meet/native/polyfills-webrtc.js → react/features/mobile/polyfills/webrtc.js 查看文件


+ 3
- 12
react/index.native.js 查看文件

@@ -1,17 +1,8 @@
1 1
 // @flow
2 2
 
3
-// FIXME The bundler-related (and the browser-related) polyfills were born at
4
-// the very early days of prototyping the execution of lib-jitsi-meet on
5
-// react-native. Today, the feature base/lib-jitsi-meet should not be
6
-// responsible for such polyfills because it is not the only feature relying on
7
-// them. Additionally, the polyfills are usually necessary earlier than the
8
-// execution of base/lib-jitsi-meet (which is understandable given that the
9
-// polyfills are globals). The remaining problem to be solved here is where to
10
-// collect the polyfills' files.
11
-import './features/base/lib-jitsi-meet/native/polyfills-bundler';
12
-
13
-// Polyfill localStorage early so any library that requires it sees it available.
14
-import './features/base/storage/native/polyfills-browser';
3
+// Apply all necessary polyfills as early as possible to make sure anything imported henceforth
4
+// sees them.
5
+import './features/mobile/polyfills';
15 6
 
16 7
 import React, { PureComponent } from 'react';
17 8
 import { AppRegistry } from 'react-native';

Loading…
取消
儲存