Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

browser.js 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. import { DOMParser } from '@xmldom/xmldom';
  2. import { Platform } from 'react-native';
  3. import BackgroundTimer from 'react-native-background-timer';
  4. import 'promise.allsettled/auto'; // Promise.allSettled.
  5. import 'react-native-url-polyfill/auto'; // Complete URL polyfill.
  6. import Storage from './Storage';
  7. /**
  8. * Implements an absolute minimum of the common logic of
  9. * {@code Document.querySelector} and {@code Element.querySelector}. Implements
  10. * the most simple of selectors necessary to satisfy the call sites at the time
  11. * of this writing (i.e. Select by tagName).
  12. *
  13. * @param {Node} node - The Node which is the root of the tree to query.
  14. * @param {string} selectors - The group of CSS selectors to match on.
  15. * @returns {Element} - The first Element which is a descendant of the specified
  16. * node and matches the specified group of selectors.
  17. */
  18. function _querySelector(node, selectors) {
  19. let element = null;
  20. node && _visitNode(node, n => {
  21. if (n.nodeType === 1 /* ELEMENT_NODE */
  22. && n.nodeName === selectors) {
  23. element = n;
  24. return true;
  25. }
  26. return false;
  27. });
  28. return element;
  29. }
  30. /**
  31. * Visits each Node in the tree of a specific root Node (using depth-first
  32. * traversal) and invokes a specific callback until the callback returns true.
  33. *
  34. * @param {Node} node - The root Node which represents the tree of Nodes to
  35. * visit.
  36. * @param {Function} callback - The callback to invoke with each visited Node.
  37. * @returns {boolean} - True if the specified callback returned true for a Node
  38. * (at which point the visiting stopped); otherwise, false.
  39. */
  40. function _visitNode(node, callback) {
  41. if (callback(node)) {
  42. return true;
  43. }
  44. /* eslint-disable no-param-reassign, no-extra-parens */
  45. if ((node = node.firstChild)) {
  46. do {
  47. if (_visitNode(node, callback)) {
  48. return true;
  49. }
  50. } while ((node = node.nextSibling));
  51. }
  52. /* eslint-enable no-param-reassign, no-extra-parens */
  53. return false;
  54. }
  55. (global => {
  56. // DOMParser
  57. //
  58. // Required by:
  59. // - lib-jitsi-meet requires this if using WebSockets
  60. global.DOMParser = DOMParser;
  61. // addEventListener
  62. //
  63. // Required by:
  64. // - jQuery
  65. if (typeof global.addEventListener === 'undefined') {
  66. // eslint-disable-next-line no-empty-function
  67. global.addEventListener = () => {};
  68. }
  69. // removeEventListener
  70. //
  71. // Required by:
  72. // - features/base/conference/middleware
  73. if (typeof global.removeEventListener === 'undefined') {
  74. // eslint-disable-next-line no-empty-function
  75. global.removeEventListener = () => {};
  76. }
  77. // document
  78. //
  79. // Required by:
  80. // - jQuery
  81. // - Strophe
  82. if (typeof global.document === 'undefined') {
  83. const document
  84. = new DOMParser().parseFromString(
  85. '<html><head></head><body></body></html>',
  86. 'text/xml');
  87. // document.addEventListener
  88. //
  89. // Required by:
  90. // - jQuery
  91. if (typeof document.addEventListener === 'undefined') {
  92. // eslint-disable-next-line no-empty-function
  93. document.addEventListener = () => {};
  94. }
  95. // document.cookie
  96. //
  97. // Required by:
  98. // - herment
  99. if (typeof document.cookie === 'undefined') {
  100. document.cookie = '';
  101. }
  102. // document.implementation.createHTMLDocument
  103. //
  104. // Required by:
  105. // - jQuery
  106. if (typeof document.implementation.createHTMLDocument === 'undefined') {
  107. document.implementation.createHTMLDocument = function(title = '') {
  108. const htmlDocument
  109. = new DOMParser().parseFromString(
  110. `<html>
  111. <head><title>${title}</title></head>
  112. <body></body>
  113. </html>`,
  114. 'text/xml');
  115. Object.defineProperty(htmlDocument, 'body', {
  116. get() {
  117. return htmlDocument.getElementsByTagName('body')[0];
  118. }
  119. });
  120. return htmlDocument;
  121. };
  122. }
  123. // Element.querySelector
  124. //
  125. // Required by:
  126. // - lib-jitsi-meet/modules/xmpp
  127. const elementPrototype
  128. = Object.getPrototypeOf(document.documentElement);
  129. if (elementPrototype) {
  130. if (typeof elementPrototype.querySelector === 'undefined') {
  131. elementPrototype.querySelector = function(selectors) {
  132. return _querySelector(this, selectors);
  133. };
  134. }
  135. // Element.remove
  136. //
  137. // Required by:
  138. // - lib-jitsi-meet ChatRoom#onPresence parsing
  139. if (typeof elementPrototype.remove === 'undefined') {
  140. elementPrototype.remove = function() {
  141. if (this.parentNode !== null) {
  142. this.parentNode.removeChild(this);
  143. }
  144. };
  145. }
  146. // Element.innerHTML
  147. //
  148. // Required by:
  149. // - jQuery's .append method
  150. if (!elementPrototype.hasOwnProperty('innerHTML')) {
  151. Object.defineProperty(elementPrototype, 'innerHTML', {
  152. get() {
  153. return this.childNodes.toString();
  154. },
  155. set(innerHTML) {
  156. // MDN says: removes all of element's children, parses
  157. // the content string and assigns the resulting nodes as
  158. // children of the element.
  159. // Remove all of element's children.
  160. this.textContent = '';
  161. // Parse the content string.
  162. const d
  163. = new DOMParser().parseFromString(
  164. `<div>${innerHTML}</div>`,
  165. 'text/xml');
  166. // Assign the resulting nodes as children of the
  167. // element.
  168. const documentElement = d.documentElement;
  169. let child;
  170. // eslint-disable-next-line no-cond-assign
  171. while (child = documentElement.firstChild) {
  172. this.appendChild(child);
  173. }
  174. }
  175. });
  176. }
  177. // Element.children
  178. //
  179. // Required by:
  180. // - lib-jitsi-meet ChatRoom#onPresence parsing
  181. if (!elementPrototype.hasOwnProperty('children')) {
  182. Object.defineProperty(elementPrototype, 'children', {
  183. get() {
  184. const nodes = this.childNodes;
  185. const children = [];
  186. let i = 0;
  187. let node = nodes[i];
  188. while (node) {
  189. if (node.nodeType === 1) {
  190. children.push(node);
  191. }
  192. i += 1;
  193. node = nodes[i];
  194. }
  195. return children;
  196. }
  197. });
  198. }
  199. }
  200. global.document = document;
  201. }
  202. // location
  203. if (typeof global.location === 'undefined') {
  204. global.location = {
  205. href: '',
  206. // Required by:
  207. // - lib-jitsi-meet/modules/xmpp/xmpp.js
  208. search: ''
  209. };
  210. }
  211. const { navigator } = global;
  212. if (navigator) {
  213. // userAgent
  214. //
  215. // Required by:
  216. // - lib-jitsi-meet/modules/browser/BrowserDetection.js
  217. let userAgent = navigator.userAgent || '';
  218. // react-native/version
  219. const { name, version } = require('react-native/package.json');
  220. let rn = name || 'react-native';
  221. version && (rn += `/${version}`);
  222. if (userAgent.indexOf(rn) === -1) {
  223. userAgent = userAgent ? `${rn} ${userAgent}` : rn;
  224. }
  225. // (OS version)
  226. const os = `(${Platform.OS} ${Platform.Version})`;
  227. if (userAgent.indexOf(os) === -1) {
  228. userAgent = userAgent ? `${userAgent} ${os}` : os;
  229. }
  230. navigator.userAgent = userAgent;
  231. }
  232. // WebRTC
  233. require('./webrtc');
  234. // Performance API
  235. // RN only provides the now() method, since the polyfill refers the global
  236. // performance object itself we extract it here to avoid infinite recursion.
  237. const performanceNow = global.performance.now;
  238. const perf = require('react-native-performance');
  239. global.performance = perf.default;
  240. global.performance.now = performanceNow;
  241. global.PerformanceObserver = perf.PerformanceObserver;
  242. // Timers
  243. //
  244. // React Native's timers won't run while the app is in the background, this
  245. // is a known limitation. Replace them with a background-friendly alternative.
  246. if (Platform.OS === 'android') {
  247. global.clearTimeout = BackgroundTimer.clearTimeout.bind(BackgroundTimer);
  248. global.clearInterval = BackgroundTimer.clearInterval.bind(BackgroundTimer);
  249. global.setInterval = BackgroundTimer.setInterval.bind(BackgroundTimer);
  250. global.setTimeout = (fn, ms = 0) => BackgroundTimer.setTimeout(fn, ms);
  251. }
  252. // localStorage
  253. if (typeof global.localStorage === 'undefined') {
  254. global.localStorage = new Storage('@jitsi-meet/');
  255. }
  256. // sessionStorage
  257. //
  258. // Required by:
  259. // - herment
  260. // - Strophe
  261. if (typeof global.sessionStorage === 'undefined') {
  262. global.sessionStorage = new Storage();
  263. }
  264. })(global || window || this); // eslint-disable-line no-invalid-this