From 3bb7df9eec0e451302c5c81353e12a761f632abd Mon Sep 17 00:00:00 2001 From: Florent Date: Tue, 25 Jun 2024 16:35:35 +0200 Subject: [PATCH] fix(prober): return not supported if browser API take too long --- .../api/probeMediaConfiguration.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/experimental/tools/mediaCapabilitiesProber/api/probeMediaConfiguration.ts b/src/experimental/tools/mediaCapabilitiesProber/api/probeMediaConfiguration.ts index 614aff8f48..37bffbd243 100644 --- a/src/experimental/tools/mediaCapabilitiesProber/api/probeMediaConfiguration.ts +++ b/src/experimental/tools/mediaCapabilitiesProber/api/probeMediaConfiguration.ts @@ -38,6 +38,11 @@ export interface IProbedMediaConfiguration { result?: IResultsFromAPI | undefined; }>; } +/** + * Value after which we consider the browser API call to have fail it is still hanging. + * We have noticed that some devices hangs indefinitly on `navigator.requestMediaKeySystemAccess`. + */ +const BROWSER_API_TIMEOUT_MS = 30000; /** * Probe media capabilities, evaluating capabilities with available browsers @@ -101,7 +106,15 @@ function probeMediaConfiguration( log.debug(error.message); } }); - promises.push(prom); + + const timeoutPromise = new Promise((_resolve, reject) => { + setTimeout(() => { + // API take too long to respond + log.warn(`MediaCapabilitiesProber: API ${browserAPI} take too long to respond`); + reject(); + }, BROWSER_API_TIMEOUT_MS); + }); + promises.push(Promise.race([prom, timeoutPromise])); } }