@iotize/tap
Version:
IoTize Device client for Javascript
75 lines (74 loc) • 2.99 kB
TypeScript
import { Decoder, Encoder } from '@iotize/common/converter/api';
import { ProtocolChangeEvent, RequestInterceptorType, TapClientInterface, TapRequestFrame, TapResponseFrame } from '@iotize/tap/client/api';
import { ComProtocol, ConnectionStateChangeEvent } from '@iotize/tap/protocol/api';
import { Observable } from 'rxjs';
import { InterceptorChain } from './interceptors/interceptor-chain';
export declare class TapClient implements TapClientInterface {
private _commandEncoder;
private _responseDecoder;
private _onProtocolChange;
private protocols;
private currentProtocolId?;
private _interceptorChain;
static create(protocol?: ComProtocol): TapClient;
constructor(requestEncoder: Encoder<TapRequestFrame, Uint8Array>, responseDecoder: Decoder<Uint8Array, TapResponseFrame>);
get interceptorChain(): InterceptorChain;
addInterceptor(interceptor: RequestInterceptorType): this;
isConnected(): boolean;
/**
* see {@link getCurrentProtocol}
*/
get protocol(): ComProtocol;
get commandEncoder(): Encoder<TapRequestFrame, Uint8Array>;
get responseDecoder(): Decoder<Uint8Array, TapResponseFrame>;
/**
* Get current protocol or throw an error if no protocol
*/
getCurrentProtocol(): ComProtocol;
/**
* Register/replace a communication protocol with given id
* If no communication protocol is selected yet, it will select it.
* @param newProtocol
* @param id
*/
addComProtocol(newProtocol: ComProtocol, id?: string): this;
/**
* Switch to given communication protocol identifier
* @throws if protocol identifier does not exist
* @param name
*/
switchProtocol(name: string): this;
/**
* Change communication protocol
* @throws if protocol identifier does not exist
* @param protocol can either be the communication protocol instance or a string identifier
*/
useComProtocol(protocol: ComProtocol | string): this;
/**
* Return true if protocol identifier is registered
* @param id
*/
hasProtocol(id: any): boolean;
connect(): Observable<any>;
disconnect(): Observable<any>;
/**
* Send request
* @param request
* @param bodyDecoder
*/
request<T>(request: TapRequestFrame): Observable<TapResponseFrame>;
/**
* Send raw request
* No interceptors/No encryption will be triggered
* @param dataIn request bytes
* @param bodyDecoder optional body decoder to use
*/
send<T>(dataIn: Uint8Array): Observable<TapResponseFrame>;
/**
* Listen to connection state change event
* We have to resubscribe when protocol change..
*/
onConnectionStateChange(): Observable<ConnectionStateChangeEvent>;
onProtocolChange(): Observable<ProtocolChangeEvent>;
protected _command<T>(command: TapRequestFrame): Observable<TapResponseFrame>;
}