fix(goLive): instrument voice/stream handshake + createStream timeout (12s)

This commit is contained in:
asepharyana
2026-08-11 20:00:33 +07:00
parent f8b253ba5e
commit ff554fcff2
2 changed files with 28 additions and 1 deletions
@@ -262,6 +262,9 @@ a=ice-lite
[audioSection, videoSection, videoRtpMap].join("\n"), [audioSection, videoSection, videoRtpMap].join("\n"),
"answer", "answer",
); );
console.log(
`[goLive:${this.constructor.name}] SELECT_PROTOCOL_ACK processed — remote answer set (${[audioSection, videoSection].join("\n").length}B)`,
);
this.emit("select_protocol_ack"); this.emit("select_protocol_ack");
} }
@@ -519,10 +522,14 @@ a=ice-lite
const reconnect = () => { const reconnect = () => {
const webRtcConn = this._webRtcWrapper.initWebRtc(); const webRtcConn = this._webRtcWrapper.initWebRtc();
webRtcConn.onStateChange((state) => { webRtcConn.onStateChange((state) => {
console.log(`[goLive:${this.constructor.name}] pc state => ${state}`);
if (state === "closed" && !this._closed) reconnect(); if (state === "closed" && !this._closed) reconnect();
}); });
this._webRtcWrapper.onLocalDescription = (sdp) => { this._webRtcWrapper.onLocalDescription = (sdp) => {
const rtc_connection_id = randomUUID(); const rtc_connection_id = randomUUID();
console.log(
`[goLive:${this.constructor.name}] sending SELECT_PROTOCOL (offer ${sdp.length}B, rtc_connection_id=${rtc_connection_id.slice(0, 8)})`,
);
this.sendOpcode(VoiceOpCodes.SELECT_PROTOCOL, { this.sendOpcode(VoiceOpCodes.SELECT_PROTOCOL, {
protocol: "webrtc", protocol: "webrtc",
codecs: Object.values(CodecPayloadType), codecs: Object.values(CodecPayloadType),
@@ -48,7 +48,19 @@ export class Streamer {
this._client = client; this._client = client;
// listen for gateway dispatch events // listen for gateway dispatch events
this.client.on("raw", (packet) => { this.client.on("raw", (packet) => {
this._gatewayEmitter.emit(packet.t, packet.d); const t = packet.t as string;
if (
t === "STREAM_CREATE" ||
t === "STREAM_SERVER_UPDATE" ||
t === "VOICE_STATE_UPDATE" ||
t === "VOICE_SERVER_UPDATE"
) {
console.log(
`[goLive:Streamer] raw dispatch ${t}`,
JSON.stringify(packet.d).slice(0, 220),
);
}
this._gatewayEmitter.emit(t, packet.d);
}); });
} }
@@ -142,6 +154,13 @@ export class Streamer {
return; return;
} }
this.signalStream(); this.signalStream();
const streamTimeout = setTimeout(() => {
reject(
new Error(
"Timed out waiting for STREAM_CREATE/STREAM_SERVER_UPDATE from Discord (stream handshake) — voice media session may not be active",
),
);
}, 12_000);
const { const {
guildId: clientGuildId, guildId: clientGuildId,
channelId: clientChannelId, channelId: clientChannelId,
@@ -155,6 +174,7 @@ export class Streamer {
clientUserId, clientUserId,
clientChannelId, clientChannelId,
(conn) => { (conn) => {
clearTimeout(streamTimeout);
resolve(conn); resolve(conn);
}, },
); );