Rate this page:

Screen Sharing in Voximplant

Screen Sharing allows you to share information on your screen during a call. You can share the entire screen or one of the active windows.

The best way to understand any functionality is to build a simple demo application. Let’s create a demo app that allows username1 to make a video call to username2 and, during the call, users can share their screen with one another. The demo app has three video blocks: the first one is for your own video stream, the second one is for the incoming video stream and the third one is for viewing locally what is being shared.

To simplify the process, we will use our video chat demo as a boilerplate. You can follow the link and copy whatever piece of code you want. So let’s do it!

SCREEN SHARING REQUIREMENTS:

  • Screen Sharing is available via VoxImplant WEB SDK only [at the moment].
  • The participant who starts sharing the screen (the initiator) should use Chrome or Firefox. - We recommend using the latest browser versions.
  • IMPORTANT: if the initiator uses Chrome, a special screen-sharing extension must be installed.
  • IMPORTANT: You should load your application over HTTPS (it also applies to localhost and dev environment). You won’t be able to share your screen in the apps loaded over HTTP, you will only be able to view the other participant.

1. CHROME EXTENSION (not actual as of February, 2019)

HELLO FROM 2019

Since Google Chrome implemented the native support of screen sharing in the 72 version, this step is not actual anymore. Though, you can explore the step if you're curious.

To use Screen Sharing in Chrome, you need to add a special extension. Get the extension template from the repository: https://github.com/voximplant/voximplant-chrome-extension

Go to the folder with the Chrome extension. Open the manifest.json file and add your website to the matches section.

Then, in the address bar on a new tab, type chrome://extensions to open the Extensions page. Select the Developer mode check box to enable loading extensions from a folder. Finally, click Load unpacked extension or drag the folder with extension onto the page to load the extension. The new extension will be displayed on the page.

IMPORTANT: If you want to change manifest.json again (for example, add another test server), you should also change the version parameter, namely increase its value. Then remove the extension from Chrome and add it again.

Great! Now you have a developer version of the extension for debugging and experimenting. However, your future users won’t be happy to install the extension in such a way. That’s why you should publish your extension in Google Web Store. For details, see the official documentation.

2. JS SCENARIO

First and foremost, you need to create a new VoxImplant application called videochat at https://manage.voximplant.com/applications, its full name will look like videochat.youraccountname.voximplant.com.

When you create an application, click on it and switch to Scenarios. Here, you have to create a backend JS scenario, let's call it simply forward. It could look like this:

Scenario code

Scenario code

That’s it, really! It’s just one smart helper function that will handle all the operations to connect two users.

Now you should create a new rule in your VoxImplant application using the new scenario. Go to the Routing tab of the application, name a new rule as intercom and leave the call pattern as default ( .* ).

Note that the application should have at least two active users, for example, username1 and username2. You can create them in the Users tab of the application.

From this step, we need to remember:

  • Full name of the application (videochat.youraccountname.voximplant.com)
  • Usernames (username1, username2)
  • Passwords for usernames (passw0rd) Tip: If you are confused about the concept, check these articles:

a) Your first VoxImplant application

b) Handling an incoming call

3. HTML + CSS

Remember that we are building a simple but user-friendly prototype that’s why we could use frameworks. So, let’s create index.html with mounted libraries: Bootstrap, JQuery and supporting scripts. See the index.html code here: https://github.com/voximplant/videochat/blob/master/WebApp/index.html Note that in HTML we use two local CSS files have been mounted: css/bootstrap-dialog.css and css/app.css. We’ve added them to make the application more user friendly. You can copy their content from the repository.

4. WEB SDK

To start using VoxImplant Web SDK, make sure that you’ve added the JavaScript library in <head>:

<script src="//cdn.voximplant.com/edge/voximplant.min.js" type="text/javascript"></script>

Then start writing the JS code for the application.

See the key pieces of code below, they are pretty important. The whole listing is available at the GitHub repository.

4.1 Initialize the SDK using a new instance:

SDK init

SDK init

4.2 Add a minimum number of handlers to provide the correct initialization:

Adding handlers

Adding handlers

4.3 Login function Do you remember the username(s), application name and passwords from paragraph one? You will definitely need them to use the application.

Logging in

Logging in

5. SCREEN SHARING

We need to add two buttons to turn ScreenSharing on/off and then make them work.

So, add the handlers with the shareScreen() and stopSharingScreen() methods to the corresponding buttons, that’s it. Note that calling shareScreen(true) allows the initiator to view what is being shared.

Sharing screen

Sharing screen

6. THE WHOLE CODE

Now you could check the whole demo app code here. Bear in mind that you should insert your own values (see paragraphs 2 and 4.3).

7. HOW TO USE IT

  • Upload the files from the WebApp folder to your web server and open index.html#accname=YOUR_VOXIMPLANT_ACCOUNT_NAME in your browser. Note that if you are using a local web server, the browser link will be like this: https://localhost:3000/#accname=YOUR_VOXIMPLANT_ACCOUNT_NAME
  • Open your awesome demo app on two different devices.
  • Allow access to your microphone and camera.
  • Sign in as username1 in one demo app
  • Sign in as username2 in the other demo app
  • In demo app 1 where you’re logged as username1, type username2 in the @Username field, then press Call. Wait a little while the video call is being established.
  • When the video stream starts, you can click Share Screen. Then a window will open in your browser prompting you to choose which screen/window you want to share. Choose the screen/window and click Share.
  • The other participant will see your screen/window. You will also be able to see what you are sharing at the moment.
  • To stop sharing the screen, click Stop Sharing. The screen sharing will stop immediately.