Add track to existing stream

The web conference solution I’m working on only asks for the permissions it really needs. That’s why joining the session only asks for permission for capturing the microphone. As soon as the publisher also decides to share his webcam video stream, the permission for both audio and video needs to be granted.

My current way to implement this is by creating a publisher with only an audioSource first. As soon as a user decides to share his/her webcam stream, the old publisher gets “unpublished” and a new one is created. This works great, but it has a huge disadvantage: The stream will be interrupted for a short moment.

So my question is: Is there a way to “upgrade” a publisher’s stream that only contains an audio track to a publisher with both audio and video tracks without having to unpublish first? I couldn’t find anything about this in the docs.

If this doesn’t work, I guess I have to send a black canvas video stream alongside the audio stream as long as the webcam permission is not granted.

You can replacing the track with another one

https://docs.openvidu.io/en/2.16.0/advanced-features/switch-camera/#switch-camera

Thanks, but that’s not what I was asking for. I’d like to know whether it is possible to add a video track to a MediaStream which doesn’t have a video track yet. The replaceTrack() method only works if there is already a video track present.

Hello @plorenz-etes,

Currently it is not possible to do it.