RelayrtcDocs
Get started
Documentation
React SDK

Screen controls

Capture a display with optional audio and manage its publication.

On this page

Import and access

React
import { useLocalParticipant, useLocalMedia } from '@relayrtc/react'
 
const local = useLocalParticipant()
const { screen } = useLocalMedia()

Requirements

A connected room and screen:publish permission. Start from a click or another user gesture.

Methods

MethodReturnsPurpose
start(options?)Promise<RoomScreenSnapshot>Open the display picker and publish its tracks.
stop()Promise<void>Stop capture and unpublish video/audio.
mute()Promise<void>Pause screen video and audio publications and await server confirmation.
unmute()Promise<void>Resume publications after server confirmation.
subscribe(listener)() => voidObserve screen snapshots outside React.

Options

start takes browser DisplayMediaStreamOptions; the default is { video: true }.

SettingExampleMeaning
videotrueRequest display video.
video.frameRate{ ideal: 15, max: 30 }Display capture frame-rate preference.
audiotrueAsk for display audio, if supported and selected.

Other display options depend on the browser’s getDisplayMedia implementation. The user selects what to share. Requesting audio does not guarantee an audio track.

Example

React
await local?.screen.start({
  video: { frameRate: { ideal: 15, max: 30 } },
  audio: true,
})
await local?.screen.stop()

Snapshot

FieldMeaning
activeScreen capture and its video publication are active.
pendingCapture, publication or cleanup is in progress.
mutedLocal screen sender is paused.
videoTrackLocal display MediaStreamTrack, or null.
audioTrackLocal display audio track, or null.
videoPublicationPublished screen_video Track, or null.
audioPublicationPublished screen_audio Track, or null.

Behavior

The SDK handles the browser’s capture-ended event and removes publications. Await mute/unmute for server confirmation and matching remote publication states. Ending shared audio removes only the audio publication; screen video continues. To remove a shared screen from other participants, stop sharing.