requestMicAccess method
Request microphone permission. Returns true if permission is granted, false otherwise. Documentation: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/permissions/request Documentation: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia This is a 'hack' to acquire media permissions. The permissions API is not supported in all browsers.
Implementation
@override
Future<bool?> requestMicAccess() async {
Logger.logLocalEvent("requesting mic permission");
try {
/// TODO(cybex-dev) - Check browser type, if it is Firefox (or Safari), use the permissions API else use the getUserMedia API
// final perm = await _webPermissionsDelegate?.request({"name": "microphone"});
// return (perm == "granted");
/// This dirty hack to get media stream. Request (to show permissions popup on Chrome and other browsers, then stop the stream to release the permission)
/// TODO(cybex-dev) - check supported media streams
html.MediaStream mediaStream = await _webNavigatorDelegate.getUserMedia(audio: true);
mediaStream.getTracks().forEach((track) => track.stop());
return hasMicAccess();
} catch (e) {
printDebug("Failed to request microphone permission");
printDebug(e);
return false;
}
}