Docs
React SDK

Screen controls

Capture a display with optional audio and manage its publication.

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()voidPause local screen video and audio senders.
unmute()voidResume local senders.
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. Local mute does not signal remote pause/resume in the current server. To remove a shared screen from other participants, stop sharing.