UNPKG

@lynx-js/web-core

Version:

This is an internal experimental package, do not use

33 lines 1.57 kB
// Copyright 2023 The Lynx Authors. All rights reserved. // Licensed under the Apache License Version 2.0 that can be found in the // LICENSE file in the root directory of this source tree. /* LYNX_NATIVE_MODULES_IMPORT */ import {} from '../../../types/index.js'; import { nativeModulesCallEndpoint, switchExposureServiceEndpoint, } from '../../endpoints.js'; export async function createNativeModules(uiThreadRpc, mainThreadRpc, nativeModulesMap) { const switchExposure = mainThreadRpc.createCall(switchExposureServiceEndpoint); const nativeModulesCall = uiThreadRpc.createCall(nativeModulesCallEndpoint); const lynxExposureModule = { resumeExposure() { switchExposure(true, true); }, stopExposure(param) { switchExposure(false, param.sendEvent ?? true); }, }; const bridgeModule = { call(name, data, callback) { nativeModulesCall(name, data, 'bridge').then(callback); }, }; const nativeModules = {}; const customNativeModules = {}; await Promise.all(Object.entries(nativeModulesMap).map(([moduleName, moduleStr]) => import(/* webpackIgnore: true */ moduleStr).then(module => customNativeModules[moduleName] = module?.default?.(nativeModules, (name, data) => nativeModulesCall(name, data, moduleName))))); /* LYNX_NATIVE_MODULES_ADD */ return Object.assign(nativeModules, { bridge: bridgeModule, LynxExposureModule: lynxExposureModule, ...customNativeModules, }); } //# sourceMappingURL=createNativeModules.js.map