Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

rn,polyfills: refactor all mobile polyfills

Saúl Ibarra Corretgécaabdadf19ae
diff --git a/react/features/base/lib-jitsi-meet/native/index.js b/react/features/base/lib-jitsi-meet/native/index.js
index 4d0b1f5643..be52ee46fe 100644
--- a/react/features/base/lib-jitsi-meet/native/index.js
+++ b/react/features/base/lib-jitsi-meet/native/index.js
@@ -1,2 +1 @@
-import './polyfills-browser';
import './WiFiStats';
diff --git a/react/features/base/storage/_.native.js b/react/features/base/storage/_.native.js
deleted file mode 100644
index 738c4d2b8a..0000000000
--- a/react/features/base/storage/_.native.js
+++ /dev/null
@@ -1 +0,0 @@
-export * from './native';
diff --git a/react/features/base/storage/_.web.js b/react/features/base/storage/_.web.js
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/react/features/base/storage/index.js b/react/features/base/storage/index.js
index a356970064..6219137035 100644
--- a/react/features/base/storage/index.js
+++ b/react/features/base/storage/index.js
@@ -1,4 +1,3 @@
-export * from './_';
export { default as PersistenceRegistry } from './PersistenceRegistry';
import './middleware';
diff --git a/react/features/base/storage/native/index.js b/react/features/base/storage/native/index.js
deleted file mode 100644
index 8caf549513..0000000000
--- a/react/features/base/storage/native/index.js
+++ /dev/null
@@ -1 +0,0 @@
-import './polyfills-browser';
diff --git a/react/features/base/storage/native/polyfills-browser.js b/react/features/base/storage/native/polyfills-browser.js
deleted file mode 100644
index 1518b76b01..0000000000
--- a/react/features/base/storage/native/polyfills-browser.js
+++ /dev/null
@@ -1,19 +0,0 @@
-import Storage from './Storage';
-
-(global => {
-
- // localStorage
- if (typeof global.localStorage === 'undefined') {
- global.localStorage = new Storage('@jitsi-meet/');
- }
-
- // sessionStorage
- //
- // Required by:
- // - herment
- // - Strophe
- if (typeof global.sessionStorage === 'undefined') {
- global.sessionStorage = new Storage();
- }
-
-})(global || window || this); // eslint-disable-line no-invalid-this
diff --git a/react/features/base/lib-jitsi-meet/native/RTCPeerConnection.js b/react/features/mobile/polyfills/RTCPeerConnection.js
similarity index 98%
rename from react/features/base/lib-jitsi-meet/native/RTCPeerConnection.js
rename to react/features/mobile/polyfills/RTCPeerConnection.js
index 60450745e5..8ba6a80de4 100644
--- a/react/features/base/lib-jitsi-meet/native/RTCPeerConnection.js
+++ b/react/features/mobile/polyfills/RTCPeerConnection.js
@@ -3,8 +3,6 @@
import { NativeModules } from 'react-native';
import { RTCPeerConnection, RTCSessionDescription } from 'react-native-webrtc';
-import logger from '../logger';
-
/* eslint-disable no-unused-vars */
// Address families.
@@ -87,7 +85,7 @@ _RTCPeerConnection.prototype._invokeQueuedOnaddstream = function(q) {
// TODO Determine whether the combination of the standard
// setRemoteDescription and onaddstream results in a similar
// swallowing of errors.
- _LOGE(e);
+ console.error(e);
}
});
};
@@ -101,7 +99,7 @@ _RTCPeerConnection.prototype.setRemoteDescription = function(description) {
return (
_synthesizeIPv6Addresses(description)
.catch(reason => {
- reason && _LOGE(reason);
+ reason && console.error(reason);
return description;
})
@@ -109,16 +107,6 @@ _RTCPeerConnection.prototype.setRemoteDescription = function(description) {
};
-/**
- * Logs at error level.
- *
- * @private
- * @returns {void}
- */
-function _LOGE(...args) {
- logger.error(...args);
-}
-
/**
* Adapts react-native-webrtc's {@link RTCPeerConnection#setRemoteDescription}
* implementation which uses the deprecated, callback-based version to the
diff --git a/react/features/base/storage/native/Storage.js b/react/features/mobile/polyfills/Storage.js
similarity index 100%
rename from react/features/base/storage/native/Storage.js
rename to react/features/mobile/polyfills/Storage.js
diff --git a/react/features/base/lib-jitsi-meet/native/polyfills-browser.js b/react/features/mobile/polyfills/browser.js
similarity index 97%
rename from react/features/base/lib-jitsi-meet/native/polyfills-browser.js
rename to react/features/mobile/polyfills/browser.js
index 49b1b0ea3d..3ce8a65682 100644
--- a/react/features/base/lib-jitsi-meet/native/polyfills-browser.js
+++ b/react/features/mobile/polyfills/browser.js
@@ -1,7 +1,9 @@
+import { Platform } from 'react-native';
import BackgroundTimer from 'react-native-background-timer';
+
import '@webcomponents/url'; // Polyfill for URL constructor
-import { Platform } from '../../react';
+import Storage from './Storage';
/**
* Gets the first common prototype of two specified Objects (treating the
@@ -372,7 +374,7 @@ function _visitNode(node, callback) {
}
// WebRTC
- require('./polyfills-webrtc');
+ require('./webrtc');
// CallStats
//
@@ -418,4 +420,18 @@ function _visitNode(node, callback) {
global.setInterval = BackgroundTimer.setInterval.bind(BackgroundTimer);
global.setTimeout = (fn, ms = 0) => BackgroundTimer.setTimeout(fn, ms);
+ // localStorage
+ if (typeof global.localStorage === 'undefined') {
+ global.localStorage = new Storage('@jitsi-meet/');
+ }
+
+ // sessionStorage
+ //
+ // Required by:
+ // - herment
+ // - Strophe
+ if (typeof global.sessionStorage === 'undefined') {
+ global.sessionStorage = new Storage();
+ }
+
})(global || window || this); // eslint-disable-line no-invalid-this
diff --git a/react/features/base/lib-jitsi-meet/native/polyfills-bundler.js b/react/features/mobile/polyfills/bundler.js
similarity index 100%
rename from react/features/base/lib-jitsi-meet/native/polyfills-bundler.js
rename to react/features/mobile/polyfills/bundler.js
diff --git a/react/features/mobile/polyfills/index.js b/react/features/mobile/polyfills/index.js
new file mode 100644
index 0000000000..5092fcd21c
--- /dev/null
+++ b/react/features/mobile/polyfills/index.js
@@ -0,0 +1,2 @@
+import './bundler';
+import './browser';
diff --git a/react/features/base/lib-jitsi-meet/native/polyfills-webrtc.js b/react/features/mobile/polyfills/webrtc.js
similarity index 100%
rename from react/features/base/lib-jitsi-meet/native/polyfills-webrtc.js
rename to react/features/mobile/polyfills/webrtc.js
diff --git a/react/index.native.js b/react/index.native.js
index 2ac15f0138..ab1da731a6 100644
--- a/react/index.native.js
+++ b/react/index.native.js
@@ -1,17 +1,8 @@
// @flow
-// FIXME The bundler-related (and the browser-related) polyfills were born at
-// the very early days of prototyping the execution of lib-jitsi-meet on
-// react-native. Today, the feature base/lib-jitsi-meet should not be
-// responsible for such polyfills because it is not the only feature relying on
-// them. Additionally, the polyfills are usually necessary earlier than the
-// execution of base/lib-jitsi-meet (which is understandable given that the
-// polyfills are globals). The remaining problem to be solved here is where to
-// collect the polyfills' files.
-import './features/base/lib-jitsi-meet/native/polyfills-bundler';
-
-// Polyfill localStorage early so any library that requires it sees it available.
-import './features/base/storage/native/polyfills-browser';
+// Apply all necessary polyfills as early as possible to make sure anything imported henceforth
+// sees them.
+import './features/mobile/polyfills';
import React, { PureComponent } from 'react';
import { AppRegistry } from 'react-native';