@voltras/node-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +272 -0
- package/dist/cjs/bluetooth/adapters/base.js +116 -0
- package/dist/cjs/bluetooth/adapters/base.js.map +1 -0
- package/dist/cjs/bluetooth/adapters/index.js +58 -0
- package/dist/cjs/bluetooth/adapters/index.js.map +1 -0
- package/dist/cjs/bluetooth/adapters/native.js +473 -0
- package/dist/cjs/bluetooth/adapters/native.js.map +1 -0
- package/dist/cjs/bluetooth/adapters/node.js +228 -0
- package/dist/cjs/bluetooth/adapters/node.js.map +1 -0
- package/dist/cjs/bluetooth/adapters/types.js +11 -0
- package/dist/cjs/bluetooth/adapters/types.js.map +1 -0
- package/dist/cjs/bluetooth/adapters/web-bluetooth-base.js +187 -0
- package/dist/cjs/bluetooth/adapters/web-bluetooth-base.js.map +1 -0
- package/dist/cjs/bluetooth/adapters/web.js +112 -0
- package/dist/cjs/bluetooth/adapters/web.js.map +1 -0
- package/dist/cjs/bluetooth/controllers/scanner-controller.js +145 -0
- package/dist/cjs/bluetooth/controllers/scanner-controller.js.map +1 -0
- package/dist/cjs/bluetooth/index.js +27 -0
- package/dist/cjs/bluetooth/index.js.map +1 -0
- package/dist/cjs/bluetooth/models/connection.js +68 -0
- package/dist/cjs/bluetooth/models/connection.js.map +1 -0
- package/dist/cjs/bluetooth/models/device.js +26 -0
- package/dist/cjs/bluetooth/models/device.js.map +1 -0
- package/dist/cjs/bluetooth/models/environment.js +106 -0
- package/dist/cjs/bluetooth/models/environment.js.map +1 -0
- package/dist/cjs/errors.js +167 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/index.js +116 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/react/hooks.js +262 -0
- package/dist/cjs/react/hooks.js.map +1 -0
- package/dist/cjs/react/index.js +18 -0
- package/dist/cjs/react/index.js.map +1 -0
- package/dist/cjs/sdk/index.js +14 -0
- package/dist/cjs/sdk/index.js.map +1 -0
- package/dist/cjs/sdk/types.js +8 -0
- package/dist/cjs/sdk/types.js.map +1 -0
- package/dist/cjs/sdk/voltra-client.js +632 -0
- package/dist/cjs/sdk/voltra-client.js.map +1 -0
- package/dist/cjs/sdk/voltra-manager.js +419 -0
- package/dist/cjs/sdk/voltra-manager.js.map +1 -0
- package/dist/cjs/shared/index.js +12 -0
- package/dist/cjs/shared/index.js.map +1 -0
- package/dist/cjs/shared/utils.js +51 -0
- package/dist/cjs/shared/utils.js.map +1 -0
- package/dist/cjs/voltra/index.js +56 -0
- package/dist/cjs/voltra/index.js.map +1 -0
- package/dist/cjs/voltra/models/connection.js +68 -0
- package/dist/cjs/voltra/models/connection.js.map +1 -0
- package/dist/cjs/voltra/models/device-filter.js +28 -0
- package/dist/cjs/voltra/models/device-filter.js.map +1 -0
- package/dist/cjs/voltra/models/device.js +152 -0
- package/dist/cjs/voltra/models/device.js.map +1 -0
- package/dist/cjs/voltra/models/telemetry/frame.js +46 -0
- package/dist/cjs/voltra/models/telemetry/frame.js.map +1 -0
- package/dist/cjs/voltra/models/telemetry/index.js +14 -0
- package/dist/cjs/voltra/models/telemetry/index.js.map +1 -0
- package/dist/cjs/voltra/protocol/commands.js +230 -0
- package/dist/cjs/voltra/protocol/commands.js.map +1 -0
- package/dist/cjs/voltra/protocol/constants.js +136 -0
- package/dist/cjs/voltra/protocol/constants.js.map +1 -0
- package/dist/cjs/voltra/protocol/data/chains.json +830 -0
- package/dist/cjs/voltra/protocol/data/eccentric.json +1598 -0
- package/dist/cjs/voltra/protocol/data/protocol.json +54 -0
- package/dist/cjs/voltra/protocol/data/weights.json +62 -0
- package/dist/cjs/voltra/protocol/index.js +25 -0
- package/dist/cjs/voltra/protocol/index.js.map +1 -0
- package/dist/cjs/voltra/protocol/telemetry-decoder.js +146 -0
- package/dist/cjs/voltra/protocol/telemetry-decoder.js.map +1 -0
- package/dist/esm/bluetooth/adapters/base.js +112 -0
- package/dist/esm/bluetooth/adapters/base.js.map +1 -0
- package/dist/esm/bluetooth/adapters/index.js +51 -0
- package/dist/esm/bluetooth/adapters/index.js.map +1 -0
- package/dist/esm/bluetooth/adapters/native.js +469 -0
- package/dist/esm/bluetooth/adapters/native.js.map +1 -0
- package/dist/esm/bluetooth/adapters/node.js +191 -0
- package/dist/esm/bluetooth/adapters/node.js.map +1 -0
- package/dist/esm/bluetooth/adapters/types.js +10 -0
- package/dist/esm/bluetooth/adapters/types.js.map +1 -0
- package/dist/esm/bluetooth/adapters/web-bluetooth-base.js +183 -0
- package/dist/esm/bluetooth/adapters/web-bluetooth-base.js.map +1 -0
- package/dist/esm/bluetooth/adapters/web.js +108 -0
- package/dist/esm/bluetooth/adapters/web.js.map +1 -0
- package/dist/esm/bluetooth/controllers/scanner-controller.js +141 -0
- package/dist/esm/bluetooth/controllers/scanner-controller.js.map +1 -0
- package/dist/esm/bluetooth/index.js +17 -0
- package/dist/esm/bluetooth/index.js.map +1 -0
- package/dist/esm/bluetooth/models/connection.js +63 -0
- package/dist/esm/bluetooth/models/connection.js.map +1 -0
- package/dist/esm/bluetooth/models/device.js +22 -0
- package/dist/esm/bluetooth/models/device.js.map +1 -0
- package/dist/esm/bluetooth/models/environment.js +101 -0
- package/dist/esm/bluetooth/models/environment.js.map +1 -0
- package/dist/esm/errors.js +155 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.js +72 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/react/hooks.js +257 -0
- package/dist/esm/react/hooks.js.map +1 -0
- package/dist/esm/react/index.js +12 -0
- package/dist/esm/react/index.js.map +1 -0
- package/dist/esm/sdk/index.js +9 -0
- package/dist/esm/sdk/index.js.map +1 -0
- package/dist/esm/sdk/types.js +7 -0
- package/dist/esm/sdk/types.js.map +1 -0
- package/dist/esm/sdk/voltra-client.js +628 -0
- package/dist/esm/sdk/voltra-client.js.map +1 -0
- package/dist/esm/sdk/voltra-manager.js +415 -0
- package/dist/esm/sdk/voltra-manager.js.map +1 -0
- package/dist/esm/shared/index.js +5 -0
- package/dist/esm/shared/index.js.map +1 -0
- package/dist/esm/shared/utils.js +45 -0
- package/dist/esm/shared/utils.js.map +1 -0
- package/dist/esm/voltra/index.js +26 -0
- package/dist/esm/voltra/index.js.map +1 -0
- package/dist/esm/voltra/models/connection.js +63 -0
- package/dist/esm/voltra/models/connection.js.map +1 -0
- package/dist/esm/voltra/models/device-filter.js +23 -0
- package/dist/esm/voltra/models/device-filter.js.map +1 -0
- package/dist/esm/voltra/models/device.js +148 -0
- package/dist/esm/voltra/models/device.js.map +1 -0
- package/dist/esm/voltra/models/telemetry/frame.js +40 -0
- package/dist/esm/voltra/models/telemetry/frame.js.map +1 -0
- package/dist/esm/voltra/models/telemetry/index.js +7 -0
- package/dist/esm/voltra/models/telemetry/index.js.map +1 -0
- package/dist/esm/voltra/protocol/commands.js +224 -0
- package/dist/esm/voltra/protocol/commands.js.map +1 -0
- package/dist/esm/voltra/protocol/constants.js +130 -0
- package/dist/esm/voltra/protocol/constants.js.map +1 -0
- package/dist/esm/voltra/protocol/data/chains.json +830 -0
- package/dist/esm/voltra/protocol/data/eccentric.json +1598 -0
- package/dist/esm/voltra/protocol/data/protocol.json +54 -0
- package/dist/esm/voltra/protocol/data/weights.json +62 -0
- package/dist/esm/voltra/protocol/index.js +9 -0
- package/dist/esm/voltra/protocol/index.js.map +1 -0
- package/dist/esm/voltra/protocol/telemetry-decoder.js +140 -0
- package/dist/esm/voltra/protocol/telemetry-decoder.js.map +1 -0
- package/dist/types/bluetooth/adapters/base.d.ts +85 -0
- package/dist/types/bluetooth/adapters/base.d.ts.map +1 -0
- package/dist/types/bluetooth/adapters/index.d.ts +35 -0
- package/dist/types/bluetooth/adapters/index.d.ts.map +1 -0
- package/dist/types/bluetooth/adapters/native.d.ts +109 -0
- package/dist/types/bluetooth/adapters/native.d.ts.map +1 -0
- package/dist/types/bluetooth/adapters/node.d.ts +91 -0
- package/dist/types/bluetooth/adapters/node.d.ts.map +1 -0
- package/dist/types/bluetooth/adapters/types.d.ts +102 -0
- package/dist/types/bluetooth/adapters/types.d.ts.map +1 -0
- package/dist/types/bluetooth/adapters/web-bluetooth-base.d.ts +90 -0
- package/dist/types/bluetooth/adapters/web-bluetooth-base.d.ts.map +1 -0
- package/dist/types/bluetooth/adapters/web.d.ts +57 -0
- package/dist/types/bluetooth/adapters/web.d.ts.map +1 -0
- package/dist/types/bluetooth/controllers/scanner-controller.d.ts +93 -0
- package/dist/types/bluetooth/controllers/scanner-controller.d.ts.map +1 -0
- package/dist/types/bluetooth/index.d.ts +14 -0
- package/dist/types/bluetooth/index.d.ts.map +1 -0
- package/dist/types/bluetooth/models/connection.d.ts +37 -0
- package/dist/types/bluetooth/models/connection.d.ts.map +1 -0
- package/dist/types/bluetooth/models/device.d.ts +25 -0
- package/dist/types/bluetooth/models/device.d.ts.map +1 -0
- package/dist/types/bluetooth/models/environment.d.ts +45 -0
- package/dist/types/bluetooth/models/environment.d.ts.map +1 -0
- package/dist/types/errors.d.ts +113 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/index.d.ts +55 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/react/hooks.d.ts +130 -0
- package/dist/types/react/hooks.d.ts.map +1 -0
- package/dist/types/react/index.d.ts +12 -0
- package/dist/types/react/index.d.ts.map +1 -0
- package/dist/types/sdk/index.d.ts +11 -0
- package/dist/types/sdk/index.d.ts.map +1 -0
- package/dist/types/sdk/types.d.ts +104 -0
- package/dist/types/sdk/types.d.ts.map +1 -0
- package/dist/types/sdk/voltra-client.d.ts +221 -0
- package/dist/types/sdk/voltra-client.d.ts.map +1 -0
- package/dist/types/sdk/voltra-manager.d.ts +226 -0
- package/dist/types/sdk/voltra-manager.d.ts.map +1 -0
- package/dist/types/shared/index.d.ts +5 -0
- package/dist/types/shared/index.d.ts.map +1 -0
- package/dist/types/shared/utils.d.ts +25 -0
- package/dist/types/shared/utils.d.ts.map +1 -0
- package/dist/types/voltra/index.d.ts +13 -0
- package/dist/types/voltra/index.d.ts.map +1 -0
- package/dist/types/voltra/models/connection.d.ts +37 -0
- package/dist/types/voltra/models/connection.d.ts.map +1 -0
- package/dist/types/voltra/models/device-filter.d.ts +19 -0
- package/dist/types/voltra/models/device-filter.d.ts.map +1 -0
- package/dist/types/voltra/models/device.d.ts +105 -0
- package/dist/types/voltra/models/device.d.ts.map +1 -0
- package/dist/types/voltra/models/telemetry/frame.d.ts +41 -0
- package/dist/types/voltra/models/telemetry/frame.d.ts.map +1 -0
- package/dist/types/voltra/models/telemetry/index.d.ts +8 -0
- package/dist/types/voltra/models/telemetry/index.d.ts.map +1 -0
- package/dist/types/voltra/protocol/commands.d.ts +99 -0
- package/dist/types/voltra/protocol/commands.d.ts.map +1 -0
- package/dist/types/voltra/protocol/constants.d.ts +103 -0
- package/dist/types/voltra/protocol/constants.d.ts.map +1 -0
- package/dist/types/voltra/protocol/index.d.ts +9 -0
- package/dist/types/voltra/protocol/index.d.ts.map +1 -0
- package/dist/types/voltra/protocol/telemetry-decoder.d.ts +45 -0
- package/dist/types/voltra/protocol/telemetry-decoder.d.ts.map +1 -0
- package/package.json +111 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BLE Abstraction Layer Types
|
|
3
|
+
*
|
|
4
|
+
* Defines interfaces for BLE operations implemented by platform-specific adapters:
|
|
5
|
+
* - Native (iOS/Android): react-native-ble-plx
|
|
6
|
+
* - Browser: Web Bluetooth API
|
|
7
|
+
* - Node.js: webbluetooth npm package
|
|
8
|
+
*/
|
|
9
|
+
import { type DiscoveredDevice } from '../models/device';
|
|
10
|
+
/**
|
|
11
|
+
* Device alias - uses the canonical DiscoveredDevice type from models.
|
|
12
|
+
*/
|
|
13
|
+
export type Device = DiscoveredDevice;
|
|
14
|
+
/**
|
|
15
|
+
* Connection state for the BLE adapter.
|
|
16
|
+
*/
|
|
17
|
+
export type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'disconnecting';
|
|
18
|
+
/**
|
|
19
|
+
* Callback for receiving BLE notifications.
|
|
20
|
+
*/
|
|
21
|
+
export type NotificationCallback = (data: Uint8Array) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Callback for connection state changes.
|
|
24
|
+
*/
|
|
25
|
+
export type ConnectionStateCallback = (state: ConnectionState) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Options for BLE connection.
|
|
28
|
+
*/
|
|
29
|
+
export interface ConnectOptions {
|
|
30
|
+
/**
|
|
31
|
+
* Data to write immediately after raw connection, before service discovery.
|
|
32
|
+
* Used for authentication that must happen within a tight time window.
|
|
33
|
+
*/
|
|
34
|
+
immediateWrite?: Uint8Array;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* BLE service configuration for adapters.
|
|
38
|
+
* Defines the UUIDs and device name prefix for BLE operations.
|
|
39
|
+
*/
|
|
40
|
+
export interface BLEServiceConfig {
|
|
41
|
+
/** Main service UUID */
|
|
42
|
+
serviceUUID: string;
|
|
43
|
+
/** Characteristic UUID for receiving notifications */
|
|
44
|
+
notifyCharUUID: string;
|
|
45
|
+
/** Characteristic UUID for writing commands */
|
|
46
|
+
writeCharUUID: string;
|
|
47
|
+
/** Optional device name prefix for filtering during scan */
|
|
48
|
+
deviceNamePrefix?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Abstract interface for BLE operations.
|
|
52
|
+
*
|
|
53
|
+
* Implemented by:
|
|
54
|
+
* - NativeBLEAdapter: Uses react-native-ble-plx (iOS/Android)
|
|
55
|
+
* - WebBLEAdapter: Uses Web Bluetooth API (browser)
|
|
56
|
+
* - NodeBLEAdapter: Uses webbluetooth package (Node.js)
|
|
57
|
+
* - ReplayBLEAdapter: Plays back recorded samples (testing/demo)
|
|
58
|
+
*/
|
|
59
|
+
export interface BLEAdapter {
|
|
60
|
+
/**
|
|
61
|
+
* Scan for devices.
|
|
62
|
+
* @param timeout Scan duration in seconds
|
|
63
|
+
* @returns List of discovered devices
|
|
64
|
+
*/
|
|
65
|
+
scan(timeout: number): Promise<Device[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Connect to a device.
|
|
68
|
+
* @param deviceId Device identifier from scan results
|
|
69
|
+
* @param options Optional connection options
|
|
70
|
+
*/
|
|
71
|
+
connect(deviceId: string, options?: ConnectOptions): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Disconnect from the current device.
|
|
74
|
+
*/
|
|
75
|
+
disconnect(): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Write data to the device's write characteristic.
|
|
78
|
+
* @param data Bytes to write
|
|
79
|
+
*/
|
|
80
|
+
write(data: Uint8Array): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Register a callback for notifications from the device.
|
|
83
|
+
* @param callback Function called with notification data
|
|
84
|
+
* @returns Unsubscribe function
|
|
85
|
+
*/
|
|
86
|
+
onNotification(callback: NotificationCallback): () => void;
|
|
87
|
+
/**
|
|
88
|
+
* Register a callback for connection state changes.
|
|
89
|
+
* @param callback Function called when state changes
|
|
90
|
+
* @returns Unsubscribe function
|
|
91
|
+
*/
|
|
92
|
+
onConnectionStateChange(callback: ConnectionStateCallback): () => void;
|
|
93
|
+
/**
|
|
94
|
+
* Get current connection state.
|
|
95
|
+
*/
|
|
96
|
+
getConnectionState(): ConnectionState;
|
|
97
|
+
/**
|
|
98
|
+
* Check if currently connected to a device.
|
|
99
|
+
*/
|
|
100
|
+
isConnected(): boolean;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/bluetooth/adapters/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG,gBAAgB,CAAC;AAEtC;;GAEG;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AC;CACxB"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebBluetoothBase
|
|
3
|
+
*
|
|
4
|
+
* Abstract base class for W3C Web Bluetooth API adapters.
|
|
5
|
+
* Provides shared GATT operations for both browser and Node.js environments.
|
|
6
|
+
*
|
|
7
|
+
* Subclasses:
|
|
8
|
+
* - WebBLEAdapter: Browser using navigator.bluetooth
|
|
9
|
+
* - NodeBLEAdapter: Node.js using webbluetooth npm package
|
|
10
|
+
*/
|
|
11
|
+
import { BaseBLEAdapter } from './base';
|
|
12
|
+
import type { Device, ConnectOptions, BLEServiceConfig } from './types';
|
|
13
|
+
/**
|
|
14
|
+
* Configuration for Web Bluetooth adapters.
|
|
15
|
+
*/
|
|
16
|
+
export interface WebBluetoothConfig {
|
|
17
|
+
/** BLE service configuration (UUIDs, device name prefix) */
|
|
18
|
+
ble: BLEServiceConfig;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Abstract base class for Web Bluetooth adapters.
|
|
22
|
+
*
|
|
23
|
+
* Implements shared GATT operations:
|
|
24
|
+
* - Service/characteristic discovery
|
|
25
|
+
* - Write operations
|
|
26
|
+
* - Notification subscription
|
|
27
|
+
* - Disconnect cleanup
|
|
28
|
+
*
|
|
29
|
+
* Subclasses implement platform-specific device selection (scan/connect).
|
|
30
|
+
*/
|
|
31
|
+
export declare abstract class WebBluetoothBase extends BaseBLEAdapter {
|
|
32
|
+
/** Connected Bluetooth device */
|
|
33
|
+
protected device: BluetoothDevice | null;
|
|
34
|
+
/** GATT server connection */
|
|
35
|
+
protected server: BluetoothRemoteGATTServer | null;
|
|
36
|
+
/** Write characteristic */
|
|
37
|
+
protected writeChar: BluetoothRemoteGATTCharacteristic | null;
|
|
38
|
+
/** Notify characteristic */
|
|
39
|
+
protected notifyChar: BluetoothRemoteGATTCharacteristic | null;
|
|
40
|
+
/** BLE service configuration */
|
|
41
|
+
protected config: BLEServiceConfig;
|
|
42
|
+
/** Bound notification handler for cleanup */
|
|
43
|
+
private boundNotificationHandler;
|
|
44
|
+
constructor(config: WebBluetoothConfig);
|
|
45
|
+
/**
|
|
46
|
+
* Scan for devices.
|
|
47
|
+
* Browser: Shows native device picker
|
|
48
|
+
* Node.js: Programmatic device selection
|
|
49
|
+
*/
|
|
50
|
+
abstract scan(timeout: number): Promise<Device[]>;
|
|
51
|
+
/**
|
|
52
|
+
* Connect to a device by ID.
|
|
53
|
+
* Subclasses may need to handle device lookup differently.
|
|
54
|
+
*/
|
|
55
|
+
abstract connect(deviceId: string, options?: ConnectOptions): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Connect to a Bluetooth device's GATT server and set up characteristics.
|
|
58
|
+
* Called by subclasses after device selection.
|
|
59
|
+
*/
|
|
60
|
+
protected connectToDevice(device: BluetoothDevice): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Discover service and characteristics, set up notifications.
|
|
63
|
+
*/
|
|
64
|
+
protected setupCharacteristics(): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Handle incoming notification data.
|
|
67
|
+
*/
|
|
68
|
+
protected handleNotification(event: Event): void;
|
|
69
|
+
/**
|
|
70
|
+
* Handle device disconnection.
|
|
71
|
+
*/
|
|
72
|
+
protected handleDisconnect(): void;
|
|
73
|
+
/**
|
|
74
|
+
* Clean up resources.
|
|
75
|
+
*/
|
|
76
|
+
protected cleanup(): void;
|
|
77
|
+
/**
|
|
78
|
+
* Disconnect from the device.
|
|
79
|
+
*/
|
|
80
|
+
disconnect(): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Write data to the device.
|
|
83
|
+
*/
|
|
84
|
+
write(data: Uint8Array): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Get info about the currently connected device.
|
|
87
|
+
*/
|
|
88
|
+
getConnectedDevice(): Device | null;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=web-bluetooth-base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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B,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAQhD;;OAEG;IACH,SAAS,CAAC,gBAAgB,IAAI,IAAI;IAKlC;;OAEG;IACH,SAAS,CAAC,OAAO,IAAI,IAAI;IAmCzB;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAWjC;;OAEG;IACG,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAc5C;;OAEG;IACH,kBAAkB,IAAI,MAAM,GAAG,IAAI;CAQpC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebBLEAdapter
|
|
3
|
+
*
|
|
4
|
+
* BLE adapter for web browsers using the native Web Bluetooth API.
|
|
5
|
+
* Uses the browser's built-in device picker for device selection.
|
|
6
|
+
*
|
|
7
|
+
* Requirements:
|
|
8
|
+
* - Chrome, Edge, or Opera browser (Safari/Firefox don't support Web Bluetooth)
|
|
9
|
+
* - HTTPS or localhost
|
|
10
|
+
* - User gesture required to trigger device picker
|
|
11
|
+
*/
|
|
12
|
+
import { WebBluetoothBase, type WebBluetoothConfig } from './web-bluetooth-base';
|
|
13
|
+
import type { Device, ConnectOptions } from './types';
|
|
14
|
+
/**
|
|
15
|
+
* BLE adapter using the browser's native Web Bluetooth API.
|
|
16
|
+
*
|
|
17
|
+
* Device selection flow:
|
|
18
|
+
* 1. Call scan() - triggers browser's device picker
|
|
19
|
+
* 2. User selects device from browser UI
|
|
20
|
+
* 3. scan() returns with the selected device
|
|
21
|
+
* 4. Call connect() to establish GATT connection
|
|
22
|
+
*/
|
|
23
|
+
export declare class WebBLEAdapter extends WebBluetoothBase {
|
|
24
|
+
/** Device selected from browser picker, stored for connect() */
|
|
25
|
+
private selectedDevice;
|
|
26
|
+
constructor(config: WebBluetoothConfig);
|
|
27
|
+
/**
|
|
28
|
+
* Scan for devices using the browser's device picker.
|
|
29
|
+
*
|
|
30
|
+
* Note: This triggers the browser's native Bluetooth device picker UI.
|
|
31
|
+
* The user must select a device from the picker. Returns when user
|
|
32
|
+
* selects a device or cancels.
|
|
33
|
+
*
|
|
34
|
+
* @param _timeout Ignored - browser controls the picker timeout
|
|
35
|
+
* @returns Array with single selected device, or empty if cancelled
|
|
36
|
+
*/
|
|
37
|
+
scan(_timeout: number): Promise<Device[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Connect to the selected device.
|
|
40
|
+
*
|
|
41
|
+
* Note: In Web Bluetooth, the device is already "selected" during scan().
|
|
42
|
+
* This method establishes the GATT connection.
|
|
43
|
+
*
|
|
44
|
+
* @param deviceId Device ID (should match the selected device)
|
|
45
|
+
* @param options Connection options
|
|
46
|
+
*/
|
|
47
|
+
connect(deviceId: string, options?: ConnectOptions): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Override disconnect to also clear selected device.
|
|
50
|
+
*/
|
|
51
|
+
disconnect(): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Check if Web Bluetooth is supported in this browser.
|
|
54
|
+
*/
|
|
55
|
+
static isSupported(): boolean;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../../../src/bluetooth/adapters/web.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,gBAAgB,EAAE,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEtD;;;;;;;;GAQG;AACH,qBAAa,aAAc,SAAQ,gBAAgB;IACjD,gEAAgE;IAChE,OAAO,CAAC,cAAc,CAAgC;gBAE1C,MAAM,EAAE,kBAAkB;IAItC;;;;;;;;;OASG;IACG,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAiC/C;;;;;;;;OAQG;IACG,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBxE;;OAEG;IACY,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAK1C;;OAEG;IACH,MAAM,CAAC,WAAW,IAAI,OAAO;CAG9B"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scanner Controller
|
|
3
|
+
*
|
|
4
|
+
* Manages BLE device scanning with auto-scan functionality.
|
|
5
|
+
* This is a generic controller that can be configured with a device filter.
|
|
6
|
+
*/
|
|
7
|
+
import type { BLEAdapter } from '../adapters';
|
|
8
|
+
import { type DiscoveredDevice } from '../models/device';
|
|
9
|
+
import type { BLEEnvironmentInfo } from '../models/environment';
|
|
10
|
+
/**
|
|
11
|
+
* Device filter function type.
|
|
12
|
+
* Used to filter discovered devices (e.g., by name prefix).
|
|
13
|
+
*/
|
|
14
|
+
export type DeviceFilter = (devices: DiscoveredDevice[]) => DiscoveredDevice[];
|
|
15
|
+
/**
|
|
16
|
+
* Scanner state snapshot.
|
|
17
|
+
*/
|
|
18
|
+
export interface ScannerState {
|
|
19
|
+
isScanning: boolean;
|
|
20
|
+
discoveredDevices: DiscoveredDevice[];
|
|
21
|
+
lastScanTime: number;
|
|
22
|
+
error: string | null;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Scanner event types.
|
|
26
|
+
*/
|
|
27
|
+
export type ScannerEvent = {
|
|
28
|
+
type: 'scanStarted';
|
|
29
|
+
} | {
|
|
30
|
+
type: 'scanCompleted';
|
|
31
|
+
devices: DiscoveredDevice[];
|
|
32
|
+
} | {
|
|
33
|
+
type: 'scanFailed';
|
|
34
|
+
error: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Scanner event listener.
|
|
38
|
+
*/
|
|
39
|
+
export type ScannerEventListener = (event: ScannerEvent) => void;
|
|
40
|
+
/**
|
|
41
|
+
* Scanner configuration.
|
|
42
|
+
*/
|
|
43
|
+
export interface ScannerConfig {
|
|
44
|
+
scanDurationMs: number;
|
|
45
|
+
scanIntervalMs: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Controller for BLE device scanning.
|
|
49
|
+
*/
|
|
50
|
+
export declare class ScannerController {
|
|
51
|
+
private adapter;
|
|
52
|
+
private _environment;
|
|
53
|
+
private config;
|
|
54
|
+
private deviceFilter?;
|
|
55
|
+
private _isScanning;
|
|
56
|
+
private _discoveredDevices;
|
|
57
|
+
private _lastScanTime;
|
|
58
|
+
private _error;
|
|
59
|
+
private _autoScanInterval;
|
|
60
|
+
private _listeners;
|
|
61
|
+
constructor(adapter: BLEAdapter, _environment: BLEEnvironmentInfo, config: ScannerConfig, deviceFilter?: DeviceFilter | undefined);
|
|
62
|
+
/**
|
|
63
|
+
* Get current scanner state.
|
|
64
|
+
*/
|
|
65
|
+
getState(): ScannerState;
|
|
66
|
+
/**
|
|
67
|
+
* Subscribe to scanner events.
|
|
68
|
+
*/
|
|
69
|
+
subscribe(listener: ScannerEventListener): () => void;
|
|
70
|
+
private emit;
|
|
71
|
+
/**
|
|
72
|
+
* Scan for devices.
|
|
73
|
+
*/
|
|
74
|
+
scan(): Promise<DiscoveredDevice[]>;
|
|
75
|
+
/**
|
|
76
|
+
* Start auto-scanning.
|
|
77
|
+
* Returns cleanup function.
|
|
78
|
+
*/
|
|
79
|
+
startAutoScan(isConnected: () => boolean): () => void;
|
|
80
|
+
/**
|
|
81
|
+
* Stop auto-scanning.
|
|
82
|
+
*/
|
|
83
|
+
stopAutoScan(): void;
|
|
84
|
+
/**
|
|
85
|
+
* Clear error state.
|
|
86
|
+
*/
|
|
87
|
+
clearError(): void;
|
|
88
|
+
/**
|
|
89
|
+
* Cleanup resources.
|
|
90
|
+
*/
|
|
91
|
+
dispose(): void;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=scanner-controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanner-controller.d.ts","sourceRoot":"","sources":["../../../../src/bluetooth/controllers/scanner-controller.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,CAAC;AAE/E;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,OAAO,CAAC;IACpB,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;IACtC,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GACvB;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,OAAO,EAAE,gBAAgB,EAAE,CAAA;CAAE,GACtD;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1C;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;AAEjE;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,qBAAa,iBAAiB;IAU1B,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,YAAY,CAAC;IAZvB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,kBAAkB,CAA0B;IACpD,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,MAAM,CAAuB;IAErC,OAAO,CAAC,iBAAiB,CAA+C;IACxE,OAAO,CAAC,UAAU,CAAwC;gBAGhD,OAAO,EAAE,UAAU,EACnB,YAAY,EAAE,kBAAkB,EAChC,MAAM,EAAE,aAAa,EACrB,YAAY,CAAC,EAAE,YAAY,YAAA;IAGrC;;OAEG;IACH,QAAQ,IAAI,YAAY;IASxB;;OAEG;IACH,SAAS,CAAC,QAAQ,EAAE,oBAAoB,GAAG,MAAM,IAAI;IAKrD,OAAO,CAAC,IAAI;IAIZ;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAwDzC;;;OAGG;IACH,aAAa,CAAC,WAAW,EAAE,MAAM,OAAO,GAAG,MAAM,IAAI;IAqBrD;;OAEG;IACH,YAAY,IAAI,IAAI;IAOpB;;OAEG;IACH,UAAU,IAAI,IAAI;IAIlB;;OAEG;IACH,OAAO,IAAI,IAAI;CAIhB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bluetooth Domain
|
|
3
|
+
*
|
|
4
|
+
* Generic BLE connection management, device scanning, and environment detection.
|
|
5
|
+
* This domain provides reusable BLE infrastructure that can be configured
|
|
6
|
+
* for any BLE device.
|
|
7
|
+
*/
|
|
8
|
+
export type { DiscoveredDevice } from './models/device';
|
|
9
|
+
export { getDeviceDisplayName, sortBySignalStrength } from './models/device';
|
|
10
|
+
export type { BLEConnectionState } from './models/connection';
|
|
11
|
+
export type { BLEEnvironment, BLEEnvironmentInfo } from './models/environment';
|
|
12
|
+
export { detectBLEEnvironment, isBLEAvailable, createNativeEnvironmentInfo } from './models/environment';
|
|
13
|
+
export { type BLEAdapter, type BLEServiceConfig, type ConnectionState, type ConnectOptions, type NotificationCallback, type ConnectionStateCallback, WebBLEAdapter, NodeBLEAdapter, NativeBLEAdapter, createBLEAdapter, type CreateBLEAdapterConfig, } from './adapters';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/bluetooth/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAG7E,YAAY,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAG9D,YAAY,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AAGzG,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAE5B,aAAa,EACb,cAAc,EACd,gBAAgB,EAEhB,gBAAgB,EAChB,KAAK,sBAAsB,GAC5B,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bluetooth Connection Model
|
|
3
|
+
*
|
|
4
|
+
* Represents generic BLE connection state and transitions.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* BLE adapter connection states.
|
|
8
|
+
*/
|
|
9
|
+
export type BLEConnectionState = 'disconnected' | 'connecting' | 'connected' | 'disconnecting';
|
|
10
|
+
/**
|
|
11
|
+
* Check if a BLE state transition is valid.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isValidBLETransition(from: BLEConnectionState, to: BLEConnectionState): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Generic BLE connection state model with validation.
|
|
16
|
+
*/
|
|
17
|
+
export declare class BLEConnectionStateModel {
|
|
18
|
+
private _state;
|
|
19
|
+
get state(): BLEConnectionState;
|
|
20
|
+
get isConnected(): boolean;
|
|
21
|
+
get isConnecting(): boolean;
|
|
22
|
+
get isDisconnected(): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Transition to a new state.
|
|
25
|
+
* @throws Error if transition is invalid
|
|
26
|
+
*/
|
|
27
|
+
transitionTo(newState: BLEConnectionState): void;
|
|
28
|
+
/**
|
|
29
|
+
* Force set state (for reconnection scenarios).
|
|
30
|
+
*/
|
|
31
|
+
forceState(state: BLEConnectionState): void;
|
|
32
|
+
/**
|
|
33
|
+
* Reset to disconnected state.
|
|
34
|
+
*/
|
|
35
|
+
reset(): void;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../../../src/bluetooth/models/connection.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,cAAc,GAAG,YAAY,GAAG,WAAW,GAAG,eAAe,CAAC;AAY/F;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,kBAAkB,EAAE,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAE9F;AAED;;GAEG;AACH,qBAAa,uBAAuB;IAClC,OAAO,CAAC,MAAM,CAAsC;IAEpD,IAAI,KAAK,IAAI,kBAAkB,CAE9B;IAED,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED,IAAI,YAAY,IAAI,OAAO,CAE1B;IAED,IAAI,cAAc,IAAI,OAAO,CAE5B;IAED;;;OAGG;IACH,YAAY,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI;IAOhD;;OAEG;IACH,UAAU,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI;IAI3C;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bluetooth Device Model
|
|
3
|
+
*
|
|
4
|
+
* Represents a discovered BLE device from scanning.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* A discovered BLE device.
|
|
8
|
+
*/
|
|
9
|
+
export interface DiscoveredDevice {
|
|
10
|
+
/** Device identifier (address on Android, UUID on iOS) */
|
|
11
|
+
id: string;
|
|
12
|
+
/** Device name */
|
|
13
|
+
name: string | null;
|
|
14
|
+
/** Signal strength in dBm */
|
|
15
|
+
rssi: number | null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get display name for a device.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getDeviceDisplayName(device: DiscoveredDevice): string;
|
|
21
|
+
/**
|
|
22
|
+
* Sort devices by signal strength (strongest first).
|
|
23
|
+
*/
|
|
24
|
+
export declare function sortBySignalStrength(devices: DiscoveredDevice[]): DiscoveredDevice[];
|
|
25
|
+
//# sourceMappingURL=device.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../../../../src/bluetooth/models/device.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,0DAA0D;IAC1D,EAAE,EAAE,MAAM,CAAC;IACX,kBAAkB;IAClB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,6BAA6B;IAC7B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAErE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG,gBAAgB,EAAE,CAMpF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bluetooth Environment Model
|
|
3
|
+
*
|
|
4
|
+
* Detects the current environment and BLE capabilities.
|
|
5
|
+
* This is a simplified version for the SDK that doesn't depend on Expo.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* BLE environment types.
|
|
9
|
+
*/
|
|
10
|
+
export type BLEEnvironment = 'native' | 'simulator' | 'expo-go' | 'web' | 'node';
|
|
11
|
+
/**
|
|
12
|
+
* BLE environment information.
|
|
13
|
+
*/
|
|
14
|
+
export interface BLEEnvironmentInfo {
|
|
15
|
+
/** Current environment type */
|
|
16
|
+
environment: BLEEnvironment;
|
|
17
|
+
/** Whether BLE is supported in this environment */
|
|
18
|
+
bleSupported: boolean;
|
|
19
|
+
/** Warning message if BLE is not supported */
|
|
20
|
+
warningMessage: string | null;
|
|
21
|
+
/** Whether this is running on web */
|
|
22
|
+
isWeb: boolean;
|
|
23
|
+
/** Whether scanning requires a user gesture (click/tap) - true for Web Bluetooth */
|
|
24
|
+
requiresUserGesture: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Detect the current BLE environment.
|
|
28
|
+
*
|
|
29
|
+
* This is a simplified version that works without React Native/Expo dependencies.
|
|
30
|
+
* For full environment detection in React Native apps, use the app's environment detection.
|
|
31
|
+
*/
|
|
32
|
+
export declare function detectBLEEnvironment(): BLEEnvironmentInfo;
|
|
33
|
+
/**
|
|
34
|
+
* Check if BLE is available in the current environment.
|
|
35
|
+
*/
|
|
36
|
+
export declare function isBLEAvailable(env: BLEEnvironmentInfo): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Create environment info for native React Native apps.
|
|
39
|
+
* Call this from your app with the detected environment.
|
|
40
|
+
*/
|
|
41
|
+
export declare function createNativeEnvironmentInfo(options: {
|
|
42
|
+
isExpoGo?: boolean;
|
|
43
|
+
isSimulator?: boolean;
|
|
44
|
+
}): BLEEnvironmentInfo;
|
|
45
|
+
//# sourceMappingURL=environment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../../../src/bluetooth/models/environment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB,QAAQ,GACR,WAAW,GACX,SAAS,GACT,KAAK,GACL,MAAM,CAAC;AAEX;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,+BAA+B;IAC/B,WAAW,EAAE,cAAc,CAAC;IAC5B,mDAAmD;IACnD,YAAY,EAAE,OAAO,CAAC;IACtB,8CAA8C;IAC9C,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,qCAAqC;IACrC,KAAK,EAAE,OAAO,CAAC;IACf,oFAAoF;IACpF,mBAAmB,EAAE,OAAO,CAAC;CAC9B;AA+BD;;;;;GAKG;AACH,wBAAgB,oBAAoB,IAAI,kBAAkB,CA+BzD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAE/D;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE;IACnD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,GAAG,kBAAkB,CA4BrB"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom SDK Error Types
|
|
3
|
+
*
|
|
4
|
+
* Provides typed errors for better error handling and developer experience.
|
|
5
|
+
* All SDK errors extend VoltraSDKError for easy catch-all handling.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* try {
|
|
10
|
+
* await client.connect();
|
|
11
|
+
* } catch (error) {
|
|
12
|
+
* if (error instanceof ConnectionError) {
|
|
13
|
+
* console.log('Connection failed:', error.code);
|
|
14
|
+
* } else if (error instanceof AuthenticationError) {
|
|
15
|
+
* console.log('Auth failed - device may need reset');
|
|
16
|
+
* } else if (error instanceof VoltraSDKError) {
|
|
17
|
+
* console.log('SDK error:', error.message);
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Error codes for SDK errors.
|
|
24
|
+
* Use these for programmatic error handling.
|
|
25
|
+
*/
|
|
26
|
+
export declare const ErrorCode: {
|
|
27
|
+
readonly CONNECTION_FAILED: "CONNECTION_FAILED";
|
|
28
|
+
readonly CONNECTION_LOST: "CONNECTION_LOST";
|
|
29
|
+
readonly CONNECTION_TIMEOUT: "CONNECTION_TIMEOUT";
|
|
30
|
+
readonly NOT_CONNECTED: "NOT_CONNECTED";
|
|
31
|
+
readonly ALREADY_CONNECTED: "ALREADY_CONNECTED";
|
|
32
|
+
readonly AUTH_FAILED: "AUTH_FAILED";
|
|
33
|
+
readonly AUTH_TIMEOUT: "AUTH_TIMEOUT";
|
|
34
|
+
readonly AUTH_INVALID_RESPONSE: "AUTH_INVALID_RESPONSE";
|
|
35
|
+
readonly BLUETOOTH_UNAVAILABLE: "BLUETOOTH_UNAVAILABLE";
|
|
36
|
+
readonly BLUETOOTH_PERMISSION_DENIED: "BLUETOOTH_PERMISSION_DENIED";
|
|
37
|
+
readonly BLUETOOTH_ADAPTER_ERROR: "BLUETOOTH_ADAPTER_ERROR";
|
|
38
|
+
readonly DEVICE_NOT_FOUND: "DEVICE_NOT_FOUND";
|
|
39
|
+
readonly DEVICE_DISCONNECTED: "DEVICE_DISCONNECTED";
|
|
40
|
+
readonly COMMAND_FAILED: "COMMAND_FAILED";
|
|
41
|
+
readonly COMMAND_TIMEOUT: "COMMAND_TIMEOUT";
|
|
42
|
+
readonly INVALID_SETTING: "INVALID_SETTING";
|
|
43
|
+
readonly TELEMETRY_DECODE_ERROR: "TELEMETRY_DECODE_ERROR";
|
|
44
|
+
readonly TIMEOUT: "TIMEOUT";
|
|
45
|
+
readonly UNKNOWN: "UNKNOWN";
|
|
46
|
+
};
|
|
47
|
+
export type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
|
|
48
|
+
/**
|
|
49
|
+
* Base error class for all SDK errors.
|
|
50
|
+
* Provides a consistent error interface with error codes.
|
|
51
|
+
*/
|
|
52
|
+
export declare class VoltraSDKError extends Error {
|
|
53
|
+
readonly code: ErrorCode;
|
|
54
|
+
readonly cause?: Error;
|
|
55
|
+
constructor(message: string, code?: ErrorCode, cause?: Error);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Thrown when a BLE connection fails or is lost.
|
|
59
|
+
*/
|
|
60
|
+
export declare class ConnectionError extends VoltraSDKError {
|
|
61
|
+
constructor(message: string, code?: ErrorCode, cause?: Error);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Thrown when Voltra device authentication fails.
|
|
65
|
+
* This typically happens during the initial connection handshake.
|
|
66
|
+
*/
|
|
67
|
+
export declare class AuthenticationError extends VoltraSDKError {
|
|
68
|
+
constructor(message: string, code?: ErrorCode, cause?: Error);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Thrown when an operation times out.
|
|
72
|
+
*/
|
|
73
|
+
export declare class TimeoutError extends VoltraSDKError {
|
|
74
|
+
readonly timeoutMs: number;
|
|
75
|
+
constructor(message: string, timeoutMs: number, cause?: Error);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Thrown when an operation requires a connection but the device is not connected.
|
|
79
|
+
*/
|
|
80
|
+
export declare class NotConnectedError extends VoltraSDKError {
|
|
81
|
+
constructor(message?: string);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Thrown when an invalid setting value is provided.
|
|
85
|
+
* For example, setting weight to a value not supported by the device.
|
|
86
|
+
*/
|
|
87
|
+
export declare class InvalidSettingError extends VoltraSDKError {
|
|
88
|
+
readonly setting: string;
|
|
89
|
+
readonly value: unknown;
|
|
90
|
+
readonly validValues?: readonly unknown[];
|
|
91
|
+
constructor(setting: string, value: unknown, validValues?: readonly unknown[], message?: string);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Thrown when Bluetooth is not available on the current platform.
|
|
95
|
+
*/
|
|
96
|
+
export declare class BluetoothUnavailableError extends VoltraSDKError {
|
|
97
|
+
readonly reason?: string;
|
|
98
|
+
constructor(reason?: string);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Thrown when a command fails to execute on the device.
|
|
102
|
+
*/
|
|
103
|
+
export declare class CommandError extends VoltraSDKError {
|
|
104
|
+
readonly command?: string;
|
|
105
|
+
constructor(message: string, command?: string, cause?: Error);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Thrown when telemetry data cannot be decoded.
|
|
109
|
+
*/
|
|
110
|
+
export declare class TelemetryError extends VoltraSDKError {
|
|
111
|
+
constructor(message: string, cause?: Error);
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;GAGG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;CAiCZ,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,OAAO,SAAS,CAAC,CAAC;AAEnE;;;GAGG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC,SAAgB,IAAI,EAAE,SAAS,CAAC;IAChC,SAAgB,KAAK,CAAC,EAAE,KAAK,CAAC;gBAElB,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,SAA6B,EAAE,KAAK,CAAC,EAAE,KAAK;CAWhF;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,cAAc;gBAE/C,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,SAAuC,EAC7C,KAAK,CAAC,EAAE,KAAK;CAKhB;AAED;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,cAAc;gBACzC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,SAAiC,EAAE,KAAK,CAAC,EAAE,KAAK;CAIpF;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,c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