Skip to content

语音通话与 TURN ​

发起通话 ​

网页私聊中点击通话按钮,对方接听后开始语音。双方需在线,单次最多 1 小时。连接默认使用 P2P,失败时尝试 TURN,也可手动切换中继。

TURN 适合直连失败或希望通过中继连接的网络。Worker 处理信令,音频由 P2P 或 TURN 传输;未配置 TURN 时仅能直连。

配置 Cloudflare TURN ​

  1. 在 Cloudflare Realtime 复用或创建 TURN Key。
  2. 将 Key 的 uid 保存为 Repository Secret EDGECHAT_TURN_KEY_ID。
  3. 将 Key 的 key 保存为 Repository Secret EDGECHAT_TURN_API_TOKEN。
  4. 重新运行 00 Deploy Worker。
  5. 用两个在线网页账号通话,切换 TURN 验证连接。

两个 Secret 成对填写,工作流在部署后通过 wrangler secret put 注入。TURN Key Token 使用该 Key 的凭据,独立于 Cloudflare 部署 API Token。通过 API 创建 Key 时需要 Calls Write 权限。

手动部署 ​

使用实际部署配置执行,按提示分别粘贴值:

bash
npx wrangler secret put EDGECHAT_TURN_KEY_ID --config wrangler.toml
npx wrangler secret put EDGECHAT_TURN_API_TOKEN --config wrangler.toml

保留模板中的 VOICE_CALL binding 与 Durable Object v4 迁移。浏览器只接收短期 TURN 凭据。

更新凭据 ​

Actions 用户修改上述两个 Repository Secrets 后重新部署。未填写时,工作流保留已在线上配置的 TURN Secrets。

使用范围与费用 ​

当前为在线网页一对一语音,不含群聊和视频;锁屏、进程停止或网络挂起可能中断。P2P 会向对方提供网络候选地址,选择 TURN 可强制中继。

TURN 流量按 Cloudflare Realtime 计费,Worker、D1、KV 和 DO 用量另计。价格见官方说明,协议见仓库文档。

基于 Cloudflare 构建 · 为自主部署而设计