lavva.webbluetooth
Version:
Library implementing WebBluetooth custom functionality if underlying platform does support it
111 lines (110 loc) • 4.29 kB
TypeScript
import { NativeTypedEvent } from "./ExtendedWebBluetooth";
export declare class LavvaBluetooth {
private receiveBuffer;
private _maxCharacteristicValueLength;
private serviceUuid;
private characteristicUuid;
private receiveSeparator;
private sendSeparator;
private static selectedDevice;
private static gattServer;
private static gattService;
private static gattOperationQueue;
private static gattOperationSequence;
private static gattQueuedOperations;
private static requestResponseQueue;
private static requestResponseSequence;
private static queuedRequestResponses;
private static readonly GATT_OPERATION_SETTLE_DELAY_MS;
private static readonly GATT_BUSY_RETRY_DELAY_MS;
private static readonly GATT_BUSY_MAX_ATTEMPTS;
private static readonly METHOD_RESPONSE_MAP;
private characteristic;
private notificationsStarted;
private pendingResponses;
OnGattServiceDisconnectedEvent: NativeTypedEvent<BluetoothRemoteGATTServer | undefined>;
OnCharacteristicValueChangedEvent: NativeTypedEvent<string>;
OnConnectedEvent: NativeTypedEvent<BluetoothDevice>;
OnDisconnectedEvent: NativeTypedEvent<BluetoothDevice>;
private filter;
private static instances;
private static getTimestamp;
private static logInfo;
private static logWarn;
private static logError;
private static globalGattDisconnectedHandlerInstalled;
private static globalGattDisconnectedHandler;
constructor();
/** Call when instance is no longer needed (prevents registry leak). */
Dispose(): void;
private getTimestamp;
private logInfo;
private logWarn;
private logError;
private WHITESPACE_NAMES;
private visualizeTrailingWhitespace;
private logTrailingWhitespaceDetail;
private updateMaxPayload;
SetFilter(filters: BluetoothLEScanFilter[]): void;
GetConnectedDevice(): BluetoothDevice | null;
private expectedUuidFrom16Bit;
private isExpectedCharacteristic;
/**
* Connects to device + primary service (shared statically).
* DOES NOT automatically connect this instance to a different characteristic than its default (0xffe1),
* but will connect this instance to its current characteristicUuid.
*/
RequestDeviceAndConnectAsync(): Promise<BluetoothDevice | DeviceConnectionError>;
/**
* Connects THIS instance to a given characteristic (notifications + listener).
* Use separate instance per characteristic.
*/
ConnectToGattCharacteristicAsync(characteristicUuid: number): Promise<BluetoothRemoteGATTCharacteristic | DeviceConnectionError>;
private AttachToCharacteristicInternal;
private handleCharacteristicValueChanged;
/**
* Disconnects the shared device connection AND cleans up ALL instance listeners/notifications.
* You can call it from any instance.
*/
DisconnectDeviceAsync(device: BluetoothDevice): Promise<DeviceDisconnectionStatus>;
private detachCharacteristic;
SendDataAsync(data: string): Promise<WriteDataStatus>;
SendAndWaitForResponseAsync<T>(data: any, timeout?: number): Promise<T>;
private WriteValueAsync;
private SplitByLength;
private runExclusiveGattOperation;
private runExclusiveRequestResponse;
private sendPayloadAsync;
private serializeOutgoingData;
private normalizeFrame;
private dispatchPendingResponse;
private rejectPendingResponses;
private createResponseMatcher;
private getExpectedResponseMethods;
private tryParseJsonFrame;
private getCorrelationId;
private getStringField;
private isGattOperationInProgressError;
}
export declare enum DeviceConnectionError {
NoDeviceHasBeenSelected = 0,
AnotherDeviceIsAlreadyConnected = 1,
FailedToConnectToGattServer = 2,
FailedToGetPrimaryService = 3,
FailedToDiscoverService = 4,
FailedToGetCharacteristic = 5,
FailedToStartNotifications = 6
}
export declare enum DeviceDisconnectionStatus {
NoDeviceConnected = 0,
FailedToForgetDevice = 1,
FailedToDisconnect = 2,
FailedToStopNotifications = 3,
DisconnectedSuccesfully = 4
}
export declare enum WriteDataStatus {
Sucess = 0,
DataIsEmpty = 1,
NoDeviceConnected = 2,
FailedToWriteValue = 3
}