getDisplayMedia method

  1. @override
Future<MediaStream> getDisplayMedia(
  1. Map<String, dynamic> mediaConstraints
)
override

Calling this method will prompts the user to select and grant permission to capture the contents of a display or portion thereof (such as a window) as a MediaStream. The resulting stream can then be recorded using the MediaStream Recording API or transmitted as part of a WebRTC session.

Implementation

@override
Future<MediaStream> getDisplayMedia(
    Map<String, dynamic> mediaConstraints) async {
  try {
    final mediaDevices = html.window.navigator.mediaDevices;
    if (mediaDevices == null) throw Exception('MediaDevices is null');

    if (jsutil.hasProperty(mediaDevices, 'getDisplayMedia')) {
      final arg = jsutil.jsify(mediaConstraints);
      final jsStream = await jsutil.promiseToFuture<html.MediaStream>(
          jsutil.callMethod(mediaDevices, 'getDisplayMedia', [arg]));
      return MediaStreamWeb(jsStream, 'local');
    } else {
      final jsStream = await html.window.navigator.getUserMedia(
          video: {'mediaSource': 'screen'},
          audio: mediaConstraints['audio'] ?? false);
      return MediaStreamWeb(jsStream, 'local');
    }
  } catch (e) {
    throw 'Unable to getDisplayMedia: ${e.toString()}';
  }
}