2025-12-03 02:20:38 +00:00
|
|
|
/**
|
|
|
|
|
* Message types for the smartsocket protocol
|
|
|
|
|
*/
|
|
|
|
|
export type TMessageType =
|
|
|
|
|
| 'authRequest' // Server requests authentication from client
|
|
|
|
|
| 'auth' // Client provides authentication data
|
|
|
|
|
| 'authResponse' // Server responds to authentication
|
|
|
|
|
| 'serverReady' // Server signals it's fully ready
|
|
|
|
|
| 'function' // Function call request
|
|
|
|
|
| 'functionResponse' // Function call response
|
|
|
|
|
| 'tagUpdate'; // Tag store synchronization
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Base message interface for all smartsocket messages
|
|
|
|
|
*/
|
2025-12-04 07:59:44 +00:00
|
|
|
export interface ISocketMessage<T = unknown> {
|
2025-12-03 02:20:38 +00:00
|
|
|
type: TMessageType;
|
|
|
|
|
id?: string; // For request/response correlation
|
|
|
|
|
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
|
|
|
|
|
*/
|
2025-12-04 07:59:44 +00:00
|
|
|
export interface IFunctionCallPayload<T = unknown> {
|
2025-12-03 02:20:38 +00:00
|
|
|
funcName: string;
|
2025-12-04 07:59:44 +00:00
|
|
|
funcData: T;
|
2025-12-03 02:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tag update payload
|
|
|
|
|
*/
|
|
|
|
|
export interface ITagUpdatePayload {
|
2025-12-04 07:59:44 +00:00
|
|
|
tags: Record<string, unknown>;
|
2025-12-03 02:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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>;
|