2021-10-20 19:58:08 +00:00
|
|
|
import { DOMParser } from '@xmldom/xmldom';
|
2020-05-06 09:22:09 +00:00
|
|
|
import { Platform } from 'react-native';
|
2017-02-14 13:59:49 +00:00
|
|
|
import BackgroundTimer from 'react-native-background-timer';
|
2020-05-06 09:22:09 +00:00
|
|
|
|
2022-01-25 10:01:52 +00:00
|
|
|
import 'promise.allsettled/auto'; // Promise.allSettled.
|
2020-10-14 19:18:01 +00:00
|
|
|
import 'react-native-url-polyfill/auto'; // Complete URL polyfill.
|
2017-02-14 13:59:49 +00:00
|
|
|
|
2020-05-06 09:22:09 +00:00
|
|
|
import Storage from './Storage';
|
2017-09-18 18:21:10 +00:00
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2018-11-08 12:25:02 +00:00
|
|
|
* Implements an absolute minimum of the common logic of
|
|
|
|
* {@code Document.querySelector} and {@code Element.querySelector}. Implements
|
|
|
|
* the most simple of selectors necessary to satisfy the call sites at the time
|
|
|
|
* of this writing (i.e. Select by tagName).
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
|
|
|
* @param {Node} node - The Node which is the root of the tree to query.
|
|
|
|
* @param {string} selectors - The group of CSS selectors to match on.
|
|
|
|
* @returns {Element} - The first Element which is a descendant of the specified
|
|
|
|
* node and matches the specified group of selectors.
|
|
|
|
*/
|
|
|
|
function _querySelector(node, selectors) {
|
|
|
|
let element = null;
|
|
|
|
|
|
|
|
node && _visitNode(node, n => {
|
|
|
|
if (n.nodeType === 1 /* ELEMENT_NODE */
|
|
|
|
&& n.nodeName === selectors) {
|
|
|
|
element = n;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Visits each Node in the tree of a specific root Node (using depth-first
|
|
|
|
* traversal) and invokes a specific callback until the callback returns true.
|
|
|
|
*
|
|
|
|
* @param {Node} node - The root Node which represents the tree of Nodes to
|
|
|
|
* visit.
|
|
|
|
* @param {Function} callback - The callback to invoke with each visited Node.
|
|
|
|
* @returns {boolean} - True if the specified callback returned true for a Node
|
|
|
|
* (at which point the visiting stopped); otherwise, false.
|
|
|
|
*/
|
|
|
|
function _visitNode(node, callback) {
|
|
|
|
if (callback(node)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* eslint-disable no-param-reassign, no-extra-parens */
|
|
|
|
|
|
|
|
if ((node = node.firstChild)) {
|
|
|
|
do {
|
|
|
|
if (_visitNode(node, callback)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} while ((node = node.nextSibling));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* eslint-enable no-param-reassign, no-extra-parens */
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
(global => {
|
2018-04-30 06:52:41 +00:00
|
|
|
// DOMParser
|
|
|
|
//
|
|
|
|
// Required by:
|
|
|
|
// - lib-jitsi-meet requires this if using WebSockets
|
|
|
|
global.DOMParser = DOMParser;
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
// addEventListener
|
|
|
|
//
|
|
|
|
// Required by:
|
|
|
|
// - jQuery
|
|
|
|
if (typeof global.addEventListener === 'undefined') {
|
|
|
|
// eslint-disable-next-line no-empty-function
|
|
|
|
global.addEventListener = () => {};
|
|
|
|
}
|
|
|
|
|
2018-08-01 20:37:15 +00:00
|
|
|
// removeEventListener
|
|
|
|
//
|
|
|
|
// Required by:
|
|
|
|
// - features/base/conference/middleware
|
|
|
|
if (typeof global.removeEventListener === 'undefined') {
|
|
|
|
// eslint-disable-next-line no-empty-function
|
|
|
|
global.removeEventListener = () => {};
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
// document
|
|
|
|
//
|
|
|
|
// Required by:
|
|
|
|
// - jQuery
|
|
|
|
// - Strophe
|
|
|
|
if (typeof global.document === 'undefined') {
|
|
|
|
const document
|
|
|
|
= new DOMParser().parseFromString(
|
2017-06-15 00:40:51 +00:00
|
|
|
'<html><head></head><body></body></html>',
|
|
|
|
'text/xml');
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
// document.addEventListener
|
|
|
|
//
|
|
|
|
// Required by:
|
|
|
|
// - jQuery
|
|
|
|
if (typeof document.addEventListener === 'undefined') {
|
|
|
|
// eslint-disable-next-line no-empty-function
|
|
|
|
document.addEventListener = () => {};
|
|
|
|
}
|
|
|
|
|
2017-09-01 19:14:03 +00:00
|
|
|
// document.cookie
|
|
|
|
//
|
|
|
|
// Required by:
|
|
|
|
// - herment
|
|
|
|
if (typeof document.cookie === 'undefined') {
|
|
|
|
document.cookie = '';
|
|
|
|
}
|
|
|
|
|
2018-03-06 00:47:13 +00:00
|
|
|
// document.implementation.createHTMLDocument
|
|
|
|
//
|
|
|
|
// Required by:
|
|
|
|
// - jQuery
|
|
|
|
if (typeof document.implementation.createHTMLDocument === 'undefined') {
|
|
|
|
document.implementation.createHTMLDocument = function(title = '') {
|
|
|
|
const htmlDocument
|
|
|
|
= new DOMParser().parseFromString(
|
|
|
|
`<html>
|
|
|
|
<head><title>${title}</title></head>
|
|
|
|
<body></body>
|
|
|
|
</html>`,
|
|
|
|
'text/xml');
|
|
|
|
|
|
|
|
Object.defineProperty(htmlDocument, 'body', {
|
|
|
|
get() {
|
|
|
|
return htmlDocument.getElementsByTagName('body')[0];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return htmlDocument;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
// Element.querySelector
|
|
|
|
//
|
|
|
|
// Required by:
|
2017-10-17 19:08:32 +00:00
|
|
|
// - lib-jitsi-meet/modules/xmpp
|
2016-10-05 14:36:59 +00:00
|
|
|
const elementPrototype
|
|
|
|
= Object.getPrototypeOf(document.documentElement);
|
|
|
|
|
2017-02-15 17:04:10 +00:00
|
|
|
if (elementPrototype) {
|
|
|
|
if (typeof elementPrototype.querySelector === 'undefined') {
|
|
|
|
elementPrototype.querySelector = function(selectors) {
|
|
|
|
return _querySelector(this, selectors);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-03-29 01:04:42 +00:00
|
|
|
// Element.remove
|
|
|
|
//
|
|
|
|
// Required by:
|
|
|
|
// - lib-jitsi-meet ChatRoom#onPresence parsing
|
|
|
|
if (typeof elementPrototype.remove === 'undefined') {
|
|
|
|
elementPrototype.remove = function() {
|
|
|
|
if (this.parentNode !== null) {
|
|
|
|
this.parentNode.removeChild(this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-02-15 17:04:10 +00:00
|
|
|
// Element.innerHTML
|
|
|
|
//
|
|
|
|
// Required by:
|
|
|
|
// - jQuery's .append method
|
|
|
|
if (!elementPrototype.hasOwnProperty('innerHTML')) {
|
|
|
|
Object.defineProperty(elementPrototype, 'innerHTML', {
|
|
|
|
get() {
|
|
|
|
return this.childNodes.toString();
|
|
|
|
},
|
|
|
|
|
|
|
|
set(innerHTML) {
|
|
|
|
// MDN says: removes all of element's children, parses
|
|
|
|
// the content string and assigns the resulting nodes as
|
|
|
|
// children of the element.
|
|
|
|
|
|
|
|
// Remove all of element's children.
|
|
|
|
this.textContent = '';
|
|
|
|
|
|
|
|
// Parse the content string.
|
|
|
|
const d
|
|
|
|
= new DOMParser().parseFromString(
|
2017-06-15 00:40:51 +00:00
|
|
|
`<div>${innerHTML}</div>`,
|
|
|
|
'text/xml');
|
2017-02-15 17:04:10 +00:00
|
|
|
|
|
|
|
// Assign the resulting nodes as children of the
|
|
|
|
// element.
|
|
|
|
const documentElement = d.documentElement;
|
|
|
|
let child;
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-cond-assign
|
|
|
|
while (child = documentElement.firstChild) {
|
|
|
|
this.appendChild(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-03-29 01:04:42 +00:00
|
|
|
|
|
|
|
// Element.children
|
|
|
|
//
|
|
|
|
// Required by:
|
|
|
|
// - lib-jitsi-meet ChatRoom#onPresence parsing
|
|
|
|
if (!elementPrototype.hasOwnProperty('children')) {
|
|
|
|
Object.defineProperty(elementPrototype, 'children', {
|
|
|
|
get() {
|
|
|
|
const nodes = this.childNodes;
|
|
|
|
const children = [];
|
|
|
|
let i = 0;
|
|
|
|
let node = nodes[i];
|
|
|
|
|
|
|
|
while (node) {
|
|
|
|
if (node.nodeType === 1) {
|
|
|
|
children.push(node);
|
|
|
|
}
|
|
|
|
i += 1;
|
|
|
|
node = nodes[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return children;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
global.document = document;
|
|
|
|
}
|
|
|
|
|
|
|
|
// location
|
|
|
|
if (typeof global.location === 'undefined') {
|
|
|
|
global.location = {
|
2017-08-04 12:57:48 +00:00
|
|
|
href: '',
|
|
|
|
|
|
|
|
// Required by:
|
|
|
|
// - lib-jitsi-meet/modules/xmpp/xmpp.js
|
|
|
|
search: ''
|
2016-10-05 14:36:59 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-07-05 20:23:10 +00:00
|
|
|
const { navigator } = global;
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
if (navigator) {
|
|
|
|
// userAgent
|
|
|
|
//
|
|
|
|
// Required by:
|
2018-01-19 17:50:03 +00:00
|
|
|
// - lib-jitsi-meet/modules/browser/BrowserDetection.js
|
2017-09-20 15:05:07 +00:00
|
|
|
let userAgent = navigator.userAgent || '';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-09-20 15:05:07 +00:00
|
|
|
// react-native/version
|
|
|
|
const { name, version } = require('react-native/package.json');
|
|
|
|
let rn = name || 'react-native';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-09-20 15:05:07 +00:00
|
|
|
version && (rn += `/${version}`);
|
|
|
|
if (userAgent.indexOf(rn) === -1) {
|
|
|
|
userAgent = userAgent ? `${rn} ${userAgent}` : rn;
|
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-09-20 15:05:07 +00:00
|
|
|
// (OS version)
|
|
|
|
const os = `(${Platform.OS} ${Platform.Version})`;
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-09-20 15:05:07 +00:00
|
|
|
if (userAgent.indexOf(os) === -1) {
|
|
|
|
userAgent = userAgent ? `${userAgent} ${os}` : os;
|
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-09-20 15:05:07 +00:00
|
|
|
navigator.userAgent = userAgent;
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// WebRTC
|
2020-05-06 09:22:09 +00:00
|
|
|
require('./webrtc');
|
2019-01-31 13:26:00 +00:00
|
|
|
|
2021-09-07 14:38:44 +00:00
|
|
|
// Performance API
|
|
|
|
|
2022-01-14 10:44:02 +00:00
|
|
|
// RN only provides the now() method, since the polyfill refers the global
|
|
|
|
// performance object itself we extract it here to avoid infinite recursion.
|
|
|
|
const performanceNow = global.performance.now;
|
2021-09-07 14:38:44 +00:00
|
|
|
|
|
|
|
const perf = require('react-native-performance');
|
|
|
|
|
2021-09-09 14:00:34 +00:00
|
|
|
global.performance = perf.default;
|
2022-01-14 10:44:02 +00:00
|
|
|
global.performance.now = performanceNow;
|
2021-09-07 14:38:44 +00:00
|
|
|
global.PerformanceObserver = perf.PerformanceObserver;
|
|
|
|
|
2019-01-31 13:26:00 +00:00
|
|
|
// CallStats
|
|
|
|
//
|
|
|
|
// Required by:
|
|
|
|
// - lib-jitsi-meet
|
2017-04-12 14:34:19 +00:00
|
|
|
require('react-native-callstats/csio-polyfill');
|
2019-01-31 13:26:00 +00:00
|
|
|
global.callstats = require('react-native-callstats/callstats');
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
// XMLHttpRequest
|
|
|
|
if (global.XMLHttpRequest) {
|
2017-09-07 17:30:09 +00:00
|
|
|
const { prototype } = global.XMLHttpRequest;
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
// XMLHttpRequest.responseXML
|
|
|
|
//
|
|
|
|
// Required by:
|
|
|
|
// - Strophe
|
2017-02-15 17:19:36 +00:00
|
|
|
if (prototype && !prototype.hasOwnProperty('responseXML')) {
|
2016-10-05 14:36:59 +00:00
|
|
|
Object.defineProperty(prototype, 'responseXML', {
|
|
|
|
get() {
|
2017-09-07 17:30:09 +00:00
|
|
|
const { responseText } = this;
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-09-07 17:30:09 +00:00
|
|
|
return (
|
|
|
|
responseText
|
|
|
|
&& new DOMParser().parseFromString(
|
2017-06-15 00:40:51 +00:00
|
|
|
responseText,
|
2017-09-07 17:30:09 +00:00
|
|
|
'text/xml'));
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-14 13:59:49 +00:00
|
|
|
// Timers
|
|
|
|
//
|
2017-02-15 17:19:36 +00:00
|
|
|
// React Native's timers won't run while the app is in the background, this
|
|
|
|
// is a known limitation. Replace them with a background-friendly
|
2017-02-14 13:59:49 +00:00
|
|
|
// alternative.
|
|
|
|
//
|
|
|
|
// Required by:
|
|
|
|
// - lib-jitsi-meet
|
|
|
|
// - Strophe
|
2020-09-17 09:39:10 +00:00
|
|
|
if (Platform.OS === 'android') {
|
|
|
|
global.clearTimeout = BackgroundTimer.clearTimeout.bind(BackgroundTimer);
|
|
|
|
global.clearInterval = BackgroundTimer.clearInterval.bind(BackgroundTimer);
|
|
|
|
global.setInterval = BackgroundTimer.setInterval.bind(BackgroundTimer);
|
|
|
|
global.setTimeout = (fn, ms = 0) => BackgroundTimer.setTimeout(fn, ms);
|
|
|
|
}
|
2017-02-14 13:59:49 +00:00
|
|
|
|
2020-05-06 09:22:09 +00:00
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
})(global || window || this); // eslint-disable-line no-invalid-this
|