Skip to main content

Basic screen sharing

Screen sharing uses LocalScreenTrack, and the flow is similar to the camera:

Handle the browser’s built-in “Stop sharing” button

When the user clicks the “Stop sharing” button at the bottom of the browser, the SDK fires the TRACK_ENDED event, and you need to clean up state in the event callback:

Capture system audio at the same time

Some browsers (Chrome 74+, Windows/macOS) support capturing system audio (such as audio from a playing video) while sharing the screen. createLocalScreenTrack accepts a second parameter audioPreset; when you pass it, the SDK also captures system audio if the system supports it:
Note:
  • System audio capture is only reliably supported in Chrome (Windows/macOS)
  • Safari and Firefox don’t support system audio capture
  • The user must check “Share audio” in the browser dialog for getAudioTrack() to return a valid track
  • When you stop sharing, remember to also call unpublishLocalTrack(screenAudioTrack) and stopCapture()

ScreenCaptureOptions parameters

You can pass the following parameters when calling localScreenTrack.startCapture(options):

Presets (ScreenPresets)