From f2ca02174002b7ebd81c85dccbdb3583b2775c60 Mon Sep 17 00:00:00 2001 From: Gregoire Parant Date: Sun, 5 Sep 2021 19:36:57 +0200 Subject: [PATCH] Hotfix media constraint error - Create error to manage displayed warning when we try to access on media with no constraint video and audio - Fix disabled microphone if we try to active and we don't have right or there is an error. Signed-off-by: Gregoire Parant --- .../Errors/MediaStreamConstraintsError.ts | 10 +++++++++ front/src/Stores/MediaStore.ts | 17 ++++++++++---- front/src/WebRtc/MediaManager.ts | 22 ++++++++++--------- 3 files changed, 35 insertions(+), 14 deletions(-) create mode 100644 front/src/Stores/Errors/MediaStreamConstraintsError.ts diff --git a/front/src/Stores/Errors/MediaStreamConstraintsError.ts b/front/src/Stores/Errors/MediaStreamConstraintsError.ts new file mode 100644 index 00000000..e7057f61 --- /dev/null +++ b/front/src/Stores/Errors/MediaStreamConstraintsError.ts @@ -0,0 +1,10 @@ +export class MediaStreamConstraintsError extends Error { + static NAME = "MediaStreamConstraintsError"; + + constructor() { + super( + "Unable to access your camera or microphone. Your browser is too old. Please consider upgrading your browser or try using a recent version of Chrome." + ); + this.name = MediaStreamConstraintsError.NAME; + } +} diff --git a/front/src/Stores/MediaStore.ts b/front/src/Stores/MediaStore.ts index 0ab40a79..b19a9356 100644 --- a/front/src/Stores/MediaStore.ts +++ b/front/src/Stores/MediaStore.ts @@ -9,6 +9,7 @@ import { WebviewOnOldIOS } from "./Errors/WebviewOnOldIOS"; import { gameOverlayVisibilityStore } from "./GameOverlayStoreVisibility"; import { peerStore } from "./PeerStore"; import { privacyShutdownStore } from "./PrivacyShutdownStore"; +import { MediaStreamConstraintsError } from "./Errors/MediaStreamConstraintsError"; /** * A store that contains the camera state requested by the user (on or off). @@ -251,8 +252,6 @@ export const mediaStreamConstraintsStore = derived( let currentAudioConstraint: boolean | MediaTrackConstraints = $audioConstraintStore; if ($enableCameraSceneVisibilityStore) { - console.log("currentVideoConstraint", currentVideoConstraint); - console.log("currentAudioConstraint", currentAudioConstraint); set({ video: currentVideoConstraint, audio: currentAudioConstraint, @@ -421,7 +420,7 @@ export const localStreamStore = derived, LocalS }); return; } catch (e) { - if (constraints.video !== false) { + if (constraints.video !== false || constraints.audio !== false) { console.info( "Error. Unable to get microphone and/or camera access. Trying audio only.", $mediaStreamConstraintsStore, @@ -433,7 +432,17 @@ export const localStreamStore = derived, LocalS error: e, }); // Let's try without video constraints - requestedCameraState.disableWebcam(); + if (constraints.video !== false) { + requestedCameraState.disableWebcam(); + } + if (constraints.audio !== false) { + requestedMicrophoneState.disableMicrophone(); + } + } else if (!constraints.video && !constraints.audio) { + set({ + type: "error", + error: new MediaStreamConstraintsError(), + }); } else { console.info( "Error. Unable to get microphone and/or camera access.", diff --git a/front/src/WebRtc/MediaManager.ts b/front/src/WebRtc/MediaManager.ts index f2a54b9e..7b32699b 100644 --- a/front/src/WebRtc/MediaManager.ts +++ b/front/src/WebRtc/MediaManager.ts @@ -12,6 +12,7 @@ import { gameOverlayVisibilityStore } from "../Stores/GameOverlayStoreVisibility import { layoutManagerActionStore, layoutManagerVisibilityStore } from "../Stores/LayoutManagerStore"; import { get } from "svelte/store"; import { localUserStore } from "../Connexion/LocalUserStore"; +import { MediaStreamConstraintsError } from "../Stores/Errors/MediaStreamConstraintsError"; export class MediaManager { startScreenSharingCallBacks: Set = new Set(); @@ -24,16 +25,17 @@ export class MediaManager { constructor() { localStreamStore.subscribe((result) => { if (result.type === "error") { - console.error(result.error); - layoutManagerActionStore.addAction({ - uuid: "cameraAccessDenied", - type: "warning", - message: "Camera access denied. Click here and check your browser permissions.", - callback: () => { - helpCameraSettingsVisibleStore.set(true); - }, - userInputManager: this.userInputManager, - }); + if (result.error.name !== MediaStreamConstraintsError.NAME) { + layoutManagerActionStore.addAction({ + uuid: "cameraAccessDenied", + type: "warning", + message: "Camera access denied. Click here and check your browser permissions.", + callback: () => { + helpCameraSettingsVisibleStore.set(true); + }, + userInputManager: this.userInputManager, + }); + } //remove it after 10 sec setTimeout(() => { layoutManagerActionStore.removeAction("cameraAccessDenied");