import {EmitterSubscription, NativeEventEmitter, NativeModules} from 'react-native' import {NativePrinter} from '../native' import {DiscoveryEventData, DiscoveryEventType, ScanResult} from './types' // For events only - will be refactored later const eventEmitter = new NativeEventEmitter(NativeModules.RNThermalPrinter) /** * Scan for Bluetooth devices (compatible with react-native-bluetooth-escpos-printer) * Just call native method and let native handle the events */ export async function scanDevices(): Promise { // Simply call native and return the result // Native will emit events that users can listen to return NativePrinter.scanBluetoothDevices() } /** * Stop scanning for Bluetooth devices */ export async function stopScanDevices(): Promise { return NativePrinter.stopScanDevices() } /** * Add event listener for Bluetooth events with type safety */ export function addDiscoveryEventListener( event: T, listener: (data: DiscoveryEventData[T]) => void, ): EmitterSubscription { return eventEmitter.addListener(event, listener) } /** * Remove event listener */ export function removeDiscoveryEventListener(subscription: EmitterSubscription): void { subscription.remove() }