@bddh/starling-realtime-client
Version:
58 lines (57 loc) • 1.72 kB
TypeScript
/**
* @file lib/Server
* @description ws服务逻辑处理
* @author zhangyue49
*/
import { type WebSocketClient } from '@bddh/starling-web-socket/es/interface';
import { CallbackMsgType, ConnectDataType, ConnectParamsType } from './interface';
export interface SteamDataType {
first: boolean;
last: boolean;
audio?: string;
body?: string;
}
export interface DHServerInterface {
action: string;
requestId: string;
clientTs: number;
body: string;
}
export interface DHErrServerInterface {
action: string;
requestId: string;
code?: number;
message?: string;
error: Error;
}
type ConnectListener = (data: ConnectDataType, off?: () => void) => void;
export interface createSocketParamsType {
token?: string;
appKey?: string;
appId?: string;
sessionId?: string;
parameters?: ConnectParamsType;
onConnect: ConnectListener;
onDigitalHumanCallback?: (data: CallbackMsgType) => void;
}
export interface RenderCallbackRes {
requestId: string;
action: string;
code: number;
body: string | null;
message: string;
}
export type RenderCallback = (res: RenderCallbackRes) => void;
declare class Server {
dhServerSocket: WebSocketClient | null;
private socketClosingPromise;
private readonly url;
private firstConnect;
private connectParams;
constructor(url: string);
createSocket: (props: createSocketParamsType) => Promise<WebSocketClient | null>;
closeSocket: () => Promise<void>;
handleConnect: () => Promise<void>;
sendMessage(message: DHServerInterface, listener: RenderCallback | null): Promise<void>;
}
export default Server;