Fix microphone permission checking for audio recording
See [#5580][0]. [0]: https://github.com/signalapp/Signal-Desktop/pull/5580
This commit is contained in:
parent
1dc353f089
commit
79b3b6408e
8 changed files with 69 additions and 43 deletions
|
@ -1,6 +1,7 @@
|
|||
// Copyright 2016-2020 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { requestMicrophonePermissions } from '../util/requestMicrophonePermissions';
|
||||
import * as log from '../logging/log';
|
||||
import type { WebAudioRecorderClass } from '../window.d';
|
||||
|
||||
|
@ -42,7 +43,15 @@ export class RecorderClass {
|
|||
}
|
||||
}
|
||||
|
||||
async start(): Promise<void> {
|
||||
async start(): Promise<boolean> {
|
||||
const hasMicrophonePermission = await requestMicrophonePermissions();
|
||||
if (!hasMicrophonePermission) {
|
||||
log.info(
|
||||
'Recorder/start: Microphone permission was denied, new audio recording not allowed.'
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
this.clear();
|
||||
|
||||
this.context = new AudioContext();
|
||||
|
@ -61,11 +70,11 @@ export class RecorderClass {
|
|||
try {
|
||||
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
||||
if (!this.context || !this.input) {
|
||||
this.onError(
|
||||
this.recorder,
|
||||
new Error('Recorder/getUserMedia/stream: Missing context or input!')
|
||||
const err = new Error(
|
||||
'Recorder/getUserMedia/stream: Missing context or input!'
|
||||
);
|
||||
return;
|
||||
this.onError(this.recorder, err);
|
||||
throw err;
|
||||
}
|
||||
this.source = this.context.createMediaStreamSource(stream);
|
||||
this.source.connect(this.input);
|
||||
|
@ -81,7 +90,10 @@ export class RecorderClass {
|
|||
|
||||
if (this.recorder) {
|
||||
this.recorder.startRecording();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
async stop(): Promise<Blob | undefined> {
|
||||
|
@ -120,15 +132,7 @@ export class RecorderClass {
|
|||
|
||||
this.clear();
|
||||
|
||||
if (error && error.name === 'NotAllowedError') {
|
||||
log.warn('Recorder/onError: Microphone permission missing');
|
||||
window.showPermissionsPopup();
|
||||
} else {
|
||||
log.error(
|
||||
'Recorder/onError:',
|
||||
error && error.stack ? error.stack : error
|
||||
);
|
||||
}
|
||||
log.error('Recorder/onError:', error && error.stack ? error.stack : error);
|
||||
}
|
||||
|
||||
getBlob(): Blob {
|
||||
|
|
|
@ -92,6 +92,7 @@ import {
|
|||
} from '../calling/constants';
|
||||
import { callingMessageToProto } from '../util/callingMessageToProto';
|
||||
import { getSendOptions } from '../util/getSendOptions';
|
||||
import { requestMicrophonePermissions } from '../util/requestMicrophonePermissions';
|
||||
import { SignalService as Proto } from '../protobuf';
|
||||
import dataInterface from '../sql/Client';
|
||||
import {
|
||||
|
@ -1510,20 +1511,8 @@ export class CallingClass {
|
|||
return true;
|
||||
}
|
||||
|
||||
private async requestMicrophonePermissions(): Promise<boolean> {
|
||||
const microphonePermission = await window.getMediaPermissions();
|
||||
if (!microphonePermission) {
|
||||
await window.showCallingPermissionsPopup(false);
|
||||
|
||||
// Check the setting again (from the source of truth).
|
||||
return window.getMediaPermissions();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private async requestPermissions(isVideoCall: boolean): Promise<boolean> {
|
||||
const microphonePermission = await this.requestMicrophonePermissions();
|
||||
const microphonePermission = await requestMicrophonePermissions();
|
||||
if (microphonePermission) {
|
||||
if (isVideoCall) {
|
||||
return this.requestCameraPermissions();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue