UNPKG

@iotize/tap

Version:

IoTize Device client for Javascript

77 lines (76 loc) 2.41 kB
import { Observable } from 'rxjs'; import { ConnectionState } from './definitions'; export interface ConnectionStateChangeEvent { newState: ConnectionState; oldState: ConnectionState; } /** * Communication protocol options */ export interface ComProtocolOptions { connect: ComProtocolConnectOptions; disconnect: ComProtocolDisconnectOptions; send: ComProtocolSendOptions; } export interface ComProtocolConnectOptions { timeout: number; } export interface ComProtocolDisconnectOptions { timeout: number; } export interface ComProtocolSendOptions { timeout: number; } export interface ComProtocol { /** * @return connection state (connected or not) */ getConnectionState(): ConnectionState; /** * @return true if connection to device has been made */ isConnected(): boolean; connect(options?: ComProtocolConnectOptions): Observable<any>; disconnect(options?: ComProtocolConnectOptions): Observable<any>; /** * Send data and wait for response * @param data * @param options */ send(data: Uint8Array, options?: ComProtocolSendOptions): Observable<Uint8Array>; write(data: Uint8Array): Promise<any>; read(): Promise<Uint8Array>; /** * Message stream. Any message received by the protocol will be notify on this stream */ receiveStream(): Observable<Uint8Array>; /** * Observe connection state changes */ onConnectionStateChange(): Observable<ConnectionStateChangeEvent>; } export declare namespace ComProtocol { class Errors extends Error { code: ErrorCode; static operationCanceled(): Errors; static notConnected(info: { protocol: ComProtocol; }): Errors; static timeoutError(info: { msg?: string; protocol: ComProtocol; timeout: number; startTime: Date; }): Errors; static operationInProgress(msg: string): Errors; static unknownError(): Errors; private constructor(); } enum ErrorCode { ProtocolNotConnected = "ProtocolNotConnected", TimeoutError = "TimeoutError", UnknownError = "UnknownError", OperationCancelled = "OperationCancelled", OperationInProgress = "ComProtocolOperationInProgress" } }