UNPKG

react-native-wear-connectivity

Version:
43 lines (40 loc) 1.73 kB
import { AppRegistry } from 'react-native'; import { NativeModules, Platform } from 'react-native'; import { watchEvents } from './subscriptions'; import { sendMessage } from './messages'; import { DeviceEventEmitter } from 'react-native'; const LINKING_ERROR = `The package 'react-native-wear-connectivity' doesn't seem to be linked. Make sure: \n\n` + Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n'; // @ts-expect-error const isTurboModuleEnabled = global.__turboModuleProxy != null; const WearConnectivityModule = isTurboModuleEnabled ? require('./NativeWearConnectivity').default : NativeModules.WearConnectivity; const WearConnectivity = WearConnectivityModule ? WearConnectivityModule : new Proxy({}, { get() { throw new Error(LINKING_ERROR); } }); const startFileTransfer = (file, _metadata) => { return WearConnectivity.sendFile(file, _metadata); }; export { startFileTransfer, sendMessage, watchEvents, WearConnectivity }; // Define the headless task const WearConnectivityTask = async taskData => { // Emit an event or process the message as needed DeviceEventEmitter.emit('message', taskData); }; /** * Monitors file transfer events. * @param callback Function to receive transfer events. * @returns Unsubscribe function. */ export function monitorFileTransfers(callback) { const subscription = DeviceEventEmitter.addListener('FileTransferEvent', callback); return () => { subscription.remove(); }; } // Register the headless task with React Native AppRegistry.registerHeadlessTask('WearConnectivityTask', () => WearConnectivityTask); //# sourceMappingURL=index.js.map