mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
fix: validate merged voice fallback and host toolbar features
This commit is contained in:
1 parent
02509ea551
commit
001457d004
32 files changed
+319
-102
No files matched your search
@@ -925,7 +925,7 @@ export function useVoiceWebSocket() {
|
||||
const sequence = voiceConnection.generation;
|
||||
const socket = ws.value;
|
||||
const isCurrent = () => generation === inputDeviceGeneration && sequence === voiceConnection.generation;
|
||||
const shouldRestartWebRtc = webrtc.active && Boolean(ws.value);
|
||||
const shouldRestartWebRtc = Boolean(webrtc.peer) && Boolean(ws.value);
|
||||
try {
|
||||
// Keep the current peer alive until the replacement microphone is ready.
|
||||
if (micStream) await startMicrophone();
|
||||
@@ -1485,7 +1485,7 @@ export function useVoiceWebSocket() {
|
||||
voxAttack = 0;
|
||||
voxRelease = 0;
|
||||
accumLen = 0;
|
||||
if (webrtc.active) micStream?.getAudioTracks().forEach((track) => { track.enabled = !muted; });
|
||||
if (webrtc.peer) micStream?.getAudioTracks().forEach((track) => { track.enabled = !muted; });
|
||||
webrtc.input?.setVolume(muted ? 0 : inputVolume.value);
|
||||
sendCmd("setMicrophoneMuted", { muted });
|
||||
if (muted && state.tsClientId) clearSpeaking(state.tsClientId);
|
||||
|
||||
@@ -490,8 +490,8 @@ test("the distributable host chrome toolbar declares its first compatible runtim
|
||||
assert.deepEqual(bundledArchive, archive, "the downloadable example and bundled skin stay in sync");
|
||||
const skin = await importSkinPack(new File([archive], "host-chrome-toolbar.wskin", { type: "application/octet-stream" }));
|
||||
assert.equal(skin.id, "community.host-chrome-toolbar");
|
||||
assert.equal(skin.minAppVersion, "0.3.3", "mode, appearance and anchor arrays are unavailable in WebSpeak 0.3.2");
|
||||
assert.equal(skin.version, "1.1.1");
|
||||
assert.equal(skin.minAppVersion, "0.3.4-dev.0", "released WebSpeak 0.3.3 rejects the new toolbar slot fields");
|
||||
assert.equal(skin.version, "1.1.2");
|
||||
assert.equal(APP_VERSION, skin.minAppVersion, "the running build must satisfy the example's declared minimum");
|
||||
assert.equal(skin.schemaVersion, 3);
|
||||
assert.equal(skin.packageType, "open-skin");
|
||||
|
||||
@@ -158,6 +158,8 @@ export function createOpusUplink(options: OpusUplinkOptions) {
|
||||
if (!active || closed || !samples.length) return active;
|
||||
let offset = 0;
|
||||
while (offset < samples.length) {
|
||||
// An encode error can deactivate the encoder inside this loop.
|
||||
if (!active) return false;
|
||||
const copy = Math.min(VOICE_FRAME_SAMPLES - pendingLength, samples.length - offset);
|
||||
pending.set(samples.subarray(offset, offset + copy), pendingLength);
|
||||
pendingLength += copy;
|
||||
@@ -171,7 +173,14 @@ export function createOpusUplink(options: OpusUplinkOptions) {
|
||||
function resetStream(): void {
|
||||
pendingLength = 0;
|
||||
timestampUs = 0;
|
||||
try { encoder?.reset(); } catch { /* reset is best effort */ }
|
||||
try {
|
||||
// WebCodecs reset clears configuration as well as pending output.
|
||||
encoder?.reset();
|
||||
encoder?.configure(OPUS_CONFIG);
|
||||
} catch (error) {
|
||||
options.onFallback(error instanceof Error ? error.message : "OPUS_RESET_FAILED");
|
||||
deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
function close(): void {
|
||||
|
||||
@@ -41,6 +41,7 @@ interface Attempt {
|
||||
active: boolean;
|
||||
closed: boolean;
|
||||
answerTimer: number | null;
|
||||
connectionTimer: number | null;
|
||||
cancelIce: (() => void) | null;
|
||||
}
|
||||
|
||||
@@ -73,6 +74,8 @@ export function createWebRtcTransport(options: TransportOptions) {
|
||||
previous.active = false;
|
||||
if (previous.answerTimer !== null) window.clearTimeout(previous.answerTimer);
|
||||
previous.answerTimer = null;
|
||||
if (previous.connectionTimer !== null) window.clearTimeout(previous.connectionTimer);
|
||||
previous.connectionTimer = null;
|
||||
const cancelIce = previous.cancelIce;
|
||||
previous.cancelIce = null;
|
||||
if (cancelIce) clean(cancelIce);
|
||||
@@ -84,6 +87,7 @@ export function createWebRtcTransport(options: TransportOptions) {
|
||||
if (peer) {
|
||||
clean(() => { peer.ontrack = null; });
|
||||
clean(() => { peer.onconnectionstatechange = null; });
|
||||
clean(() => { peer.onicecandidateerror = null; });
|
||||
clean(() => peer.close());
|
||||
}
|
||||
}
|
||||
@@ -98,6 +102,15 @@ export function createWebRtcTransport(options: TransportOptions) {
|
||||
if (isFailureCurrent()) await options.onFailure(reason, isFailureCurrent);
|
||||
}
|
||||
|
||||
function ready(record: Attempt): void {
|
||||
if (!isCurrent(record) || record.active || record.peer?.connectionState !== "connected"
|
||||
|| record.peer.remoteDescription?.type !== "answer") return;
|
||||
if (record.connectionTimer !== null) window.clearTimeout(record.connectionTimer);
|
||||
record.connectionTimer = null;
|
||||
record.active = true;
|
||||
options.onReady();
|
||||
}
|
||||
|
||||
async function waitForIce(record: Attempt, peer: RTCPeerConnection): Promise<void> {
|
||||
if (peer.iceGatheringState === "complete") return;
|
||||
await new Promise<void>(resolve => {
|
||||
@@ -120,7 +133,7 @@ export function createWebRtcTransport(options: TransportOptions) {
|
||||
async function start(connection: Connection): Promise<void> {
|
||||
stop();
|
||||
const record: Attempt = { connection, peer: null, input: null, meter: null,
|
||||
active: false, closed: false, answerTimer: null, cancelIce: null };
|
||||
active: false, closed: false, answerTimer: null, connectionTimer: null, cancelIce: null };
|
||||
current = record;
|
||||
let microphone: Microphone | null;
|
||||
try { microphone = await options.prepareMicrophone(); }
|
||||
@@ -161,10 +174,10 @@ export function createWebRtcTransport(options: TransportOptions) {
|
||||
peer.onconnectionstatechange = () => {
|
||||
options.onConnectionState?.(peer.connectionState);
|
||||
if (isCurrent(record) && peer.connectionState === "failed") void failAttempt(record, "WEBRTC_CONNECTION_FAILED");
|
||||
else ready(record);
|
||||
};
|
||||
options.onConnectionState?.(peer.connectionState);
|
||||
|
||||
record.active = true;
|
||||
const offer = await peer.createOffer();
|
||||
if (!isCurrent(record)) return;
|
||||
await peer.setLocalDescription({ ...offer, sdp: addOpusFmtpParameters(offer.sdp ?? "", ["stereo=1"]) });
|
||||
@@ -196,8 +209,16 @@ export function createWebRtcTransport(options: TransportOptions) {
|
||||
if (!isCurrent(record)) return;
|
||||
if (record.answerTimer !== null) window.clearTimeout(record.answerTimer);
|
||||
record.answerTimer = null;
|
||||
record.active = true;
|
||||
options.onReady();
|
||||
// An SDP answer acknowledges signaling, not a working ICE/DTLS path.
|
||||
// Keep compatibility audio until the peer really connects, and bound
|
||||
// attempts that remain stuck in "connecting" without a failed event.
|
||||
ready(record);
|
||||
if (!record.active && record.connectionTimer === null) {
|
||||
record.connectionTimer = window.setTimeout(() => {
|
||||
record.connectionTimer = null;
|
||||
if (isCurrent(record) && !record.active) void failAttempt(record, "WEBRTC_CONNECTION_TIMEOUT");
|
||||
}, 15_000);
|
||||
}
|
||||
} catch { await failAttempt(record, "WEBRTC_ANSWER_REJECTED"); }
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user