try{let e=typeof window<`u`?window:typeof global<`u`?global:typeof globalThis<`u`?globalThis:typeof self<`u`?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]=`ef58a85b-d8ca-4b49-8377-a8f7590de9e0`,e._sentryDebugIdIdentifier=`sentry-dbid-ef58a85b-d8ca-4b49-8377-a8f7590de9e0`)}catch{}import"./rolldown-runtime-eb2nym32.js";import{Ia as e,pg as t}from"./entry.client-dr7r6s9a.js";import{n,r,t as i}from"./bluetoothManagerPlugin-lxlkwq70.js";var a=class{bluetoothManagerPlugin;logger=new t(`FireOSBluetoothAdaptor`);constructor(){let t=r();if(!t)throw new e;this.bluetoothManagerPlugin=t}deviceScan(e,t,n){return n.aborted?(this.logger.info(`Scan aborted by caller before start`),Promise.resolve()):(this.logger.info(`Starting Bluetooth scan`),n.addEventListener(`abort`,()=>{this.logger.info(`Scanning aborted by caller`),this.bluetoothManagerPlugin.stopScan(()=>{this.logger.info(`Scan stopped successfully`)},e=>{this.logger.error(`Error stopping scan: ${e}`)})},{once:!0}),this.bluetoothManagerPlugin.scanDevices([1284,1288],t=>{if(n.aborted){this.logger.info(`Device scan aborted by caller`);return}e([{name:t.deviceName,macAddress:t.deviceAddress}])},e=>{if(n.aborted){this.logger.info(`Device scan aborted by caller, ignoring error: ${e}`);return}t(Error(`Scanning failed: ${e}`))}),Promise.resolve())}pairDevice(e,t,n,r){return r.aborted?(this.logger.info(`Pairing aborted by caller before start`),Promise.resolve()):(this.bondDevice(e,t,n,r,!1),Promise.resolve())}bondDevice(e,t,r,a,o){this.bluetoothManagerPlugin.bondDevice(e,e=>{if(a.aborted){this.logger.info(`Pairing aborted by caller`);return}e===n.Bonded&&t()},n=>{if(a.aborted){this.logger.info(`Pairing aborted by caller, ignoring error: ${n}`);return}n===i.AlreadyBonded&&!o?this.rebond(e,t,r,a):r(Error(`Bonding failed: ${n}`))})}rebond(e,t,r,i){this.logger.info(`Device ${e} is already bonded; unbonding before re-bond`),this.bluetoothManagerPlugin.unbondDevice(e,a=>{if(i.aborted){this.logger.info(`Rebond aborted by caller during unbond`);return}a===n.Unbonded&&(this.logger.info(`Device ${e} unbonded; re-bonding`),this.bondDevice(e,t,r,i,!0))},e=>{if(i.aborted){this.logger.info(`Rebond aborted by caller, ignoring unbond error: ${e}`);return}r(Error(`Unbonding failed: ${e}`))})}};export{a as FireOSBluetoothAdaptor};