跳到主要内容

httpSend()

httpSend(event: string, payload: any, opts?: { timeout?: number }): Promise<{ success: true } | { success: false; status: number; error: string }>

始终经 HTTP 发送 Broadcast,不依赖 WebSocket 状态。ArrayBuffer / ArrayBufferViewapplication/octet-stream 发送,其余 JSON 编码。仅发送时创建的频道,完成后应 removeChannel()

参数

event
string

Broadcast 事件名

payload
any

消息体,不能为空

opts
{ timeout?: number }

超时等选项

返回

Promise
object

成功返回 { success: true }

示例

const channel = realtime.channel("room");
try {
await channel.httpSend("cursor-pos", { x: 12, y: 40 });
} finally {
await realtime.removeChannel(channel);
}