Adding a video source to a yet audio-only publisher

We are looking for a solution for adding a video source without interrupting audio transmission.

The goal is to write an application which only asks for permissions when they are needed, i.e. not to ask for video permission on joining the session. It should only be asked for once the video stream gets enabled by the user afterwards.

What we do at the moment is the following:

1.) The user joins the session and a new publisher transmitting only an audio stream is created:

var publisher = OV.initPublisher('videos', { audioSource: undefined, videoSource: null, publishAudio: true, publishVideo: false, insertMode: 'PREPEND' });

2.) The user presses the button for enabling his video stream:

`
var newPublisher = OV.initPublisher(‘videos’, {
audioSource: undefined,
videoSource: undefined,
publishAudio: true,
publishVideo: true,
resolution: ‘640x480’,
frameRate: 30,
insertMode: ‘PREPEND’,
mirror: true
});

newPublisher.on(‘videoElementCreated’, function (event) {
$(event.element).prop(‘muted’, true);
});

// unpublish the old publisher
session.unpublish(publisher);

// publish the new publisher
publisher = newPublisher;
session.publish(publisher);
`

The problem with this is that by unpublishing the stream, the audio stream gets interrupted for a few seconds. However, we don’t see another way for:

1.) Asking for video permission at a later time, and
2.) Adding a video stream to the existing audio stream

We’ve been looking for some kind of “dummy video device” which we can include in the initial publisher’s stream in order to replace it with the real stream afterwards - but we couldn’t find a way to get this working.

Is there any way to solve our issue so that the audio transmission doesn’t get interrupted?

Hi, you can try using replaceTrack method. https://docs.openvidu.io/en/2.15.0/advanced-features/switch-camera/#by-using-method-publisherreplacetrack

With this approach you can replace the video track without renegociate (unpublish and republish the stream) and the audio won’t get interrupted.

Hi, thanks for your reply.
I already know this function, however, if we start the stream with audio only, I can’t replace a non-existing video track by a real one.
For now, I tried creating a canvas video stream of a black square which I use as “dummy” video stream as long as video permission hasn’t been granted. However, the canvas element only generates video frames when it is modified and thus the video stream just stops, even audio isn’t transmitted anymore then.