跳到主要内容

send()

send(args: { type: "broadcast" | "presence" | "postgres_changes"; event: string; payload?: any }, opts?: { timeout?: number }): Promise<"ok" | "timed out" | "error">

向频道发送消息。Broadcast 在 WebSocket 未就绪时会回退 HTTP(该回退将废弃,请改用 httpSend())。

参数

args
object
opts
{ timeout?: number }

超时等选项

返回

Promise
"ok" | "timed out" | "error"

发送结果

示例

channel.subscribe(async (status) => {
if (status !== "SUBSCRIBED") return;
await channel.send({
type: "broadcast",
event: "cursor-pos",
payload: { x: 12, y: 40 },
});
});