Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(dynamic-branding): load custom icons in parallel with a per-icon timeout

Hristo Terezova6bd61bf3922
diff --git a/react/features/dynamic-branding/constants.ts b/react/features/dynamic-branding/constants.ts
new file mode 100644
index 0000000000..4658e6aaf6
--- /dev/null
+++ b/react/features/dynamic-branding/constants.ts
@@ -0,0 +1,5 @@
+/**
+ * Maximum time in milliseconds to wait for a single custom icon SVG to download. The icons are
+ * hosted by the customer, so one slow or unreachable URL must not hold back the others.
+ */
+export const CUSTOM_ICON_FETCH_TIMEOUT = 5000;
diff --git a/react/features/dynamic-branding/functions.any.ts b/react/features/dynamic-branding/functions.any.ts
index 8149720ebe..befbd7b46b 100644
--- a/react/features/dynamic-branding/functions.any.ts
+++ b/react/features/dynamic-branding/functions.any.ts
@@ -2,6 +2,7 @@ import { IReduxState } from '../app/types';
import { IStateful } from '../base/app/types';
import { toState } from '../base/redux/functions';
+import { CUSTOM_ICON_FETCH_TIMEOUT } from './constants';
import { cleanSvg } from './functions';
import logger from './logger';
@@ -65,29 +66,51 @@ export function isDynamicBrandingDataLoaded(state: IReduxState) {
}
/**
- * Fetch SVG XMLs from branding icons urls.
+ * Loads the SVG content of the given branding icons. The icons are requested in parallel and
+ * each request is bounded by {@link CUSTOM_ICON_FETCH_TIMEOUT}, so a slow or dead URL delays
+ * neither the other icons nor the rest of the branding. Icons that fail to load are logged
+ * and left out of the result.
*
- * @param {Object} customIcons - The map of branded icons.
- * @returns {Object}
+ * @param {Record<string, string>} customIcons - Map of icon name to SVG URL.
+ * @returns {Promise<Record<string, string>>} Map of icon name to sanitized SVG XML.
*/
-export const fetchCustomIcons = async (customIcons: Record<string, string>) => {
+export async function fetchCustomIcons(customIcons: Record<string, string>): Promise<Record<string, string>> {
+ const entries = Object.entries(customIcons);
+ const results = await Promise.allSettled(entries.map(entry => fetchCustomIcon(entry[1])));
const localCustomIcons: Record<string, string> = {};
- for (const [ key, url ] of Object.entries(customIcons)) {
- try {
- const response = await fetch(url);
+ results.forEach((result, index) => {
+ const [ key, url ] = entries[index];
- if (response.ok) {
- const svgXml = await response.text();
-
- localCustomIcons[key] = cleanSvg(svgXml);
- } else {
- logger.error(`Failed to fetch ${url}. Status: ${response.status}`);
- }
- } catch (error) {
- logger.error(`Error fetching ${url}:`, error);
+ if (result.status === 'fulfilled') {
+ localCustomIcons[key] = result.value;
+ } else {
+ logger.error(`Error fetching custom icon ${key} from ${url}:`, result.reason);
}
- }
+ });
return localCustomIcons;
-};
+}
+
+/**
+ * Fetches a single icon SVG, giving up after {@link CUSTOM_ICON_FETCH_TIMEOUT}.
+ *
+ * @param {string} url - The URL of the SVG.
+ * @returns {Promise<string>} The sanitized SVG XML.
+ */
+async function fetchCustomIcon(url: string): Promise<string> {
+ const controller = new AbortController();
+ const timeout = setTimeout(() => controller.abort(), CUSTOM_ICON_FETCH_TIMEOUT);
+
+ try {
+ const response = await fetch(url, { signal: controller.signal });
+
+ if (!response.ok) {
+ throw new Error(`Unexpected status ${response.status}`);
+ }
+
+ return cleanSvg(await response.text());
+ } finally {
+ clearTimeout(timeout);
+ }
+}