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 Video 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 Share the Screen 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.
Stream.closein sequence to unpublish and close the current screen-sharing stream.
AgoraRTC.createStreamto create a new local video stream.
Stream.publishto 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.
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:
- Supports only Chrome 65+, Safari and the latest Firefox browser.
- Does not take effect on some mobile devices.
- Does not support switching to a screen-sharing stream in dual-stream mode.