Calls: Show notification when missing access to camera or mic (#2157)
This commit is contained in:
parent
59a0d28b65
commit
74d88e80d5
@ -6,7 +6,7 @@ import { updateChat } from '../../reducers';
|
|||||||
import { ARE_CALLS_SUPPORTED } from '../../../util/environment';
|
import { ARE_CALLS_SUPPORTED } from '../../../util/environment';
|
||||||
import { notifyAboutCall } from '../../../util/notifications';
|
import { notifyAboutCall } from '../../../util/notifications';
|
||||||
import { selectPhoneCallUser } from '../../selectors/calls';
|
import { selectPhoneCallUser } from '../../selectors/calls';
|
||||||
import { initializeSoundsForSafari } from '../ui/calls';
|
import { checkNavigatorUserMediaPermissions, initializeSoundsForSafari } from '../ui/calls';
|
||||||
import { onTickEnd } from '../../../util/schedulers';
|
import { onTickEnd } from '../../../util/schedulers';
|
||||||
|
|
||||||
addActionHandler('apiUpdate', (global, actions, update) => {
|
addActionHandler('apiUpdate', (global, actions, update) => {
|
||||||
@ -96,6 +96,7 @@ addActionHandler('apiUpdate', (global, actions, update) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
void initializeSoundsForSafari();
|
void initializeSoundsForSafari();
|
||||||
|
void checkNavigatorUserMediaPermissions(call.isVideo);
|
||||||
return {
|
return {
|
||||||
...global,
|
...global,
|
||||||
phoneCall: call,
|
phoneCall: call,
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
import { addActionHandler, getGlobal, setGlobal } from '../../index';
|
import {
|
||||||
|
addActionHandler, getActions, getGlobal, setGlobal,
|
||||||
|
} from '../../index';
|
||||||
import { selectActiveGroupCall, selectChatGroupCall, selectGroupCall } from '../../selectors/calls';
|
import { selectActiveGroupCall, selectChatGroupCall, selectGroupCall } from '../../selectors/calls';
|
||||||
import { callApi } from '../../../api/gramjs';
|
import { callApi } from '../../../api/gramjs';
|
||||||
import { selectChat, selectUser } from '../../selectors';
|
import { selectChat, selectUser } from '../../selectors';
|
||||||
@ -217,6 +219,8 @@ addActionHandler('joinGroupCall', async (global, actions, payload) => {
|
|||||||
createAudioElement();
|
createAudioElement();
|
||||||
|
|
||||||
await initializeSoundsForSafari();
|
await initializeSoundsForSafari();
|
||||||
|
void checkNavigatorUserMediaPermissions(true);
|
||||||
|
|
||||||
const { groupCalls: { activeGroupCallId } } = global;
|
const { groupCalls: { activeGroupCallId } } = global;
|
||||||
let groupCall = id ? selectGroupCall(global, id) : selectChatGroupCall(global, chatId);
|
let groupCall = id ? selectGroupCall(global, id) : selectChatGroupCall(global, chatId);
|
||||||
|
|
||||||
@ -319,6 +323,7 @@ addActionHandler('requestCall', async (global, actions, payload) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await initializeSoundsForSafari();
|
await initializeSoundsForSafari();
|
||||||
|
void checkNavigatorUserMediaPermissions(isVideo);
|
||||||
|
|
||||||
setGlobal({
|
setGlobal({
|
||||||
...getGlobal(),
|
...getGlobal(),
|
||||||
@ -365,3 +370,44 @@ export function removeGroupCallAudioElement() {
|
|||||||
audioContext = undefined;
|
audioContext = undefined;
|
||||||
audioElement = undefined;
|
audioElement = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This method is used instead of a navigator.permissions.query to determine permission to use a microphone,
|
||||||
|
// because Firefox does not have support for 'microphone' and 'camera' permissions
|
||||||
|
// https://github.com/mozilla/standards-positions/issues/19#issuecomment-370158947
|
||||||
|
export function checkNavigatorUserMediaPermissions(isVideo?: boolean) {
|
||||||
|
if (isVideo) {
|
||||||
|
navigator.mediaDevices.getUserMedia({ video: true })
|
||||||
|
.then((stream) => {
|
||||||
|
if (stream.getVideoTracks().length === 0) {
|
||||||
|
getActions().showNotification({
|
||||||
|
message: langProvider.getTranslation('Call.Camera.Error'),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
checkMicrophonePermission();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
getActions().showNotification({
|
||||||
|
message: langProvider.getTranslation('Call.Camera.Error'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
checkMicrophonePermission();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkMicrophonePermission() {
|
||||||
|
navigator.mediaDevices.getUserMedia({ audio: true })
|
||||||
|
.then((stream) => {
|
||||||
|
if (stream.getAudioTracks().length === 0) {
|
||||||
|
getActions().showNotification({
|
||||||
|
message: langProvider.getTranslation('RequestAcces.Error.HaveNotAccess.Call'),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
getActions().showNotification({
|
||||||
|
message: langProvider.getTranslation('RequestAcces.Error.HaveNotAccess.Call'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user