1import{W as u}from"./app-BMB7SW2A.js";class l extends u{constructor(){super(...arguments),this.devices=new Map,this.services=new Map,this.characteristicListeners=new Map}async initialize(e){if(!navigator.bluetooth)throw new Error("Web Bluetooth API is not available")}shimWebBluetooth(){}async isAvailable(){if(!navigator.bluetooth)return{available:!1};try{return{available:await navigator.bluetooth.getAvailability()}}catch{return{available:!1}}}async isEnabled(){const{available:e}=await this.isAvailable();return{enabled:e}}async isLocationEnabled(){return{enabled:!0}}async openAppSettings(){throw new Error("openAppSettings is not supported on web")}async openBluetoothSettings(){throw new Error("openBluetoothSettings is not supported on web")}async openLocationSettings(){throw new Error("openLocationSettings is not supported on web")}async checkPermissions(){return{bluetooth:"prompt",location:"granted"}}async requestPermissions(){return{bluetooth:"granted",location:"granted"}}async startScan(e){var t;if(!navigator.bluetooth)throw new Error("Web Bluetooth API is not available");const i={};e?.services&&e.services.length>0?i.filters=[{services:e.services}]:i.acceptAllDevices=!0,e?.services&&(i.optionalServices=e.services);try{const c=await navigator.bluetooth.requestDevice(i),r={deviceId:c.id,name:(t=c.name)!==null&&t!==void 0?t:null};this.devices.set(c.id,c),this.notifyListeners("deviceScanned",{device:r})}catch(c){if(c instanceof Error&&c.name==="NotFoundError")return;throw c}}async stopScan(){}async connect(e){const t=this.devices.get(e.deviceId);if(!t)throw new Error(`Device ${e.deviceId} not found`);if(!t.gatt)throw new Error(`Device ${e.deviceId} does not support GATT`);await t.gatt.connect(),this.notifyListeners("deviceConnected",{deviceId:e.deviceId})}async disconnect(e){var t;const i=this.devices.get(e.deviceId);if(!i)throw new Error(`Device ${e.deviceId} not found`);!((t=i.gatt)===null||t===void 0)&&t.connected&&i.gatt.disconnect(),this.notifyListeners("deviceDisconnected",{deviceId:e.deviceId})}async createBond(e){throw new Error("createBond is not supported on web")}async isBonded(e){throw new Error("isBonded is not supported on web")}async discoverServices(e){var t;const i=this.devices.get(e.deviceId);if(!(!((t=i?.gatt)===null||t===void 0)&&t.connected))throw new Error(`Device ${e.deviceId} is not connected`);const c=await i.gatt.getPrimaryServices(),r=[];for(const n of c){const a=await n.getCharacteristics(),o=await Promise.all(a.map(async s=>{const d=await s.getDescriptors();return{uuid:s.uuid,properties:{broadcast:s.properties.broadcast,read:s.properties.read,writeWithoutResponse:s.properties.writeWithoutResponse,write:s.properties.write,notify:s.properties.notify,indicate:s.properties.indicate,authenticatedSignedWrites:s.properties.authenticatedSignedWrites,extendedProperties:!1},descriptors:d.map(v=>({uuid:v.uuid}))}}));r.push({uuid:n.uuid,characteristics:o})}this.services.set(e.deviceId,r)}async getServices(e){const t=this.services.get(e.deviceId);return t?{services:t}:{services:[]}}async getConnectedDevices(){var e,t;const i=[];for(const[c,r]of this.devices)!((e=r.gatt)===null||e===void 0)&&e.connected&&i.push({deviceId:c,name:(t=r.name)!==null&&t!==void 0?t:null});return{devices:i}}async readCharacteristic(e){var t;const i=this.devices.get(e.deviceId);if(!(!((t=i?.gatt)===null||t===void 0)&&t.connected))throw new Error(`Device ${e.deviceId} is not connected`);const n=await(await(await i.gatt.getPrimaryService(e.service)).getCharacteristic(e.characteristic)).readValue(),a=[];for(let o=0;o<n.byteLength;o++)a.push(n.getUint8(o));return{value:a}}async writeCharacteristic(e){var t;const i=this.devices.get(e.deviceId);if(!(!((t=i?.gatt)===null||t===void 0)&&t.connected))throw new Error(`Device ${e.deviceId} is not connected`);const r=await(await i.gatt.getPrimaryService(e.service)).getCharacteristic(e.characteristic),n=new Uint8Array(e.value);e.type==="withoutResponse"?await r.writeValueWithoutResponse(n):await r.writeValueWithResponse(n)}async startCharacteristicNotifications(e){var t;const i=this.devices.get(e.deviceId);if(!(!((t=i?.gatt)===null||t===void 0)&&t.connected))throw new Error(`Device ${e.deviceId} is not connected`);const r=await(await i.gatt.getPrimaryService(e.service)).getCharacteristic(e.characteristic),n=`${e.deviceId}-${e.service}-${e.characteristic}`,a=o=>{const s=o.target.value;if(!s)return;const d=[];for(let v=0;v<s.byteLength;v++)d.push(s.getUint8(v));this.notifyListeners("characteristicChanged",{deviceId:e.deviceId,service:e.service,characteristic:e.characteristic,value:d})};r.addEventListener("characteristicvaluechanged",a),this.characteristicListeners.set(n,a),await r.startNotifications()}async stopCharacteristicNotifications(e){var t;const i=this.devices.get(e.deviceId);if(!(!((t=i?.gatt)===null||t===void 0)&&t.connected))throw new Error(`Device ${e.deviceId} is not connected`);const r=await(await i.gatt.getPrimaryService(e.service)).getCharacteristic(e.characteristic),n=`${e.deviceId}-${e.service}-${e.characteristic}`,a=this.characteristicListeners.get(n);a&&(r.removeEventListener("characteristicvaluechanged",a),this.characteristicListeners.delete(n)),await r.stopNotifications()}async readDescriptor(e){var t;const i=this.devices.get(e.deviceId);if(!(!((t=i?.gatt)===null||t===void 0)&&t.connected))throw new Error(`Device ${e.deviceId} is not connected`);const a=(await(await(await i.gatt.getPrimaryService(e.service)).getCharacteristic(e.characteristic)).getDescriptors()).find(d=>d.uuid===e.descriptor);if(!a)throw new Error(`Descriptor ${e.descriptor} not found`);const o=await a.readValue(),s=[];for(let d=0;d<o.byteLength;d++)s.push(o.getUint8(d));return{value:s}}async writeDescriptor(e){var t;const i=this.devices.get(e.deviceId);if(!(!((t=i?.gatt)===null||t===void 0)&&t.connected))throw new Error(`Device ${e.deviceId} is not connected`);const a=(await(await(await i.gatt.getPrimaryService(e.service)).getCharacteristic(e.characteristic)).getDescriptors()).find(s=>s.uuid===e.descriptor);if(!a)throw new Error(`Descriptor ${e.descriptor} not found`);const o=new Uint8Array(e.value);await a.writeValue(o)}async readRssi(e){throw new Error("readRssi is not supported on web")}async requestMtu(e){throw new Error("requestMtu is not supported on web")}async requestConnectionPriority(e){throw new Error("requestConnectionPriority is not supported on web")}async startAdvertising(e){throw new Error("startAdvertising is not supported on web")}async addGattService(e){throw new Error("addGattService is not supported on web")}async removeGattService(e){throw new Error("removeGattService is not supported on web")}async setGattCharacteristicValue(e){throw new Error("setGattCharacteristicValue is not supported on web")}async notifyGattCharacteristicChanged(e){throw new Error("notifyGattCharacteristicChanged is not supported on web")}async stopAdvertising(){throw new Error("stopAdvertising is not supported on web")}async startForegroundService(e){throw new Error("startForegroundService is not supported on web")}async stopForegroundService(){throw new Error("stopForegroundService is not supported on web")}async getPluginVersion(){return{version:"web"}}}export{l as BluetoothLowEnergyWeb};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.