UNPKG

@push.rocks/smartsocket

Version:

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

54 lines (53 loc) 1.44 kB
/** * Message types for the smartsocket protocol */ export type TMessageType = 'authRequest' | 'auth' | 'authResponse' | 'serverReady' | 'function' | 'functionResponse' | 'tagUpdate'; /** * Base message interface for all smartsocket messages */ export interface ISocketMessage<T = unknown> { type: TMessageType; id?: string; payload: T; } /** * Authentication request payload (server -> client) */ export interface IAuthRequestPayload { serverAlias: string; } /** * Authentication data payload (client -> server) */ export interface IAuthPayload { alias: string; } /** * Authentication response payload (server -> client) */ export interface IAuthResponsePayload { success: boolean; error?: string; } /** * Function call payload */ export interface IFunctionCallPayload<T = unknown> { funcName: string; funcData: T; } /** * Tag update payload */ export interface ITagUpdatePayload { tags: Record<string, unknown>; } /** * Helper type for creating typed messages */ export type TAuthRequestMessage = ISocketMessage<IAuthRequestPayload>; export type TAuthMessage = ISocketMessage<IAuthPayload>; export type TAuthResponseMessage = ISocketMessage<IAuthResponsePayload>; export type TFunctionMessage = ISocketMessage<IFunctionCallPayload>; export type TFunctionResponseMessage = ISocketMessage<IFunctionCallPayload>; export type TTagUpdateMessage = ISocketMessage<ITagUpdatePayload>;