mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
feat(voice): support Cloudflare Tunnel deployments and WebRTC fallback
Route page and signaling traffic through Cloudflare Tunnel while sending WebRTC media over direct UDP, with optional TURN REST as a fallback. When WebRTC was already offered and then fails, stay in the current session, automatically resume compatibility audio, and keep a Reconnect WebRTC control. A reconnect retries WebRTC only, leaves compatibility running until it succeeds, and stays on compatibility if it fails again. Database schema 14 adds nullable voice override columns and is a one-way boundary: older binaries reject this database. This change is for review, not a production rollout.
This commit is contained in:
1 parent
9a12e2ee7b
commit
b6e7b1e4da
68 files changed
+3525
-189
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import { createHmac, randomBytes } from "node:crypto";
|
||||
import type { VoiceIceServer } from "../shared/voice-ice.js";
|
||||
|
||||
export interface TurnRestConfig {
|
||||
urls: string[];
|
||||
secret: string;
|
||||
ttlSeconds: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* coturn's `use-auth-secret` REST API:
|
||||
* username = "<expiry unix seconds>:<session id>"
|
||||
* credential = base64(HMAC-SHA1(secret, username))
|
||||
*
|
||||
* Credentials are minted per browser connection; they are not shared between
|
||||
* sessions and never need to be persisted.
|
||||
*/
|
||||
export function createTurnRestCredential(
|
||||
config: TurnRestConfig,
|
||||
sessionId: string,
|
||||
nowMs = Date.now(),
|
||||
): VoiceIceServer {
|
||||
const suffix = sessionId.replace(/[^A-Za-z0-9_-]/g, "").slice(0, 64) || randomBytes(8).toString("hex");
|
||||
const expiry = Math.floor(nowMs / 1_000) + Math.max(1, Math.trunc(config.ttlSeconds));
|
||||
const username = `${expiry}:${suffix}`;
|
||||
const credential = createHmac("sha1", config.secret).update(username).digest("base64");
|
||||
return {
|
||||
urls: config.urls.length === 1 ? config.urls[0]! : [...config.urls],
|
||||
username,
|
||||
credential,
|
||||
};
|
||||
}
|
||||
|
||||
export function createTurnRestUsername(expirySeconds: number, sessionId: string): string {
|
||||
return `${Math.trunc(expirySeconds)}:${sessionId}`;
|
||||
}
|
||||
Reference in new issue
Block a user