UNPKG

@applicaster/zapp-react-dom-app

Version:

Zapp App Component for Applicaster's Quick Brick React Native App

70 lines (58 loc) 2.27 kB
import { QuickBrickCommunicationModule } from "./QuickBrickCommunicationModule"; import { AnalyticsBridge } from "./AnalyticsBridge"; import { getStorageModule } from "./Storage"; import { DeviceEventEmitter } from "./DeviceEventEmitter"; import { AppLoaderBridge } from "./AppLoaderBridge"; import { isSamsungPlatform, isLgPlatform } from "../App/Loader/utils/platform"; // Polyfill for abort controller required by shaka-player 4.x.x import "abortcontroller-polyfill/dist/polyfill-patch-fetch"; // @babel/polyfill is deprecated and the maintainers recommend to use corejs and regenerator // https://github.com/zloirock/core-js#babelpolyfill import "core-js/stable"; import "regenerator-runtime/runtime"; // Polyfill for ShadowDOM, Array.from, Object.assign, and more for webcomponents import "@webcomponents/webcomponentsjs"; const PLATFORM_KEYS = { samsung: "samsung_tv", lg: "lg_tv", web: "web", }; // const DESKTOP_BROWSER = [PLATFORMS.linux, PLATFORMS.mac, PLATFORMS.win]; export function registerNativeModulesPolyfills(NativeModules) { NativeModules.QuickBrickCommunicationModule = QuickBrickCommunicationModule; NativeModules.LocalStorage = getStorageModule("localStorage"); NativeModules.SessionStorage = getStorageModule("sessionStorage"); NativeModules.AnalyticsBridge = AnalyticsBridge; NativeModules.AppLoaderBridge = AppLoaderBridge; } function getWebPlatform(fallbackPlatform) { try { if (isLgPlatform()) { return PLATFORM_KEYS.lg; } if (isSamsungPlatform()) { return PLATFORM_KEYS.samsung; } return fallbackPlatform; } catch (e) { return fallbackPlatform; } } export function overloadReactNativePlatform(Platform, fallbackPlatform) { if (Platform.OS === "web") { Platform.OS = getWebPlatform(fallbackPlatform); // inacurate (web) is can be web|lg-tv|samsung-tv Object.defineProperty(Platform, "Version", { get() { return window.sessionStorage.getItem("applicaster.v2_::_osVersion"); }, }); } } export function addReactNativeModules(ReactNative) { try { ReactNative.DeviceEventEmitter = DeviceEventEmitter; } catch (error) { // eslint-disable-next-line console.warn("could not attach the DeviceEventEmitter polyfill", error); } }