import { NativeModulesProxy, EventEmitter, Subscription } from 'expo-modules-core'; // Import the native module. On web, it will be resolved to V2rayModule.web.ts // and on native platforms to V2rayModule.ts import V2rayModule from './V2rayModuleModule'; import V2rayModuleView from './V2rayModuleView'; import { ChangeEventPayload, V2rayModuleViewProps } from './V2rayModule.types'; // Get the native constant value. export const PI = V2rayModule.PI; export function hello(): string { return V2rayModule.hello(); } export async function setValueAsync(value: string) { return await V2rayModule.setValueAsync(value); } // For now the events are not going through the JSI, so we have to use its bridge equivalent. // This will be fixed in the stable release and built into the module object. // Note: On web, NativeModulesProxy.V2rayModule is undefined, so we fall back to the directly imported implementation const emitter = new EventEmitter(NativeModulesProxy.V2rayModule ?? V2rayModule); export function addChangeListener(listener: (event: ChangeEventPayload) => void): Subscription { return emitter.addListener('onChange', listener); } export { V2rayModuleView, V2rayModuleViewProps, ChangeEventPayload };