Description:
Could you please add functionality to dynamically update the media source during an active stream? This could be implemented in setMediaStream or like as a new method updateMediaStream.
I’ve created a rough implementation (see example below), but I’m not a JavaScript developer, and I’m concerned about potential issues:
- Updating the video source with different constraints (e.g., resolution changes). Do we need to create a new offer or perform additional steps to update the parameters?
- Removing and re-adding tracks (e.g.,
audioSender.replaceTrack(null)). After removing a track, adding a new one fails because the sender is no longer found.
Here’s my example code for video track replacement:
async function replaceVideoTrackOnFly(newVideoTrack) {
if (!ovenkit || !isStreaming) return;
try {
// Find the current video sender in the peer connection
const videoSender = ovenkit.peerConnection.getSenders().find(sender =>
sender.track && sender.track.kind === 'video'
);
if (videoSender) {
// Replace the track
await videoSender.replaceTrack(newVideoTrack);
// Also update the input stream that OvenKit keeps track of
const oldTrack = ovenkit.inputStream.getVideoTracks()[0];
if (oldTrack) {
ovenkit.inputStream.removeTrack(oldTrack);
}
ovenkit.inputStream.addTrack(newVideoTrack);
console.log('Video track replaced successfully');
return true;
} else {
console.error('No video sender found in peer connection');
return false;
}
} catch (err) {
console.error('Error replacing video track:', err);
return false;
}
}
This seems to work, but I’m unsure about the technical nuances. Could you provide guidance or implement a robust solution for this use case? Thank you!
Description:
Could you please add functionality to dynamically update the media source during an active stream? This could be implemented in
setMediaStreamor like as a new methodupdateMediaStream.I’ve created a rough implementation (see example below), but I’m not a JavaScript developer, and I’m concerned about potential issues:
audioSender.replaceTrack(null)). After removing a track, adding a new one fails because the sender is no longer found.Here’s my example code for video track replacement:
This seems to work, but I’m unsure about the technical nuances. Could you provide guidance or implement a robust solution for this use case? Thank you!