getUserMedia method

  1. @override
Future<MediaStream> getUserMedia(
  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> getUserMedia(
    Map<String, dynamic> mediaConstraints) async {
  try {
    final response = await WebRTC.invokeMethod(
      'getUserMedia',
      <String, dynamic>{'constraints': mediaConstraints},
    );
    if (response == null) {
      throw Exception('getUserMedia return null, something wrong');
    }

    String streamId = response['streamId'];
    var stream = MediaStreamNative(streamId, 'local');
    stream.setMediaTracks(
        response['audioTracks'] ?? [], response['videoTracks'] ?? []);
    return stream;
  } on PlatformException catch (e) {
    throw 'Unable to getUserMedia: ${e.message}';
  }
}