@iotize/device-client.js
Version:
IoTize Device client for Javascript
79 lines (78 loc) • 3.23 kB
TypeScript
import { Observable } from 'rxjs';
import { Decoder, Encoder } from '../../core';
import { ComProtocol, ConnectionStateChangeEvent } from '../../protocol/api/com-protocol.interface';
import { ResponseInterface } from '../api';
import { BodyDecoder } from '../api/converter';
import { IoTizeClient as IoTizeClientInterface, ProtocolChangeEvent } from '../api/iotize-client.interface';
import { InterceptorChain, RequestInterceptorType } from './interceptors';
import { Command } from './request/command';
import { Response } from './response/response';
export declare class DefaultIoTizeClient implements IoTizeClientInterface {
private _commandEncoder;
private _responseDecoder;
private _onProtocolChange;
private protocols;
private currentProtocolId?;
private _interceptorChain;
static create(protocol?: ComProtocol): DefaultIoTizeClient;
constructor(requestEncoder: Encoder<Command, Uint8Array>, responseDecoder: Decoder<Uint8Array, Response<any>>);
readonly interceptorChain: InterceptorChain;
addInterceptor(interceptor: RequestInterceptorType): this;
isConnected(): boolean;
/**
* see {@link getCurrentProtocol}
*/
readonly protocol: ComProtocol;
readonly commandEncoder: Encoder<Command, Uint8Array>;
readonly responseDecoder: Decoder<Uint8Array, Response<any>>;
/**
* 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 command
* @param command
* @param bodyDecoder
*/
command<T>(command: Command, bodyDecoder?: BodyDecoder<T>): Observable<ResponseInterface<T>>;
/**
* 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, bodyDecoder?: BodyDecoder<T>): Observable<Response<T>>;
/**
* Listen to connection state change event
* We have to resubscribe when protocol change..
*/
onConnectionStateChange(): Observable<ConnectionStateChangeEvent>;
onProtocolChange(): Observable<ProtocolChangeEvent>;
protected _command<T>(command: Command, bodyDecoder?: BodyDecoder<T>): Observable<Response<T>>;
}