Add the start/stop screen share buttons.
In your index.html file add a screen share and stop sharing button in the same div as your make call button from part 1.
If you run this in a browser, you should see something like this:
Figure 1.1. Video area with call buttons
Now let’s apply the extra style style=”display:none” to our share screen and stop sharing buttons. We will only show these when connected to a call.
If you refresh your browser, you should see something like this:
Figure 1.2. Video area with a make call button
Let’s update the call.onEstablished method in the index.js file to display the screen share buttons when a call is connected.
Let’s also update the call.onEnded method in the index.js file to hide the screen share button when a call is disconnected.
Once you have an active call, you can start sharing your screen. To do this, let’s implement a new function in index.js
Optionally, we enlarge our video element. We increase its width from 300px to 800px.
await currentCall.startScreenShare() does all the internal job for us. This is a Sendbird function.
Once we call the screen sharing function from Sendbird, we set a listener for when the remote user stops it. The logic inside this function is to reduce the size of our video element (back to 300px) and hide the Stop share screen button.
Figure 2. Browsers internally will ask for which monitor you want to share.
Let’s apply the logic to stop screen sharing:
Congratulations on completing this tutorial! In Part 1, we implemented the functionality for making calls, and now in part 2, we have added the functionality for sharing your screen.
You are now ready to make users more efficient with their 1:1 communication in your web app!
Keep on building wonderful connections in your apps!
Stay up-to-date on the latest technical content from Sendbird.