UNPKG

@push.rocks/smartsocket

Version:

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

76 lines (75 loc) 2.61 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.TWebSocket | pluginsTyped.IWebSocketLike; } /** * 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.TWebSocket | pluginsTyped.IWebSocketLike; 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); /** * Sends a message through the socket */ sendMessage(message: interfaces.ISocketMessage): void; /** * Handles incoming messages */ handleMessage(messageData: interfaces.ISocketMessage): void; private handleFunctionCall; private handleFunctionResponse; private handleTagUpdate; /** * adds a tag to a connection */ addTag(tagArg: interfaces.ITag): Promise<void>; /** * Gets a tag by id */ getTagById(tagIdArg: interfaces.ITag['id']): interfaces.ITag | undefined; /** * Removes a tag from a connection */ removeTagById(tagIdArg: interfaces.ITag['id']): void; /** * authenticate the socket (server side) */ authenticate(): Promise<SocketConnection>; /** * listen to function requests */ listenToFunctionRequests(): Promise<unknown>; disconnect(): Promise<void>; private updateStatus; }