@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) • 2.26 kB
TypeScript
import * as plugins from './smartsocket.plugins.js';
import { type ISocketFunctionCallDataRequest, type ISocketFunctionCallDataResponse } from './smartsocket.classes.socketfunction.js';
import { SocketConnection } from './smartsocket.classes.socketconnection.js';
import { Smartsocket } from './smartsocket.classes.smartsocket.js';
import { SmartsocketClient } from './smartsocket.classes.smartsocketclient.js';
export type TSocketRequestStatus = 'new' | 'pending' | 'finished';
export type TSocketRequestSide = 'requesting' | 'responding';
/**
* interface of constructor of class SocketRequest
*/
export interface ISocketRequestConstructorOptions<T extends plugins.typedrequestInterfaces.ITypedRequest> {
side: TSocketRequestSide;
originSocketConnection: SocketConnection;
shortId: string;
funcCallData?: ISocketFunctionCallDataRequest<T>;
}
/**
* request object that is sent initially and may or may not receive a response
*/
export interface ISocketRequestDataObject<T extends plugins.typedrequestInterfaces.ITypedRequest> {
funcCallData: ISocketFunctionCallDataRequest<T> | ISocketFunctionCallDataResponse<T>;
shortId: string;
responseTimeout?: number;
}
export declare class SocketRequest<T extends plugins.typedrequestInterfaces.ITypedRequest> {
static getSocketRequestById(smartsocketRef: Smartsocket | SmartsocketClient, shortIdArg: string): SocketRequest<any>;
status: TSocketRequestStatus;
side: TSocketRequestSide;
shortid: string;
originSocketConnection: SocketConnection;
funcCallData: ISocketFunctionCallDataRequest<T>;
done: plugins.smartpromise.Deferred<ISocketFunctionCallDataResponse<T>>;
smartsocketRef: Smartsocket | SmartsocketClient;
constructor(smartsocketRefArg: Smartsocket | SmartsocketClient, optionsArg: ISocketRequestConstructorOptions<T>);
/**
* dispatches a socketrequest from the requesting to the receiving side
*/
dispatch(): Promise<ISocketFunctionCallDataResponse<T>>;
/**
* handles the response that is received by the requesting side
*/
handleResponse(responseDataArg: ISocketRequestDataObject<T>): Promise<void>;
/**
* creates the response on the responding side
*/
createResponse(): Promise<void>;
}