UNPKG

@push.rocks/smartsocket

Version:

Provides easy and secure websocket communication mechanisms, including server and client implementation, function call routing, connection management, and tagging.

77 lines (76 loc) 2.45 kB
import * as plugins from './smartsocket.plugins.js'; import * as interfaces from './interfaces/index.js'; import { SocketConnection } from './smartsocket.classes.socketconnection.js'; import { SocketFunction } from './smartsocket.classes.socketfunction.js'; import { SocketRequest } from './smartsocket.classes.socketrequest.js'; /** * interface for class SmartsocketClient */ export interface ISmartsocketClientOptions { port: number; url: string; alias: string; autoReconnect?: boolean; maxRetries?: number; initialBackoffDelay?: number; maxBackoffDelay?: number; } export declare class SmartsocketClient { shortId: string; remoteShortId: string; alias: string; socketConnection: SocketConnection; serverUrl: string; serverPort: number; autoReconnect: boolean; maxRetries: number; initialBackoffDelay: number; maxBackoffDelay: number; currentRetryCount: number; currentBackoffDelay: number; eventSubject: plugins.smartrx.rxjs.Subject<interfaces.TConnectionStatus>; eventStatus: interfaces.TConnectionStatus; socketFunctions: plugins.lik.ObjectMap<SocketFunction<any>>; socketRequests: plugins.lik.ObjectMap<SocketRequest<any>>; private tagStore; private tagStoreSubscription; /** * adds a tag to a connection */ addTag(tagArg: interfaces.ITag): Promise<void>; /** * gets a tag by id * @param tagIdArg */ getTagById(tagIdArg: interfaces.ITag['id']): Promise<interfaces.ITag<any>>; /** * removes a tag from a connection */ removeTagById(tagIdArg: interfaces.ITag['id']): Promise<void>; constructor(optionsArg: ISmartsocketClientOptions); addSocketFunction(socketFunction: SocketFunction<any>): void; /** * connect the client to the server */ connect(): Promise<unknown>; private disconnectRunning; /** * disconnect from the server */ disconnect(useAutoReconnectSetting?: boolean): Promise<void>; /** * stops the client completely */ stop(): Promise<void>; /** * dispatches a server call * @param functionNameArg * @param dataArg */ serverCall<T extends plugins.typedrequestInterfaces.ITypedRequest>(functionNameArg: T['method'], dataArg: T['request']): Promise<T['response']>; private updateStatus; /** * Resets the reconnection state */ resetReconnectionState(): void; }