Skip to content

Commit

Permalink
Clean up repeat jitterbuffer target event
Browse files Browse the repository at this point in the history
  • Loading branch information
ehfd authored Jun 7, 2024
1 parent 7624076 commit ff0ba43
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions addons/gst-web/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,44 +518,48 @@ function enableStatWatch() {
}
webrtc.onconnectionstatechange = (state) => {
videoConnected = state;
if (videoConnected === "connected" && audioConnected === "connected") {
app.status = state;
if (!statwatchenabled) {
enableStatWatch();
}
if (videoConnected === "connected") {
// Repeatedly emit minimum latency target
webrtc.peerConnection.getReceivers().forEach((receiver) => {
let intervalLoop = setInterval(() => {
let intervalLoop = setInterval(async () => {
if (receiver.track.readyState !== "live" || receiver.transport.state !== "connected") {
clearInterval(intervalLoop);
return;
} else {
receiver.jitterBufferTarget = receiver.jitterBufferDelayHint = receiver.playoutDelayHint = 0;
receiver.jitterBufferTarget = receiver.jitterBufferDelayHint = receiver.playoutDelayHint = 0.0;
}
}, 1);
});
} else {
app.status = state === "connected" ? audioConnected : videoConnected;
}
};
audio_webrtc.onconnectionstatechange = (state) => {
audioConnected = state;
if (videoConnected === "connected" && audioConnected === "connected") {
app.status = state;
if (!statwatchenabled) {
enableStatWatch();
}
} else {
app.status = state === "connected" ? audioConnected : videoConnected;
}
};
audio_webrtc.onconnectionstatechange = (state) => {
audioConnected = state;
if (audioConnected === "connected") {
// Repeatedly emit minimum latency target
audio_webrtc.peerConnection.getReceivers().forEach((receiver) => {
let intervalLoop = setInterval(() => {
let intervalLoop = setInterval(async () => {
if (receiver.track.readyState !== "live" || receiver.transport.state !== "connected") {
clearInterval(intervalLoop);
return;
} else {
receiver.jitterBufferTarget = receiver.jitterBufferDelayHint = receiver.playoutDelayHint = 0;
receiver.jitterBufferTarget = receiver.jitterBufferDelayHint = receiver.playoutDelayHint = 0.0;
}
}, 1);
});
}
if (audioConnected === "connected" && videoConnected === "connected") {
app.status = state;
if (!statwatchenabled) {
enableStatWatch();
}
} else {
app.status = state === "connected" ? videoConnected : audioConnected;
}
Expand Down

0 comments on commit ff0ba43

Please sign in to comment.