UNPKG

@push.rocks/smartsocket

Version:

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

66 lines (65 loc) 2.31 kB
import * as plugins from './smartsocket.plugins.js'; import * as pluginsTyped from './smartsocket.pluginstyped.js'; import * as interfaces from './interfaces/index.js'; import { Smartsocket } from './smartsocket.classes.smartsocket.js'; import { SmartsocketClient } from './smartsocket.classes.smartsocketclient.js'; /** * defines is a SocketConnection is server or client side. Important for mesh setups. */ export type TSocketConnectionSide = 'server' | 'client'; /** * interface for constructor of class SocketConnection */ export interface ISocketConnectionConstructorOptions { alias: string; authenticated: boolean; side: TSocketConnectionSide; smartsocketHost: Smartsocket | SmartsocketClient; socket: pluginsTyped.socketIo.Socket | pluginsTyped.socketIoClient.Socket; } /** * interface for authentication data */ export interface ISocketConnectionAuthenticationObject { alias: string; } export declare let allSocketConnections: plugins.lik.ObjectMap<SocketConnection>; /** * class SocketConnection represents a websocket connection */ export declare class SocketConnection { alias: string; side: TSocketConnectionSide; authenticated: boolean; smartsocketRef: Smartsocket | SmartsocketClient; socket: pluginsTyped.socketIo.Socket | pluginsTyped.socketIoClient.Socket; eventSubject: plugins.smartrx.rxjs.Subject<interfaces.TConnectionStatus>; eventStatus: interfaces.TConnectionStatus; private tagStore; tagStoreObservable: plugins.smartrx.rxjs.Subject<interfaces.TTagStore>; remoteTagStoreObservable: plugins.smartrx.rxjs.Subject<interfaces.TTagStore>; constructor(optionsArg: ISocketConnectionConstructorOptions); /** * 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>; /** * authenticate the socket */ authenticate(): Promise<unknown>; /** * listen to function requests */ listenToFunctionRequests(): Promise<unknown>; disconnect(): Promise<void>; private updateStatus; }