UNPKG

@push.rocks/smartsocket

Version:

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

48 lines (47 loc) 1.93 kB
import * as plugins from './smartsocket.plugins.js'; import * as pluginsTyped from './smartsocket.pluginstyped.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'; export interface ISmartsocketConstructorOptions { alias: string; port?: number; } export declare class Smartsocket { /** * a unique id to detect server restarts */ alias: string; smartenv: plugins.smartenv.Smartenv; options: ISmartsocketConstructorOptions; socketConnections: plugins.lik.ObjectMap<SocketConnection>; socketFunctions: plugins.lik.ObjectMap<SocketFunction<any>>; socketRequests: plugins.lik.ObjectMap<SocketRequest<any>>; eventSubject: plugins.smartrx.rxjs.Subject<interfaces.TConnectionStatus>; private socketServer; constructor(optionsArg: ISmartsocketConstructorOptions); /** * Returns WebSocket hooks for integration with smartserve * Pass these hooks to SmartServe's websocket config */ getSmartserveWebSocketHooks(): pluginsTyped.ISmartserveWebSocketHooks; /** * starts smartsocket */ start(): Promise<void>; /** * Handle a new WebSocket connection * Called by SocketServer when a new connection is established */ handleNewConnection(socket: pluginsTyped.TWebSocket | pluginsTyped.IWebSocketLike): Promise<void>; /** * stops smartsocket */ stop(): Promise<void>; /** * allows call to specific client. */ clientCall<T extends plugins.typedrequestInterfaces.ITypedRequest>(functionNameArg: T['method'], dataArg: T['request'], targetSocketConnectionArg: SocketConnection): Promise<T['response']>; addSocketFunction(socketFunction: SocketFunction<any>): void; }