# How to switch between webcam and screen share using a single WebRTC live stream?

**URL:** https://community.wowza.com/t/how-to-switch-between-webcam-and-screen-share-using-a-single-webrtc-live-stream/55389
**Category:** Wowza Video (Formerly Streaming Cloud)
**Tags:** webrtc
**Created:** [June 15, 2020, 3:23pm UTC](https://community.wowza.com/t/how-to-switch-between-webcam-and-screen-share-using-a-single-webrtc-live-stream/55389 "2020-06-15T15:23:44Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Jose\_Emmanuel\_Manang](https://avatars.discourse-cdn.com/v4/letter/j/439d5e/32.png) [@Jose\_Emmanuel\_Manang](https://community.wowza.com/u/Jose_Emmanuel_Manang)
#### Post date: [June 15, 2020, 3:23pm UTC](https://community.wowza.com/t/how-to-switch-between-webcam-and-screen-share-using-a-single-webrtc-live-stream/55389/1 "2020-06-15T15:23:44Z")

</div>

I am using the resources on this link: [https://github.com/WowzaMediaSystems/webrtc-examples](https://github.com/WowzaMediaSystems/webrtc-examples).

---

<div class="post-metadata">

### Author: ![Amara\_Graham](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/amara_graham/32/381_2.png) [@Amara\_Graham](https://community.wowza.com/u/Amara_Graham)
#### Post date: [June 15, 2020, 3:46pm UTC](https://community.wowza.com/t/how-to-switch-between-webcam-and-screen-share-using-a-single-webrtc-live-stream/55389/2 "2020-06-15T15:46:21Z")

</div>

This functionality does not exist at this time in our repo. The example repo has one example for screenshare and one example for webcam chat/meeting, but not both.

---

<div class="post-metadata">

### Author: ![Marc\_Medina](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@Marc\_Medina](https://community.wowza.com/u/Marc_Medina)
#### Post date: [June 16, 2020, 3:02pm UTC](https://community.wowza.com/t/how-to-switch-between-webcam-and-screen-share-using-a-single-webrtc-live-stream/55389/3 "2020-06-16T15:02:52Z")

</div>

Hi Amara! I also encountered this kind of error. What would be the best way to implement Wowza for eLearning? The feature that I want to achieve is Live Stream the teacher’s video and at the same time Share Screen the presentation (Ex. PPT, PDF, etc.).

---

<div class="post-metadata">

### Author: ![Jose\_Emmanuel\_Manang](https://avatars.discourse-cdn.com/v4/letter/j/439d5e/32.png) [@Jose\_Emmanuel\_Manang](https://community.wowza.com/u/Jose_Emmanuel_Manang)
#### Post date: [June 16, 2020, 5:40am UTC](https://community.wowza.com/t/how-to-switch-between-webcam-and-screen-share-using-a-single-webrtc-live-stream/55389/4 "2020-06-16T05:40:55Z")

</div>

I see. I was planning to use Wowza for E-Learning where you can use your webcam and screen share simultaneously. Do you have some recommendations?

---

<div class="post-metadata">

### Author: ![Amara\_Graham](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/amara_graham/32/381_2.png) [@Amara\_Graham](https://community.wowza.com/u/Amara_Graham)
#### Post date: [June 16, 2020, 8:01pm UTC](https://community.wowza.com/t/how-to-switch-between-webcam-and-screen-share-using-a-single-webrtc-live-stream/55389/5 "2020-06-16T20:01:51Z")

</div>

@Jose Emmanuel Manangan @Marc Medina honestly I would use Zoom at this point. Currently we do not have a way to composite the webcam and screenshare into a single stream at the server with Wowza. We’ve talked about putting compositing on our roadmap, but I cannot make any promises as to when this may happen or if it would include handling use cases like this.

I’m happy to add this item into our feature request backlog.

---

<div class="post-metadata">

### Author: ![Remco\_Treuren](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@Remco\_Treuren](https://community.wowza.com/u/Remco_Treuren)
#### Post date: [June 26, 2020, 2:13pm UTC](https://community.wowza.com/t/how-to-switch-between-webcam-and-screen-share-using-a-single-webrtc-live-stream/55389/6 "2020-06-26T14:13:03Z")

</div>

You can switch between the two but not put them into one composite.

Switching is quite easy, what you need to use is replaceTrack. This will seamlessly switch the track from for instance webcam to screen and back without interrupting the stream. We’ve been doing this for years.

---

<div class="post-metadata">

### Author: ![Kevin\_Mui](https://avatars.discourse-cdn.com/v4/letter/k/7ea924/32.png) [@Kevin\_Mui](https://community.wowza.com/u/Kevin_Mui)
#### Post date: [September 1, 2020, 9:39pm UTC](https://community.wowza.com/t/how-to-switch-between-webcam-and-screen-share-using-a-single-webrtc-live-stream/55389/7 "2020-09-01T21:39:23Z")

</div>

Is there a repo that you can share? Sounds like you got it figured out!

---

<div class="post-metadata">

### Author: ![Kevin\_Mui](https://avatars.discourse-cdn.com/v4/letter/k/7ea924/32.png) [@Kevin\_Mui](https://community.wowza.com/u/Kevin_Mui)
#### Post date: [September 18, 2020, 7:35pm UTC](https://community.wowza.com/t/how-to-switch-between-webcam-and-screen-share-using-a-single-webrtc-live-stream/55389/8 "2020-09-18T19:35:59Z")

</div>

@Remco_Treuren could you share the codebase or example of how get webrtc to switch between cam/screenshare? TIA

---

<div class="post-metadata">

### Author: ![Remy\_G](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/remy_g/32/487_2.png) [@Remy\_G](https://community.wowza.com/u/Remy_G)
#### Post date: [September 25, 2020, 6:02pm UTC](https://community.wowza.com/t/how-to-switch-between-webcam-and-screen-share-using-a-single-webrtc-live-stream/55389/9 "2020-09-25T18:02:41Z")

</div>

You can use replaceTrack for this.

So you create a track for the screen with getDisplayMedia, and one for the camera with getUserMedia and you store the streams in two variables, let’s say ‘camera’ and ‘screen’. So you store the stream variable you get through both methods.

Then, to switch in this example from ‘camera’ to ‘stream’, :

```
     peerConnection.getSenders().forEach(
      function (rtpSender) {
        if (rtpSender.track.kind == 'video') {
          rtpSender.replaceTrack(screen.getVideoTracks()[0]).then(function() {
            console.log("Replaced video track from camera to screen");
          }).catch(function(error) {
            console.log("Could not replace video track: " + error);
          });
        }
      }
     );
```

---

<div class="post-metadata">

### Author: ![Chakrit\_Worakulsawat](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/chakrit_worakulsawat/32/1141_2.png) [@Chakrit\_Worakulsawat](https://community.wowza.com/u/Chakrit_Worakulsawat)
#### Post date: [June 15, 2022, 4:01am UTC](https://community.wowza.com/t/how-to-switch-between-webcam-and-screen-share-using-a-single-webrtc-live-stream/55389/10 "2022-06-15T04:01:22Z")

</div>

Hi everyone,

I just tried `replaceVideoTrack()` function in webrtc-examples, but got the `PeerConnectionError` from `startPublish()` 's callback:

```auto
{
message: 'Peer connection failed',
stack: "Error: Failed to execute 'setLocalDescription' on 'RTCPeerConnection': Failed to set local offer sdp: Failed to set local video description recv parameters for m-section with mid='2'."
}

```

Anyone ever encountered this?  
Thanks!
