From 5d5099a0f5fcc2b20b98e3c616fa5a441200433a Mon Sep 17 00:00:00 2001 From: "Jan Brodersen (Armitxes)" Date: Wed, 15 Feb 2023 15:30:19 +0000 Subject: [PATCH] [FIX] mail: No crash from "enumerateDevices" in discuss calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, when accessing the discuss call settings in non-localhost without SSL, there was the following crash: ``` "Cannot read 'enumerateDevices' of undefined" ``` Odoo uses zxing-js to detect devices within the discuss app. zxing-js provides methods such as "hasNavigator", "isMediaDevicesSuported" or "canEnumerateDevices" to check if features are available. These are not called by Odoo before using the related features what can result in a JS traceback. This commit fixes the issue by showing a warning as a toaster notification and in the dev tools, instead of a traceback. The zxing-js methods are not exposed, hence the reliance on truthy mediaDevices. See also https://github.com/zxing-js/library/issues/225 Closes https://github.com/odoo/odoo/issues/112255 Closes https://github.com/odoo/odoo/pull/112813 closes odoo/odoo#119903 X-original-commit: 32238dd680396c6ccb519aa8b3fb7487c38395f7 Signed-off-by: Alexandre Kühn (aku) --- addons/mail/static/src/rtc/call_settings.js | 11 +++++++++++ doc/cla/individual/Armitxes.md | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 doc/cla/individual/Armitxes.md diff --git a/addons/mail/static/src/rtc/call_settings.js b/addons/mail/static/src/rtc/call_settings.js index 025e7fe4eba..cd2ce485516 100644 --- a/addons/mail/static/src/rtc/call_settings.js +++ b/addons/mail/static/src/rtc/call_settings.js @@ -4,12 +4,14 @@ import { Component, onWillStart, useExternalListener, useState } from "@odoo/owl import { useRtc } from "@mail/rtc/rtc_hook"; import { useService } from "@web/core/utils/hooks"; import { browser } from "@web/core/browser/browser"; +import { _t } from "@web/core/l10n/translation"; export class CallSettings extends Component { static template = "mail.CallSettings"; static props = ["thread", "className?"]; setup() { + this.notification = useService("notification"); this.userSettings = useState(useService("mail.user_settings")); this.rtc = useRtc(); this.state = useState({ @@ -18,6 +20,15 @@ export class CallSettings extends Component { useExternalListener(browser, "keydown", this._onKeyDown); useExternalListener(browser, "keyup", this._onKeyUp); onWillStart(async () => { + if (!browser.navigator.mediaDevices) { + // zxing-js: isMediaDevicesSuported or canEnumerateDevices is false. + this.notification.add( + _t("Media devices unobtainable. SSL might not be set up properly."), + { type: "warning" } + ); + console.warn("Media devices unobtainable. SSL might not be set up properly."); + return; + } this.state.userDevices = await browser.navigator.mediaDevices.enumerateDevices(); }); } diff --git a/doc/cla/individual/Armitxes.md b/doc/cla/individual/Armitxes.md new file mode 100644 index 00000000000..81375d13072 --- /dev/null +++ b/doc/cla/individual/Armitxes.md @@ -0,0 +1,11 @@ +Germany, 2023-02-15 + +I hereby agree to the terms of the Odoo Individual Contributor License +Agreement v1.0. + +I declare that I am authorized and able to make this agreement and sign this +declaration. + +Signed, + +Jan Brodersen janbrodersen@armitxes.net https://github.com/Armitxes \ No newline at end of file