DisplayMedia

Reactive wrapper around the Screen Capture API. Capture screen content with Angular signals.

Secure Context Required

This feature is available only in secure contexts (HTTPS) or potentially trustworthy origins (such as localhost or 127.0.0.1). Regular http:// URLs will not work in most browsers.

Loading demo...

Usage

angular-ts
import { Component } from '@angular/core';
import { displayMedia } from '@signality/core';

@Component({
  template: `
    @if (dm.isSupported()) {
      <button (click)="dm.start()" [disabled]="dm.stream()">
        Start Capture
      </button>
      <button (click)="dm.stop()" [disabled]="!dm.stream()">
        Stop Capture
      </button>
      <video [srcObject]="dm.stream()" autoplay></video>
    }
  `,
})
export class ScreenCaptureDemo {
  readonly dm = displayMedia(); 
}

Parameters

ParameterTypeDescription
optionsDisplayMediaOptionsOptional configuration (see Options below)

Options

OptionTypeDefaultDescription
videoboolean | MediaTrackConstraintstrueVideo constraints
audioboolean | MediaTrackConstraintsfalseAudio constraints
injectorInjector-Optional injector for DI context

Return Value

PropertyTypeDescription
isSupportedSignal<boolean>Whether Screen Capture API is supported
isActiveSignal<boolean>Whether currently capturing
streamSignal<MediaStream | null>Current media stream
errorSignal<Error | null>Last error occurred
start() => Promise<MediaStream | null>Start screen capture
stop() => voidStop screen capture

Browser Compatibility

The Screen Capture API has limited browser support. Always check isSupported() before using screen capture (see Browser API support detection):

angular-html
@if (screen.isSupported()) {
  <button (click)="screen.start()">Start Screen Share</button>
} @else {
  <p>Screen capture is not available in this browser</p>
}

For detailed browser support information, see Can I use: Screen Capture API.

SSR Compatibility

On the server, signals initialize with safe defaults:

  • isSupportedfalse
  • isActivefalse
  • streamnull
  • errornull
  • start, stop → no-op functions

Type Definitions

typescript
interface DisplayMediaOptions extends WithInjector {
  readonly video?: boolean | MediaTrackConstraints;
  readonly audio?: boolean | MediaTrackConstraints;
}

interface DisplayMediaRef {
  readonly isSupported: Signal<boolean>;
  readonly isActive: Signal<boolean>;
  readonly stream: Signal<MediaStream | null>;
  readonly error: Signal<Error | null>;
  readonly start: () => Promise<MediaStream | null>;
  readonly stop: () => void;
}

function displayMedia(options?: DisplayMediaOptions): DisplayMediaRef;
Edit this page on GitHub Last updated: Mar 19, 2026, 23:28:23