maybe finally fix double audio

This commit is contained in:
legop3
2026-02-18 22:02:32 -05:00
parent d165f69b6f
commit f1c6ab44ce
4 changed files with 18 additions and 13 deletions
+5 -3
View File
@@ -291,6 +291,7 @@ export default function VideoTile({
url: sessionInfo.url,
token: sessionInfo.token,
video: videoRef.current,
receiveAudio: !hasDedicatedAudio,
onStatus: handleStatus,
});
@@ -306,7 +307,7 @@ export default function VideoTile({
clearTimeout(resetMuteId);
player?.stop();
};
}, [usingSnapshot, sessionInfo?.url, sessionInfo?.token, restartToken, scheduleRestart, ensurePlayback]);
}, [usingSnapshot, sessionInfo?.url, sessionInfo?.token, restartToken, scheduleRestart, ensurePlayback, hasDedicatedAudio]);
useEffect(() => {
if (status === 'stopped' && sessionInfo?.url) {
@@ -330,7 +331,8 @@ export default function VideoTile({
if (graphReady) {
const compressor = audioCompressorRef.current;
const gainNode = audioGainRef.current;
audioEl.volume = 1;
// Keep element output at zero; audio should come only from WebAudio graph.
audioEl.volume = 0;
if (gainNode) {
gainNode.gain.value = effectiveRoverGain;
}
@@ -354,7 +356,7 @@ export default function VideoTile({
}
const hasGraph = Boolean(audioSourceNodeRef.current && audioGainRef.current);
audioEl.volume = hasGraph ? 1 : effectiveRoverGain;
audioEl.volume = hasGraph ? 0 : effectiveRoverGain;
if (audioCompressorRef.current) {
audioCompressorRef.current.threshold.value = 0;
audioCompressorRef.current.knee.value = 0;
+6 -3
View File
@@ -27,11 +27,12 @@ function buildAuthHeader(token) {
}
export class WhepPlayer {
constructor({ url, token, video, onStatus, audioOnly = false }) {
constructor({ url, token, video, onStatus, audioOnly = false, receiveAudio = true }) {
this.url = url;
this.token = token;
this.video = video;
this.audioOnly = audioOnly;
this.receiveAudio = receiveAudio;
this.pc = null;
this.abortController = null;
this.onStatus = onStatus;
@@ -78,7 +79,9 @@ export class WhepPlayer {
pc.addTransceiver('audio', { direction: 'recvonly' });
} else {
pc.addTransceiver('video', { direction: 'recvonly' });
pc.addTransceiver('audio', { direction: 'recvonly' });
if (this.receiveAudio) {
pc.addTransceiver('audio', { direction: 'recvonly' });
}
}
pc.onconnectionstatechange = () => {
@@ -93,7 +96,7 @@ export class WhepPlayer {
try {
const offer = await pc.createOffer({
offerToReceiveAudio: true,
offerToReceiveAudio: this.audioOnly ? true : this.receiveAudio,
offerToReceiveVideo: !this.audioOnly,
});
await pc.setLocalDescription(offer);