From 1e0a3ceb7476764c08e6ded0dcc5079237005721 Mon Sep 17 00:00:00 2001 From: virtuacoplenny Date: Wed, 28 Mar 2018 18:04:42 -0700 Subject: [PATCH] fix(chat): polyfills for lib-jitsi-meet ChatRoom#onPresence (#2678) The onPresence parsing was refactored to remove use of jQuery. This exposed three methods not available in react-native: ParentNode.children, ChildNode.remove, and document.querySelectorAll. The querySelectorAll change could be swapped for the already polyfilled querySelector, but children and remove had to be added. The polyfills are based on those supplied by MDN web docs, but modified to pass jitsi linting. --- .../native/polyfills-browser.js | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/react/features/base/lib-jitsi-meet/native/polyfills-browser.js b/react/features/base/lib-jitsi-meet/native/polyfills-browser.js index 5b435a8c5..86e70ce15 100644 --- a/react/features/base/lib-jitsi-meet/native/polyfills-browser.js +++ b/react/features/base/lib-jitsi-meet/native/polyfills-browser.js @@ -195,6 +195,18 @@ function _visitNode(node, callback) { }; } + // 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); + } + }; + } + // Element.innerHTML // // Required by: @@ -231,6 +243,31 @@ function _visitNode(node, callback) { } }); } + + // 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; + } + }); + } } // FIXME There is a weird infinite loop related to console.log and