mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-03 09:52:50 +08:00
stream: the answer args key is "answer", and it plays
Live-verified against TS6 6.0.0-beta12.1: the working payload is
{"cmd":"answer","args":{"answer":"<sdp>"}}. Audio and video RTP now
arrive from a real TS6 publisher into the browser.
53f6856 sent the bare SDP string instead, inferred statically from an
`answer` branch in the inbound dispatcher that references no key
literal. The inference was wrong - that branch delegates the object
read to a shared JSON helper, and the key lives there. A branch with no
key literal in it means the read is elsewhere, not that there is no key.
The wrong shape is completely silent: the server accepts and routes the
command, and the client discards it. Only getStats() shows it, as TS6
answering our connectivity checks while never sending one of its own
(requestsReceived=0) - it replies from the credentials in its own offer
without ever having applied a remote description. So drop the 5 s
retry-in-the-other-shape fallback, and keep send_with_result on
streamsignaling so a refused command at least surfaces as an error.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
1 parent
c2e4760e37
commit
b57d32bc18
2 files changed
+27
-60
No files matched your search
+11
-5
@@ -1516,11 +1516,17 @@ async fn run(args: Args) -> Result<()> {
|
|||||||
packet.write_arg("id", &id);
|
packet.write_arg("id", &id);
|
||||||
packet.write_arg("clid", &clid);
|
packet.write_arg("clid", &clid);
|
||||||
packet.write_arg("json", &json);
|
packet.write_arg("json", &json);
|
||||||
// Fire and forget: ICE candidates arrive in bursts
|
// Not fire-and-forget: a signaling command the server refuses
|
||||||
// and a return_code round trip per candidate would
|
// (a stale clid, say) is otherwise indistinguishable from a peer
|
||||||
// only add latency to the handshake.
|
// that simply ignored the payload, and the whole handshake then
|
||||||
if let Err(e) = packet.send(&mut con) {
|
// stalls with nothing to look at.
|
||||||
emit(&Event::Error { message: format!("streamsignaling failed: {e}") });
|
match packet.send_with_result(&mut con) {
|
||||||
|
Ok(handle) => {
|
||||||
|
pending_messages.insert(handle, "Stream signaling".into());
|
||||||
|
}
|
||||||
|
Err(e) => emit(&Event::Error {
|
||||||
|
message: format!("streamsignaling failed: {e}"),
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => emit(&Event::Error {
|
_ => emit(&Event::Error {
|
||||||
|
|||||||
+16
-55
@@ -24,10 +24,11 @@ export interface StreamEvent {
|
|||||||
/**
|
/**
|
||||||
* The payload shape inside `notifystreamsignaling`'s `json` argument.
|
* The payload shape inside `notifystreamsignaling`'s `json` argument.
|
||||||
*
|
*
|
||||||
* `args` is not always an object: TS6's dispatcher reads it as a bare string
|
* Each `cmd` names its own key inside `args`, and the key is *not* `sdp`
|
||||||
* for `offer`/`reconnectOffer`/`answer` and as an object only for
|
* except for `iceCandidate`: an answer is `{answer: "<sdp>"}`, an offer
|
||||||
* `iceCandidate` (`sdp`/`mid`/`mLine`) and `joinResponse`
|
* `{offer: "<sdp>"}`, a candidate `{sdp, mid, mLine}`. Live-verified against
|
||||||
* (`decision`/`offer`) - see the note on ANSWER_ARGS_ARE_A_BARE_STRING.
|
* TS6 6.0.0-beta12.1 - `{sdp: "<sdp>"}` and a bare string are both accepted
|
||||||
|
* by the server and then silently dropped by the client.
|
||||||
*/
|
*/
|
||||||
interface SignalingMessage {
|
interface SignalingMessage {
|
||||||
cmd: string;
|
cmd: string;
|
||||||
@@ -61,23 +62,6 @@ export interface StreamViewerOptions {
|
|||||||
iceServers?: RTCIceServer[];
|
iceServers?: RTCIceServer[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether `{cmd:"answer"}` carries the SDP as `args` itself rather than as
|
|
||||||
* `args.sdp`.
|
|
||||||
*
|
|
||||||
* Derived from TeamSpeak.dll: the inbound dispatcher LEAs a key literal in
|
|
||||||
* every branch that reads an object (`decision`/`offer` for joinResponse,
|
|
||||||
* `sdp`/`mid`/`mLine` for iceCandidate) and none at all in the `answer` and
|
|
||||||
* `offer` branches, whose handler ends in `StreamP2P::SetAnswerString(const
|
|
||||||
* std::string&)`. That is static evidence, not a capture - TS6 has never had
|
|
||||||
* an answer from us to react to - so the viewer falls back to the object form
|
|
||||||
* if the connection has not come up in time (see ANSWER_FALLBACK_MS).
|
|
||||||
*/
|
|
||||||
const ANSWER_ARGS_ARE_A_BARE_STRING = true;
|
|
||||||
|
|
||||||
/** How long to wait before retrying the answer in the other shape. */
|
|
||||||
const ANSWER_FALLBACK_MS = 5000;
|
|
||||||
|
|
||||||
const DEFAULT_ICE_SERVERS: RTCIceServer[] = [
|
const DEFAULT_ICE_SERVERS: RTCIceServer[] = [
|
||||||
{ urls: "stun:turn.teamspeak.com:3478" },
|
{ urls: "stun:turn.teamspeak.com:3478" },
|
||||||
{ urls: "stun:turn2.teamspeak.com:3478" },
|
{ urls: "stun:turn2.teamspeak.com:3478" },
|
||||||
@@ -114,7 +98,6 @@ export class StreamViewer {
|
|||||||
private pendingRemoteCandidates: RTCIceCandidateInit[] = [];
|
private pendingRemoteCandidates: RTCIceCandidateInit[] = [];
|
||||||
private remoteDescriptionSet = false;
|
private remoteDescriptionSet = false;
|
||||||
private closed = false;
|
private closed = false;
|
||||||
private answerFallbackTimer: ReturnType<typeof setTimeout> | null = null;
|
|
||||||
|
|
||||||
readonly streamId: string;
|
readonly streamId: string;
|
||||||
readonly peerClientId: number;
|
readonly peerClientId: number;
|
||||||
@@ -178,35 +161,12 @@ export class StreamViewer {
|
|||||||
|
|
||||||
const answer = await pc.createAnswer();
|
const answer = await pc.createAnswer();
|
||||||
await pc.setLocalDescription(answer);
|
await pc.setLocalDescription(answer);
|
||||||
this.sendAnswer(answer.sdp ?? "");
|
this.signal("answer", { answer: answer.sdp ?? "" });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.fail(`Could not answer the stream offer: ${describe(err)}`);
|
this.fail(`Could not answer the stream offer: ${describe(err)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends the answer in the shape the DLL suggests, and re-sends it in the
|
|
||||||
* other one if that produced no connection. TS6 drops a payload it cannot
|
|
||||||
* read without complaining, so a silent stall is the only symptom of
|
|
||||||
* guessing wrong here.
|
|
||||||
*/
|
|
||||||
private sendAnswer(sdp: string): void {
|
|
||||||
this.clearAnswerFallback();
|
|
||||||
this.signal("answer", ANSWER_ARGS_ARE_A_BARE_STRING ? sdp : { sdp });
|
|
||||||
this.answerFallbackTimer = setTimeout(() => {
|
|
||||||
this.answerFallbackTimer = null;
|
|
||||||
if (this.closed || this.pc?.connectionState === "connected") return;
|
|
||||||
console.warn("[stream] no connection after the answer; retrying in the other args shape");
|
|
||||||
this.signal("answer", ANSWER_ARGS_ARE_A_BARE_STRING ? { sdp } : sdp);
|
|
||||||
}, ANSWER_FALLBACK_MS);
|
|
||||||
}
|
|
||||||
|
|
||||||
private clearAnswerFallback(): void {
|
|
||||||
if (this.answerFallbackTimer === null) return;
|
|
||||||
clearTimeout(this.answerFallbackTimer);
|
|
||||||
this.answerFallbackTimer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async handleSignaling(args: Record<string, string>): Promise<void> {
|
private async handleSignaling(args: Record<string, string>): Promise<void> {
|
||||||
let msg: SignalingMessage;
|
let msg: SignalingMessage;
|
||||||
try {
|
try {
|
||||||
@@ -241,14 +201,17 @@ export class StreamViewer {
|
|||||||
case "offer":
|
case "offer":
|
||||||
case "reconnectOffer": {
|
case "reconnectOffer": {
|
||||||
// Renegotiation from the publisher, e.g. after it switches source.
|
// Renegotiation from the publisher, e.g. after it switches source.
|
||||||
// Accept both shapes: the bare string is what the DLL reads, the
|
// `offer` mirrors the `answer` key we send; the other two are cheap
|
||||||
// object is cheap to tolerate and costs nothing if it never arrives.
|
// to tolerate and cost nothing if they never arrive.
|
||||||
|
const a = msg.args as Record<string, unknown> | string | null;
|
||||||
const sdp =
|
const sdp =
|
||||||
typeof msg.args === "string"
|
typeof a === "string"
|
||||||
? msg.args
|
? a
|
||||||
: typeof (msg.args as { sdp?: unknown } | null)?.sdp === "string"
|
: typeof a?.offer === "string"
|
||||||
? (msg.args as { sdp: string }).sdp
|
? a.offer
|
||||||
: null;
|
: typeof a?.sdp === "string"
|
||||||
|
? a.sdp
|
||||||
|
: null;
|
||||||
if (sdp) await this.acceptOffer(sdp);
|
if (sdp) await this.acceptOffer(sdp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -292,7 +255,6 @@ export class StreamViewer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pc.onconnectionstatechange = () => {
|
pc.onconnectionstatechange = () => {
|
||||||
if (pc.connectionState === "connected") this.clearAnswerFallback();
|
|
||||||
this.opts.onStateChange?.(pc.connectionState);
|
this.opts.onStateChange?.(pc.connectionState);
|
||||||
if (pc.connectionState === "failed") this.fail("The stream connection failed");
|
if (pc.connectionState === "failed") this.fail("The stream connection failed");
|
||||||
};
|
};
|
||||||
@@ -318,7 +280,6 @@ export class StreamViewer {
|
|||||||
close(): void {
|
close(): void {
|
||||||
if (this.closed) return;
|
if (this.closed) return;
|
||||||
this.closed = true;
|
this.closed = true;
|
||||||
this.clearAnswerFallback();
|
|
||||||
|
|
||||||
this.opts.send({
|
this.opts.send({
|
||||||
type: "leaveStream",
|
type: "leaveStream",
|
||||||
|
|||||||
Reference in new issue
Block a user