diff --git a/package-lock.json b/package-lock.json index b435498..3f73bd4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@heroicons/react": "^2.2.0", "@tailwindcss/vite": "^4.1.17", + "@types/web-bluetooth": "^0.0.21", "konva": "^10.0.12", "pyodide": "^0.27.4", "react": "^19.2.0", @@ -1543,6 +1544,12 @@ "@types/react": "*" } }, + "node_modules/@types/web-bluetooth": { + "version": "0.0.21", + "resolved": "https://registry.npmjs.org/@types/web-bluetooth/-/web-bluetooth-0.0.21.tgz", + "integrity": "sha512-oIQLCGWtcFZy2JW77j9k8nHzAOpqMHLQejDA48XXMWH6tjCQHz5RCFz1bzsmROyL6PUm+LLnUiI4BCn221inxA==", + "license": "MIT" + }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "8.48.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.48.0.tgz", diff --git a/package.json b/package.json index 6cd6f4c..77b4e07 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "dependencies": { "@heroicons/react": "^2.2.0", "@tailwindcss/vite": "^4.1.17", + "@types/web-bluetooth": "^0.0.21", "konva": "^10.0.12", "pyodide": "^0.27.4", "react": "^19.2.0", diff --git a/src/web-bluetooth.d.ts b/src/web-bluetooth.d.ts deleted file mode 100644 index e9a191c..0000000 --- a/src/web-bluetooth.d.ts +++ /dev/null @@ -1,125 +0,0 @@ -// WebBluetooth API type declarations -// https://webbluetoothcg.github.io/web-bluetooth/ - -interface BluetoothRemoteGATTServer { - device: BluetoothDevice; - connected: boolean; - connect(): Promise; - disconnect(): void; - getPrimaryService(service: BluetoothServiceUUID): Promise; - getPrimaryServices(service?: BluetoothServiceUUID): Promise; -} - -interface BluetoothDevice extends EventTarget { - id: string; - name?: string; - gatt?: BluetoothRemoteGATTServer; - watchingAdvertisements: boolean; - watchAdvertisements(options?: WatchAdvertisementsOptions): Promise; - unwatchAdvertisements(): void; - forget(): Promise; - addEventListener( - type: 'gattserverdisconnected' | 'advertisementreceived', - listener: EventListenerOrEventListenerObject, - options?: boolean | AddEventListenerOptions - ): void; -} - -interface WatchAdvertisementsOptions { - signal?: AbortSignal; -} - -interface BluetoothRemoteGATTService extends EventTarget { - device: BluetoothDevice; - uuid: string; - isPrimary: boolean; - getCharacteristic(characteristic: BluetoothCharacteristicUUID): Promise; - getCharacteristics(characteristic?: BluetoothCharacteristicUUID): Promise; - getIncludedService(service: BluetoothServiceUUID): Promise; - getIncludedServices(service?: BluetoothServiceUUID): Promise; -} - -interface BluetoothRemoteGATTCharacteristic extends EventTarget { - service: BluetoothRemoteGATTService; - uuid: string; - properties: BluetoothCharacteristicProperties; - value?: DataView; - getDescriptor(descriptor: BluetoothDescriptorUUID): Promise; - getDescriptors(descriptor?: BluetoothDescriptorUUID): Promise; - readValue(): Promise; - writeValue(value: BufferSource): Promise; - writeValueWithResponse(value: BufferSource): Promise; - writeValueWithoutResponse(value: BufferSource): Promise; - startNotifications(): Promise; - stopNotifications(): Promise; - addEventListener( - type: 'characteristicvaluechanged', - listener: EventListenerOrEventListenerObject, - options?: boolean | AddEventListenerOptions - ): void; -} - -interface BluetoothCharacteristicProperties { - broadcast: boolean; - read: boolean; - writeWithoutResponse: boolean; - write: boolean; - notify: boolean; - indicate: boolean; - authenticatedSignedWrites: boolean; - reliableWrite: boolean; - writableAuxiliaries: boolean; -} - -interface BluetoothRemoteGATTDescriptor { - characteristic: BluetoothRemoteGATTCharacteristic; - uuid: string; - value?: DataView; - readValue(): Promise; - writeValue(value: BufferSource): Promise; -} - -interface RequestDeviceOptions { - filters?: BluetoothLEScanFilter[]; - optionalServices?: BluetoothServiceUUID[]; - acceptAllDevices?: boolean; -} - -interface BluetoothLEScanFilter { - services?: BluetoothServiceUUID[]; - name?: string; - namePrefix?: string; - manufacturerData?: BluetoothManufacturerDataFilter[]; - serviceData?: BluetoothServiceDataFilter[]; -} - -interface BluetoothManufacturerDataFilter { - companyIdentifier: number; - dataPrefix?: BufferSource; - mask?: BufferSource; -} - -interface BluetoothServiceDataFilter { - service: BluetoothServiceUUID; - dataPrefix?: BufferSource; - mask?: BufferSource; -} - -type BluetoothServiceUUID = number | string; -type BluetoothCharacteristicUUID = number | string; -type BluetoothDescriptorUUID = number | string; - -interface Bluetooth extends EventTarget { - getAvailability(): Promise; - requestDevice(options?: RequestDeviceOptions): Promise; - getDevices(): Promise; - addEventListener( - type: 'availabilitychanged', - listener: EventListenerOrEventListenerObject, - options?: boolean | AddEventListenerOptions - ): void; -} - -interface Navigator { - bluetooth: Bluetooth; -} diff --git a/tsconfig.app.json b/tsconfig.app.json index a9b5a59..59fc04f 100644 --- a/tsconfig.app.json +++ b/tsconfig.app.json @@ -5,7 +5,7 @@ "useDefineForClassFields": true, "lib": ["ES2022", "DOM", "DOM.Iterable"], "module": "ESNext", - "types": ["vite/client"], + "types": ["vite/client", "web-bluetooth"], "skipLibCheck": true, /* Bundler mode */