@cloudpss/ubrpc
Version:
Rpc server/client build on websocket and ubjson.
17 lines (15 loc) • 361 B
text/typescript
import { encode } from '@cloudpss/ubjson';
import type { RpcPayload } from '../types/payload.js';
/** 发送消息 */
export function send<T extends RpcPayload['type']>(
socket: WebSocket,
type: T,
info: Omit<RpcPayload & { type: T }, 'type'>,
): void {
socket.send(
encode({
...info,
type,
}),
);
}