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: Reconnects on shard changed when enableForcedReload is not set.

damenchoace5b70d065b
diff --git a/react/features/app/actions.native.ts b/react/features/app/actions.native.ts
index 7297c262ec..4c303a4d84 100644
--- a/react/features/app/actions.native.ts
+++ b/react/features/app/actions.native.ts
@@ -6,6 +6,7 @@ import {
setConfig,
storeConfig
} from '../base/config/actions';
+import { buildConfigURL } from '../base/config/functions.any';
import {
createFakeConfig,
restoreConfig
@@ -15,10 +16,7 @@ import { JITSI_CONNECTION_URL_KEY } from '../base/connection/constants';
import { loadConfig } from '../base/lib-jitsi-meet/functions.native';
import { createDesiredLocalTracks } from '../base/tracks/actions.native';
import isInsecureRoomName from '../base/util/isInsecureRoomName';
-import { parseURLParams } from '../base/util/parseURLParams';
import {
- appendURLParam,
- getNormalizedRoomName,
parseURIString,
toURLString
} from '../base/util/uri';
@@ -107,14 +105,7 @@ export function appNavigate(uri?: string, options: IReloadNowOptions = {}) {
protocol !== 'http:' && protocol !== 'https:' && (protocol = 'https:');
const baseURL = `${protocol}//${host}${contextRoot || '/'}`;
- let url = `${baseURL}config.js`;
-
- // XXX In order to support multiple shards, tell the room to the deployment.
- room && (url = appendURLParam(url, 'room', getNormalizedRoomName(room) ?? ''));
-
- const { release } = parseURLParams(location, true, 'search');
-
- release && (url = appendURLParam(url, 'release', release));
+ const url = buildConfigURL(locationURL, room);
let config;
diff --git a/react/features/app/actions.web.ts b/react/features/app/actions.web.ts
index e171da4357..eea092ecb4 100644
--- a/react/features/app/actions.web.ts
+++ b/react/features/app/actions.web.ts
@@ -6,7 +6,6 @@ import {
setConfig
} from '../base/config/actions';
import { setLocationURL } from '../base/connection/actions.web';
-import { loadConfig } from '../base/lib-jitsi-meet/functions.web';
import { isEmbedded } from '../base/util/embedUtils';
import { parseURIString } from '../base/util/uri';
import { isVpaasMeeting } from '../jaas/functions';
@@ -70,11 +69,8 @@ export function appNavigate(uri?: string) {
dispatch(clearNotifications());
dispatch(configWillLoad(locationURL));
-
- const config = await loadConfig();
-
dispatch(setLocationURL(locationURL));
- dispatch(setConfig(config));
+ dispatch(setConfig(window.config));
dispatch(setRoom(room));
};
}
diff --git a/react/features/base/conference/middleware.any.ts b/react/features/base/conference/middleware.any.ts
index bcd7342395..70d5a0fe5d 100644
--- a/react/features/base/conference/middleware.any.ts
+++ b/react/features/base/conference/middleware.any.ts
@@ -26,11 +26,13 @@ import { stopLocalVideoRecording } from '../../recording/actions.any';
import LocalRecordingManager from '../../recording/components/Recording/LocalRecordingManager';
import { AudioMixerEffect } from '../../stream-effects/audio-mixer/AudioMixerEffect';
import { iAmVisitor } from '../../visitors/functions';
-import { overwriteConfig } from '../config/actions';
+import { configWillLoad, overwriteConfig, setConfig } from '../config/actions';
+import { buildConfigURL } from '../config/functions.any';
import { CONNECTION_ESTABLISHED, CONNECTION_FAILED, CONNECTION_WILL_CONNECT } from '../connection/actionTypes';
import { connect, connectionDisconnected, disconnect, setPreferVisitor } from '../connection/actions';
import { validateJwt } from '../jwt/functions';
import { JitsiConferenceErrors, JitsiConferenceEvents, JitsiConnectionErrors } from '../lib-jitsi-meet';
+import { loadConfig } from '../lib-jitsi-meet/functions';
import { MEDIA_TYPE } from '../media/constants';
import { PARTICIPANT_UPDATED, PIN_PARTICIPANT } from '../participants/actionTypes';
import { PARTICIPANT_ROLE } from '../participants/constants';
@@ -310,6 +312,31 @@ function _conferenceFailed({ dispatch, getState }: IStore, next: Function, actio
|| error?.name === JitsiConnectionErrors.SHARD_CHANGED_ERROR)) {
dispatch(conferenceWillLeave(conference));
dispatch(reloadNow());
+ } else if (!enableForcedReload && error?.name === JitsiConnectionErrors.SHARD_CHANGED_ERROR) {
+ // we need to reconnect, but make sure we update config before that
+ const { locationURL } = getState()['features/base/connection'];
+
+ if (!locationURL) {
+ logger.error('No locationURL!');
+
+ return result;
+ }
+
+ dispatch(disconnect());
+
+ dispatch(configWillLoad(locationURL));
+
+ const { room } = getState()['features/base/conference'];
+ const url = buildConfigURL(locationURL, room);
+
+ loadConfig(url).then(config => {
+ dispatch(setConfig(config));
+
+ dispatch(connect());
+ }).catch(() => {
+ // in case of an error we continue connecting reusing window.config
+ dispatch(connect());
+ });
}
return result;
diff --git a/react/features/base/config/functions.any.ts b/react/features/base/config/functions.any.ts
index 9fed40943b..bad2ac7c59 100644
--- a/react/features/base/config/functions.any.ts
+++ b/react/features/base/config/functions.any.ts
@@ -10,6 +10,11 @@ import { browser } from '../lib-jitsi-meet';
import { getLocalParticipant } from '../participants/functions';
import { isEmbedded } from '../util/embedUtils';
import { parseURLParams } from '../util/parseURLParams';
+import {
+ appendURLParam,
+ getNormalizedRoomName,
+ parseURIString
+} from '../util/uri';
import { IConfig } from './configType';
import CONFIG_WHITELIST from './configWhitelist';
@@ -51,6 +56,33 @@ export function createFakeConfig(baseURL: string) {
};
}
+/**
+ * Builds the config.js URL for a given location and optional room name.
+ * Extracted to avoid duplication between app navigation (native) and shard-change reconnect (web).
+ *
+ * @param {URL | { href: string }} locationURL - The location URL.
+ * @param {string | null | undefined} room - Optional room name to append as a query param.
+ * @returns {string} The full config.js URL with room and release params appended as needed.
+ */
+export function buildConfigURL(locationURL: URL, room?: string | null): string {
+ const { protocol, host, contextRoot } = parseURIString(locationURL.href);
+ const normalizedProtocol = protocol === 'http:' || protocol === 'https:' ? protocol : 'https:';
+ const baseURL = `${normalizedProtocol}//${host}${contextRoot || '/'}`;
+ let url = `${baseURL}config.js`;
+
+ if (room) {
+ url = appendURLParam(url, 'room', getNormalizedRoomName(room) ?? '');
+ }
+
+ const { release } = parseURLParams(locationURL, true, 'search');
+
+ if (release) {
+ url = appendURLParam(url, 'release', release as string);
+ }
+
+ return url;
+}
+
/**
* Selector used to get the meeting region.
*
diff --git a/react/features/base/lib-jitsi-meet/functions.web.ts b/react/features/base/lib-jitsi-meet/functions.web.ts
index b661299dc5..23d663ad13 100644
--- a/react/features/base/lib-jitsi-meet/functions.web.ts
+++ b/react/features/base/lib-jitsi-meet/functions.web.ts
@@ -1,14 +1,99 @@
+import { safeJsonParse } from '@jitsi/js-utils/json';
+
+import { IConfig } from '../config/configType';
+
+import logger from './logger';
+
export * from './functions.any';
+const WORKER_SCRIPT = `
+self.onmessage = function(e) {
+ const configText = e.data;
+ try {
+ const configObj = eval(
+ '(function(){\\n'
+ + configText
+ + '\\n; return (typeof config !== "undefined" ? config : globalThis.config); })()'
+ );
+
+ if (configObj == void 0) {
+ self.postMessage({ error: 'config is undefined after eval()' });
+ return;
+ }
+
+ if (typeof configObj !== 'object') {
+ self.postMessage({ error: 'config is not an object' });
+ return;
+ }
+
+ self.postMessage({ result: JSON.stringify(configObj) });
+ } catch (err) {
+ self.postMessage({ error: err?.message ?? String(err) });
+ }
+};
+`;
+
+/**
+ * Parses config.js text content inside a Web Worker for isolation.
+ *
+ * @param {string} configText - The raw config.js source text.
+ * @returns {Promise<Object>}
+ */
+function parseConfigInWorker(configText: string): Promise<Object> {
+ return new Promise((resolve, reject) => {
+ const blob = new Blob([ WORKER_SCRIPT ]);
+ // @ts-ignore -- URL.createObjectURL/revokeObjectURL not typed in this ts-loader context
+ const workerUrl = URL.createObjectURL(blob);
+ const worker = new Worker(workerUrl);
+
+ worker.onmessage = (e: MessageEvent) => {
+ // @ts-ignore
+ URL.revokeObjectURL(workerUrl);
+ worker.terminate();
+
+ if (e.data.error) {
+ reject(new Error(e.data.error));
+ } else {
+ resolve(safeJsonParse(e.data.result));
+ }
+ };
+
+ worker.onerror = (err: ErrorEvent) => {
+ // @ts-ignore
+ URL.revokeObjectURL(workerUrl);
+ worker.terminate();
+ reject(new Error(err.message));
+ };
+
+ worker.postMessage(configText);
+ });
+}
+
/**
- * Loads config.js from a specific remote server.
+ * Loads config.js from a specific URL.
*
- * @param {string} _url - The URL to load.
+ * @param {string} [url] - The URL to load.
* @returns {Promise<IConfig>}
*/
-export async function loadConfig(_url?: string) {
- // Return "the config.js file" from the global scope - that is how the
- // Web app on both the client and the server was implemented before the
- // React Native app was even conceived.
- return window.config;
+export async function loadConfig(url: string): Promise<IConfig> {
+
+ try {
+ const response = await fetch(url);
+
+ if (!response.ok) {
+ return Promise.reject(
+ new Error(`Failed to fetch config: ${response.status} ${response.statusText}`));
+ }
+
+ const configText = await response.text();
+ const config = await parseConfigInWorker(configText);
+
+ logger.info(`Config loaded from ${url}`);
+
+ return Promise.resolve(config);
+ } catch (err) {
+ logger.error(`Failed to load config from ${url}`, err);
+
+ return Promise.reject(err);
+ }
}