import type { DglabSocketDeviceType } from '../base/types'; /** * V4 协议帧类型 */ export type V4ServerFrame = V4HelloFrame | V4ClientAttachedFrame | V4ClientDisconnectedFrame | V4HeartbeatFrame | V4PongFrame | V4IdleTimeoutFrame | V4ErrorFrame | V4MessageFrame; /** * V4 Hello 帧 */ export interface V4HelloFrame { type: 'hello'; clientId: string; } /** * V4 客户端接入帧 */ export interface V4ClientAttachedFrame { type: 'client_attached'; clientId: string; } /** * V4 客户端断开帧 */ export interface V4ClientDisconnectedFrame { type: 'client_disconnected'; clientId: string; } /** * V4 心跳帧(控制方无需回复) */ export interface V4HeartbeatFrame { type: 'heartbeat'; } /** * V4 服务端级 PONG 帧 */ export interface V4PongFrame { type: 'pong'; } /** * V4 空闲超时帧(控制方空闲超时,随后连接会被服务端关闭) */ export interface V4IdleTimeoutFrame { type: 'idle_timeout'; } /** * V4 错误帧 */ export interface V4ErrorFrame { type: 'error'; code: string; message?: string; clientId?: string; } /** * V4 消息帧 */ export interface V4MessageFrame { type: 'message'; clientId: string; data: TData; } /** * V4 RPC 方法名 */ export type V4RpcMethod = 'devices.get' | 'device.op' | 'device.op.clear' | 'ping'; /** * V4 动作类型 * - AppendPulseData: 裸波形数据任务 * - AddIntensity: 相对增减强度任务 * - SetTempIntensity: 设置临时强度任务 * - SetIntensity: 设置绝对强度任务 */ export declare enum V4ActionType { AppendPulseData = 0, AddIntensity = 3, SetTempIntensity = 4, SetIntensity = 7 } /** * V4 通道类型 * - A: A 通道 * - B: B 通道 */ export declare enum V4Channel { A = 0, B = 1 } /** * V4 RPC 请求 */ export interface V4RpcRequest { t: 'req'; reqId?: string; requestId?: string; m?: V4RpcMethod | (string & {}); data?: TData; } /** * V4 RPC 响应 */ export interface V4RpcResponse { t: 'resp'; reqId?: string; requestId?: string; result?: TResult; error?: string; } /** * V4 设备描述 */ export interface V4DeviceDescriptor { slotId: string; name: string; type: DglabSocketDeviceType; } /** * V4 插槽状态 */ export interface V4SlotState { markLight: 'yellow' | 'green' | 'red' | 'purple' | 'blue' | 'cyan' | null; hasDevice: boolean; [key: string]: unknown; } /** * V4 设备信息 */ export interface V4DeviceInfo extends V4DeviceDescriptor { props?: Record; slotState?: Partial & Record; } /** * V4 设备列表获取结果 */ export interface V4DevicesGetResult { devices: V4DeviceDescriptor[]; } /** * V4 设备快照事件 */ export interface V4DevicesSnapshotEvent { t: 'ev'; ev: 'devices.snapshot'; devices: V4DeviceInfo[]; } /** * V4 设备列表增量事件 */ export interface V4DevicesPatchEvent { t: 'ev'; ev: 'devices.patch'; added?: V4DeviceInfo[]; removed?: string[]; } /** * V4 插槽增量事件 */ export interface V4SlotPatch { slotId: string; props?: Record; slotState?: Partial & Record; } /** * V4 插槽增量事件 */ export interface V4SlotsPatchEvent { t: 'ev'; ev: 'slots.patch'; slots?: V4SlotPatch[]; } /** * V4 自定义动作事件 */ export interface V4CustomActionEvent { t: 'ev'; ev: 'custom.action'; action: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9; } /** * V4 事件联合类型 */ export type V4EventPayload = V4DevicesSnapshotEvent | V4DevicesPatchEvent | V4SlotsPatchEvent | V4CustomActionEvent; /** * V4 设备事件 */ export type V4DeviceEventPayload = V4DeviceInfo | (Partial & { slotId: string; }); /** * V4 发送选项 */ export interface V4SendOptions { timeout?: number; } /** * V4 设备操作基础类型 */ export interface V4DeviceOperateBase { s: string; c: V4Channel; p?: 0 | 1 | 2; d?: number; im?: boolean; } /** * V4 相对强度指令 */ export interface V4AddIntensityOperate extends V4DeviceOperateBase { t: V4ActionType.AddIntensity; v: number; } /** * V4 临时强度任务 */ export interface V4SetTempIntensityOperate extends V4DeviceOperateBase { t: V4ActionType.SetTempIntensity; v: number; } /** * V4 绝对强度指令 */ export interface V4SetIntensityOperate extends V4DeviceOperateBase { t: V4ActionType.SetIntensity; v: number; } /** * V4 波形数据指令 */ export interface V4AppendPulseDataOperate extends V4DeviceOperateBase { t: V4ActionType.AppendPulseData; v: number[][] | string[]; ver?: number; seq?: number; } /** * V4 波形数据选项 */ export interface V4AppendPulseDataOptions extends Omit { version?: number; seq?: number; } /** * V4 设备操作联合类型 */ export type V4DeviceOperate = V4AddIntensityOperate | V4SetTempIntensityOperate | V4SetIntensityOperate | V4AppendPulseDataOperate; /** * V4 操作选项 */ export interface V4OperateOptions extends V4SendOptions { priority?: 0 | 1 | 2; immediate?: boolean; } /** * V4 清理操作选项 */ export type V4ClearOperateOptions = { slotId?: undefined; channel?: undefined; } | { slotId: string; channel?: V4Channel; }; /** * V4 发送 Promise */ export type V4SendPromise = Promise & { requestId?: string; clientId?: string; }; /** * V4 任意 RPC 负载联合类型 */ export type V4AnyRpcPayload = V4RpcRequest | V4RpcResponse | Record; /** * V4 等待响应 */ export interface V4PendingResponse { clientId: string; requestId: string; promise: Promise; resolve: (value: T | PromiseLike) => void; reject: (reason?: unknown) => void; timer?: ReturnType; settled: boolean; }