jiti-meet/react/features/base/util/loadScript.native.js

27 lines
915 B
JavaScript
Raw Normal View History

/**
2016-12-07 22:00:54 +00:00
* Loads a script from a specific URL. React Native cannot load a JS
* file/resource/URL via a <script> HTML element, so the implementation
2017-08-31 19:16:44 +00:00
* fetches the specified <tt>url</tt> as plain text using {@link fetch()} and
* then evaluates the fetched string as JavaScript code (using {@link eval()}).
*
2017-08-31 19:16:44 +00:00
* @param {string} url - The absolute URL from which the script is to be
2016-12-07 22:00:54 +00:00
* (down)loaded.
* @returns {void}
*/
2016-12-07 22:00:54 +00:00
export function loadScript(url) {
return (
fetch(url, { method: 'GET' })
2016-12-07 22:00:54 +00:00
.then(response => {
switch (response.status) {
case 200:
return response.responseText || response.text();
default:
throw response.statusText;
}
})
.then(responseText => {
eval.call(window, responseText); // eslint-disable-line no-eval
}));
}