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.
This commit is contained in:
parent
062bc13d4f
commit
caabdadf19
|
@ -1,2 +1 @@
|
||||||
import './polyfills-browser';
|
|
||||||
import './WiFiStats';
|
import './WiFiStats';
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
export * from './native';
|
|
|
@ -1,4 +1,3 @@
|
||||||
export * from './_';
|
|
||||||
export { default as PersistenceRegistry } from './PersistenceRegistry';
|
export { default as PersistenceRegistry } from './PersistenceRegistry';
|
||||||
|
|
||||||
import './middleware';
|
import './middleware';
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
import './polyfills-browser';
|
|
|
@ -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
|
|
|
@ -3,8 +3,6 @@
|
||||||
import { NativeModules } from 'react-native';
|
import { NativeModules } from 'react-native';
|
||||||
import { RTCPeerConnection, RTCSessionDescription } from 'react-native-webrtc';
|
import { RTCPeerConnection, RTCSessionDescription } from 'react-native-webrtc';
|
||||||
|
|
||||||
import logger from '../logger';
|
|
||||||
|
|
||||||
/* eslint-disable no-unused-vars */
|
/* eslint-disable no-unused-vars */
|
||||||
|
|
||||||
// Address families.
|
// Address families.
|
||||||
|
@ -87,7 +85,7 @@ _RTCPeerConnection.prototype._invokeQueuedOnaddstream = function(q) {
|
||||||
// TODO Determine whether the combination of the standard
|
// TODO Determine whether the combination of the standard
|
||||||
// setRemoteDescription and onaddstream results in a similar
|
// setRemoteDescription and onaddstream results in a similar
|
||||||
// swallowing of errors.
|
// swallowing of errors.
|
||||||
_LOGE(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -101,7 +99,7 @@ _RTCPeerConnection.prototype.setRemoteDescription = function(description) {
|
||||||
return (
|
return (
|
||||||
_synthesizeIPv6Addresses(description)
|
_synthesizeIPv6Addresses(description)
|
||||||
.catch(reason => {
|
.catch(reason => {
|
||||||
reason && _LOGE(reason);
|
reason && console.error(reason);
|
||||||
|
|
||||||
return description;
|
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}
|
* Adapts react-native-webrtc's {@link RTCPeerConnection#setRemoteDescription}
|
||||||
* implementation which uses the deprecated, callback-based version to the
|
* implementation which uses the deprecated, callback-based version to the
|
|
@ -1,7 +1,9 @@
|
||||||
|
import { Platform } from 'react-native';
|
||||||
import BackgroundTimer from 'react-native-background-timer';
|
import BackgroundTimer from 'react-native-background-timer';
|
||||||
|
|
||||||
import '@webcomponents/url'; // Polyfill for URL constructor
|
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
|
* Gets the first common prototype of two specified Objects (treating the
|
||||||
|
@ -372,7 +374,7 @@ function _visitNode(node, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebRTC
|
// WebRTC
|
||||||
require('./polyfills-webrtc');
|
require('./webrtc');
|
||||||
|
|
||||||
// CallStats
|
// CallStats
|
||||||
//
|
//
|
||||||
|
@ -418,4 +420,18 @@ function _visitNode(node, callback) {
|
||||||
global.setInterval = BackgroundTimer.setInterval.bind(BackgroundTimer);
|
global.setInterval = BackgroundTimer.setInterval.bind(BackgroundTimer);
|
||||||
global.setTimeout = (fn, ms = 0) => BackgroundTimer.setTimeout(fn, ms);
|
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
|
})(global || window || this); // eslint-disable-line no-invalid-this
|
|
@ -0,0 +1,2 @@
|
||||||
|
import './bundler';
|
||||||
|
import './browser';
|
|
@ -1,17 +1,8 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
// FIXME The bundler-related (and the browser-related) polyfills were born at
|
// Apply all necessary polyfills as early as possible to make sure anything imported henceforth
|
||||||
// the very early days of prototyping the execution of lib-jitsi-meet on
|
// sees them.
|
||||||
// react-native. Today, the feature base/lib-jitsi-meet should not be
|
import './features/mobile/polyfills';
|
||||||
// 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';
|
|
||||||
|
|
||||||
import React, { PureComponent } from 'react';
|
import React, { PureComponent } from 'react';
|
||||||
import { AppRegistry } from 'react-native';
|
import { AppRegistry } from 'react-native';
|
||||||
|
|
Loading…
Reference in New Issue