Browse Source

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 years ago
parent
commit
caabdadf19

+ 0
- 1
react/features/base/lib-jitsi-meet/native/index.js View File

1
-import './polyfills-browser';
2
 import './WiFiStats';
1
 import './WiFiStats';

+ 0
- 1
react/features/base/storage/_.native.js View File

1
-export * from './native';

+ 0
- 0
react/features/base/storage/_.web.js View File


+ 0
- 1
react/features/base/storage/index.js View File

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

+ 0
- 1
react/features/base/storage/native/index.js View File

1
-import './polyfills-browser';

+ 0
- 19
react/features/base/storage/native/polyfills-browser.js View File

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 View File

3
 import { NativeModules } from 'react-native';
3
 import { NativeModules } from 'react-native';
4
 import { RTCPeerConnection, RTCSessionDescription } from 'react-native-webrtc';
4
 import { RTCPeerConnection, RTCSessionDescription } from 'react-native-webrtc';
5
 
5
 
6
-import logger from '../logger';
7
-
8
 /* eslint-disable no-unused-vars */
6
 /* eslint-disable no-unused-vars */
9
 
7
 
10
 // Address families.
8
 // Address families.
87
             // TODO Determine whether the combination of the standard
85
             // TODO Determine whether the combination of the standard
88
             // setRemoteDescription and onaddstream results in a similar
86
             // setRemoteDescription and onaddstream results in a similar
89
             // swallowing of errors.
87
             // swallowing of errors.
90
-            _LOGE(e);
88
+            console.error(e);
91
         }
89
         }
92
     });
90
     });
93
 };
91
 };
101
     return (
99
     return (
102
         _synthesizeIPv6Addresses(description)
100
         _synthesizeIPv6Addresses(description)
103
             .catch(reason => {
101
             .catch(reason => {
104
-                reason && _LOGE(reason);
102
+                reason && console.error(reason);
105
 
103
 
106
                 return description;
104
                 return description;
107
             })
105
             })
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
  * Adapts react-native-webrtc's {@link RTCPeerConnection#setRemoteDescription}
111
  * Adapts react-native-webrtc's {@link RTCPeerConnection#setRemoteDescription}
124
  * implementation which uses the deprecated, callback-based version to the
112
  * implementation which uses the deprecated, callback-based version to the

react/features/base/storage/native/Storage.js → react/features/mobile/polyfills/Storage.js View File


react/features/base/lib-jitsi-meet/native/polyfills-browser.js → react/features/mobile/polyfills/browser.js View File

1
+import { Platform } from 'react-native';
1
 import BackgroundTimer from 'react-native-background-timer';
2
 import BackgroundTimer from 'react-native-background-timer';
3
+
2
 import '@webcomponents/url'; // Polyfill for URL constructor
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
  * Gets the first common prototype of two specified Objects (treating the
9
  * Gets the first common prototype of two specified Objects (treating the
372
     }
374
     }
373
 
375
 
374
     // WebRTC
376
     // WebRTC
375
-    require('./polyfills-webrtc');
377
+    require('./webrtc');
376
 
378
 
377
     // CallStats
379
     // CallStats
378
     //
380
     //
418
     global.setInterval = BackgroundTimer.setInterval.bind(BackgroundTimer);
420
     global.setInterval = BackgroundTimer.setInterval.bind(BackgroundTimer);
419
     global.setTimeout = (fn, ms = 0) => BackgroundTimer.setTimeout(fn, ms);
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
 })(global || window || this); // eslint-disable-line no-invalid-this
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 View File


+ 2
- 0
react/features/mobile/polyfills/index.js View File

1
+import './bundler';
2
+import './browser';

react/features/base/lib-jitsi-meet/native/polyfills-webrtc.js → react/features/mobile/polyfills/webrtc.js View File


+ 3
- 12
react/index.native.js View File

1
 // @flow
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
 import React, { PureComponent } from 'react';
7
 import React, { PureComponent } from 'react';
17
 import { AppRegistry } from 'react-native';
8
 import { AppRegistry } from 'react-native';

Loading…
Cancel
Save