This page introduces three solutions for switching between the screen-sharing stream and the stream captured by the camera in a screen-sharing scenario using the Agora RTC SDK for Web.
Switching from the screen-sharing stream to the camera stream and vice versa are the same process. The following solutions take the first case as an example.
Create two Client objects on the sender, which correspond to the screen-sharing stream and the camera stream. See Enable both screen sharing and video for details.
To switch from the screen-sharing stream to the camera stream, subscribe to the camera stream on the receiver.
We recommend this solution if your application scenario allows creating two streams at the same time.
Client.unpublish
and Stream.close
in sequence to unpublish and close the current screen-sharing stream.AgoraRTC.createStream
to create a new local video stream.Stream.init
and Stream.publish
to initialize and publish the stream.This solution is reliable and works with multiple browsers and platforms, but it does not support dynamic switching. You may need to allow for a couple of seconds to switch streams.
Call Stream.replaceTrack
to replace the video track in the local stream with the screen-sharing stream.
This solution supports dynamic switching, but the replaceTrack
method has the following limitations: