When sharing a screen using the Vonage Video API the browser presents options as to what screen or component to share on the stream. This happens outside of code in the browser. In some scenarios, it may be desirable to know what option was selected by the user.
- Vonage Video API
- Initialise the publisher with the: videoSource: "screen" parameter
- Wait until the stream is created (You can use the streamCreated event as per the sample below)
- Use publisher.getVideoSource() to obtain the MediaStreamTrack object for the stream
- Review the MediaStreamTrack.track.label parameter which contains information on the selection that was made by the user.
const mst = publisher.getVideoSource(); // Returns a MediaStreamTrack object
The output will be one of the following depending on the selection of screen, window or tab:
label: 'screen:1:0' OR label: 'screen:2:0' (primary or secondary screen where available)
label: "window:2936:0" (A specific Window)
label: "web-contents-media-stream://603F00B94761A0F37D10271C79342286" (a browser tab)
Individual web pages are not tab aware and cannot access information on other tabs, windows or applications. Although you cannot identify the source of the tab or window you can determine what type of stream is being published based on this information.
More information on the MediaStreamTrack object can be found here:
NOTE: These examples are for Chromium based browsers. While these objects are available in Safari the screen sharing mechanism is different. In Safari I always observed a label of "Screen 0" and it always selected the screen on which the page was resident.