@neurosity/sdk
Version:
Neurosity SDK
56 lines (55 loc) • 2.63 kB
TypeScript
/// <reference types="web-bluetooth" />
import { Observable, BehaviorSubject, ReplaySubject } from "rxjs";
import { BluetoothTransport } from "../BluetoothTransport";
import { TextCodec } from "../utils/textCodec";
import { ActionOptions, SubscribeOptions } from "../types";
import { TRANSPORT_TYPE, BLUETOOTH_CONNECTION } from "../types";
import { DeviceInfo } from "../../../types/deviceInfo";
declare type Options = {
autoConnect?: boolean;
};
export declare class WebBluetoothTransport implements BluetoothTransport {
type: TRANSPORT_TYPE;
textCodec: TextCodec;
options: Options;
device: BluetoothDevice;
server: BluetoothRemoteGATTServer;
service: BluetoothRemoteGATTService;
characteristicsByName: {
[name: string]: BluetoothRemoteGATTCharacteristic;
};
connection$: BehaviorSubject<BLUETOOTH_CONNECTION>;
pendingActions$: BehaviorSubject<any[]>;
logs$: ReplaySubject<string>;
onDisconnected$: Observable<void>;
connectionStream$: Observable<BLUETOOTH_CONNECTION>;
_isAutoConnectEnabled$: ReplaySubject<boolean>;
constructor(options?: Options);
_getPairedDevices(): Promise<BluetoothDevice[]>;
_autoConnect(selectedDevice$: Observable<DeviceInfo>): Observable<void>;
enableAutoConnect(autoConnect: boolean): void;
addLog(log: string): void;
isConnected(): boolean;
connection(): Observable<BLUETOOTH_CONNECTION>;
connect(deviceNickname?: string): Promise<void>;
requestDevice(deviceNickname?: string): Promise<BluetoothDevice>;
getServerServiceAndCharacteristics(device: BluetoothDevice): Promise<never>;
_onDisconnected(): Observable<any>;
disconnect(): Promise<void>;
/**
*
* Bluetooth GATT attributes, services, characteristics, etc. are invalidated
* when a device disconnects. This means your code should always retrieve
* (through getPrimaryService(s), getCharacteristic(s), etc.) these attributes
* after reconnecting.
*/
getCharacteristicByName(characteristicName: string): Promise<BluetoothRemoteGATTCharacteristic>;
subscribeToCharacteristic({ characteristicName, manageNotifications, skipJSONDecoding }: SubscribeOptions): Observable<any>;
readCharacteristic(characteristicName: string, parse?: boolean): Promise<any>;
writeCharacteristic(characteristicName: string, data: string): Promise<void>;
_addPendingAction(actionId: number): void;
_removePendingAction(actionId: number): void;
_autoToggleActionNotifications(): Observable<any>;
dispatchAction({ characteristicName, action }: ActionOptions): Promise<any>;
}
export {};