Agora switch from audio to video call during voice call

1.3k views Asked by At

I have implemented Agora Web SDK for calling and its working great in Laravel and Vue.js.

I want to know if there is any way to switch from audio to video call while having audio call.

If I createStream with video = false then it is only audio call but I cannot change it to switch to video call using rtc.localStream.unmuteVideo() because it requires video = true to make it work

If I createStream with video = true then I turn of the camera using rtc.localStream.muteVideo(). So it turns off the camera and user can turn it on when required. But camera light is still on.

// create local stream
                this.rtc.localStream = AgoraRTC.createStream({
                    streamID: this.rtc.params.uid,
                    audio: true,
                    video: true,
                    screen: false,
                    microphoneId: this.option.microphoneId,
                    cameraId: this.option.cameraId
                });

Which means it is still a video call but video track is just a blank screen.

I am looking for a way where I can remove the only audio call stream and add audio-video call stream without interruption.

I have looked into Agora docs but I couldnt find anything about it.

I think once a stream is created then cannot change video to true or false.

UPDATE:

After reading Hermes' answer. I did some RnD and found some useful events.

Trick is same as mentioned in answer.

To change call from screen <=> audio <=> video <=> screen.

  1. Unpublish the local stream using
  2. Create new stream to add/remove video or screen sharing
  3. wait for old local stream to be unpublished and init the new stream and publish it.

Above 3 steps will trigger AGORA events

  1. client.unpublish triggers stream-removed event
  2. publish triggers stream-added event . In this event listener, subscribe to new stream. When you subscribe to new stream then stream-subscribed event is triggered.

On the basis of these events, you can update the ui and (local, remote) streams as well.

1

There are 1 answers

2
Hermes On BEST ANSWER

The best way to handle this is to use two Agora stream objects.

First create the audio only stream, and publish it using client.publish. Then when you want to change to a video call, \ then call client.unpublish on the the audio stream and create a second stream with video option enabled and call client.publish with the video stream.

There will be only a momentary interruption as the one stream is unpublished and then new one is published to the channel.