Discussions
OnTrack event error
6 months ago by sudesh.wong
After peerconnection gets disconnected , when we reconnect, we are getting this error
ChatComponent.tsx:264 Uncaught (in promise) InvalidAccessError: Failed to execute 'getStats' on 'RTCPeerConnection': There is no sender or receiver for the track.
This happens in the onTrack event
function onTrack(event) {
if (!event.track) return;
statsIntervalId = setInterval(async () => {
if (peerConnection) {
const stats = await peerConnection.getStats(event.track); // This part is getting error
stats.forEach((report) => {
if (report.type === 'inbound-rtp' && report.kind === 'video') {
const videoStatusChanged = videoIsPlaying !== report.bytesReceived > lastBytesReceived;
if (videoStatusChanged) {
videoIsPlaying = report.bytesReceived > lastBytesReceived;
onVideoStatusChange(videoIsPlaying, event.streams[0]);
}
lastBytesReceived = report.bytesReceived;
}
});
}
return null;
}, 500);
}
Kindly advise
Thank you