hasPermission method

Future<bool> hasPermission()

Implementation

Future<bool> hasPermission() async {
  final mediaDevices = web.window.navigator.mediaDevices;

  try {
    final constraints = web.MediaStreamConstraints(audio: {true}.toJSBox);
    final ms = await mediaDevices.getUserMedia(constraints).toDart;

    // Clean-up
    final tracks = ms.getAudioTracks().toDart;
    for (var track in tracks) {
      track.stop();
    }

    return true;
  } catch (_) {
    return false;
  }
}