/** * Copyright (c) Double Symmetry GmbH * Commercial use requires a license. See https://rntp.dev/pricing */ import { NativeEventEmitter, NativeModules, Platform } from 'react-native'; // Native module + event emitter selection. The web platform has its own // variant of this file (trackPlayerModule.web.ts) that the bundler resolves // via the `.web` extension — keeping `require` (a Metro/CJS construct that // does not exist in browser ESM bundlers like Vite/webpack) out of the web // bundle entirely. // @ts-expect-error global.__turboModuleProxy is injected by the New Architecture. const isTurboModuleEnabled = global.__turboModuleProxy != null; const TrackPlayerModule = isTurboModuleEnabled ? require('./NativeTrackPlayer').default : NativeModules.TrackPlayer; export const TrackPlayer = TrackPlayerModule ? TrackPlayerModule : new Proxy( {}, { get() { throw new Error( `The package '@rntp/player' 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' ); }, } ); export const emitter = new NativeEventEmitter( Platform.OS === 'android' ? null : TrackPlayer );