2.12 Publisher.replaceTrack()

Hello,
When using replaceTrack() in 2.12 to switch camera or share screen, after disconnecting the session, the camera and/or microphone is still in use.
Is this intended, and if so, how to properly clean up?
It works fine with the old solution of creating a new publisher and unpublish/publish, but I understood replaceTrack() was the way to go with 2.12.

Hello @Jan,

You’re right, When replaceTrack comes into play, the microphone and camera don’t release leaving the session.

We’ll fix it.

Thank you :slight_smile:

2 Likes

Actually the behavior is fine. When calling replaceTrack, you must have obtained a MediaStreamTrack object somehow. Probably by using native Web API getUserMedia or using OpenVidu.getUserMedia. Developers are responsible of those MediaStreams and their inner MediaStreamTracks. So you must store it and properly dispose it whenever you want. If you don’t dispose your own MediaStreamTracks, then the camera light of the device won’t shut down.

Regards.

Hey again @pabloFuente, I was struggling with disposing the tracks. I found that when replacing the video track, the audio tracks returned from getUserMedia were not handled. Thought I’d share my solution:

        .getUserMedia(constraints)
        .then(stream => {
            const track = stream.getVideoTracks()[0];
            publisher.replaceTrack(track);
            stream.getAudioTracks().forEach(t  => t.stop()); 
        })

If you are not gonna use the audio tracks, then you shouldn’t ask for them in the constraints. That should be the real solution.

Regards.

1 Like