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(VisitorsList): use separate stomp instance.

Hristo Terezov92a4750d0eb9
diff --git a/react/features/visitors/VisitorsListWebsocketClient.ts b/react/features/visitors/VisitorsListWebsocketClient.ts
new file mode 100644
index 0000000000..c510909efe
--- /dev/null
+++ b/react/features/visitors/VisitorsListWebsocketClient.ts
@@ -0,0 +1,127 @@
+import { Client } from '@stomp/stompjs';
+
+import logger from './logger';
+import { WebsocketClient } from './websocket-client';
+
+/**
+ * Websocket client impl, used for visitors list.
+ * Uses STOMP for authenticating (https://stomp.github.io/).
+ */
+export class VisitorsListWebsocketClient extends WebsocketClient {
+ private static client: VisitorsListWebsocketClient;
+
+ /**
+ * Creates a new instance of the VisitorsListWebsocketClient.
+ *
+ * @static
+ * @returns {VisitorsListWebsocketClient}
+ */
+ static override getInstance(): VisitorsListWebsocketClient {
+ if (!this.client) {
+ this.client = new VisitorsListWebsocketClient();
+ }
+
+ return this.client;
+ }
+
+ /**
+ * Connects to the visitors list with initial queue subscription, then switches to topic deltas.
+ *
+ * @param {string} queueServiceURL - The service URL to use.
+ * @param {string} queueEndpoint - The queue endpoint for initial list.
+ * @param {string} topicEndpoint - The topic endpoint for deltas.
+ * @param {Function} initialCallback - Callback executed with initial visitors list.
+ * @param {Function} deltaCallback - Callback executed with delta updates.
+ * @param {string} token - The token to be used for authorization.
+ * @param {Function?} connectCallback - Callback executed when connected.
+ * @returns {void}
+ */
+ connectVisitorsList(queueServiceURL: string,
+ queueEndpoint: string,
+ topicEndpoint: string,
+ initialCallback: (visitors: Array<{ n: string; r: string; }>) => void,
+ deltaCallback: (updates: Array<{ n: string; r: string; s: string; }>) => void,
+ token: string | undefined,
+ connectCallback?: () => void) {
+ this.stompClient = new Client({
+ brokerURL: queueServiceURL,
+ forceBinaryWSFrames: true,
+ appendMissingNULLonIncoming: true
+ });
+
+ const errorConnecting = (error: any) => {
+ if (this.retriesCount > 3) {
+ this.stompClient?.deactivate();
+ this.stompClient = undefined;
+
+ return;
+ }
+
+ this.retriesCount++;
+
+ logger.error(`Error connecting to ${queueServiceURL} ${JSON.stringify(error)}`);
+ };
+
+ this.stompClient.onWebSocketError = errorConnecting;
+
+ this.stompClient.onStompError = frame => {
+ logger.error('STOMP error received', frame);
+ errorConnecting(frame.headers.message);
+ };
+
+ if (token) {
+ this.stompClient.connectHeaders = {
+ Authorization: `Bearer ${token}`
+ };
+ }
+
+ this.stompClient.onConnect = () => {
+ if (!this.stompClient) {
+ return;
+ }
+
+ logger.debug('Connected to visitors list websocket');
+ connectCallback?.();
+
+ let initialReceived = false;
+ const cachedDeltas: Array<{ n: string; r: string; s: string; }> = [];
+
+ // Subscribe first for deltas so we don't miss any while waiting for the initial list
+ this.stompClient.subscribe(topicEndpoint, deltaMessage => {
+ try {
+ const updates: Array<{ n: string; r: string; s: string; }> = JSON.parse(deltaMessage.body);
+
+ if (!initialReceived) {
+ cachedDeltas.push(...updates);
+ } else {
+ deltaCallback(updates);
+ }
+ } catch (e) {
+ logger.error(`Error parsing visitors delta response: ${deltaMessage}`, e);
+ }
+ });
+
+ // Subscribe for the initial list after topic subscription is active
+ const queueSubscription = this.stompClient.subscribe(queueEndpoint, message => {
+ try {
+ const visitors: Array<{ n: string; r: string; }> = JSON.parse(message.body);
+
+ logger.debug(`Received initial visitors list with ${visitors.length} visitors`);
+ initialReceived = true;
+ initialCallback(visitors);
+
+ queueSubscription.unsubscribe();
+
+ if (cachedDeltas.length) {
+ deltaCallback(cachedDeltas);
+ cachedDeltas.length = 0;
+ }
+ } catch (e) {
+ logger.error(`Error parsing initial visitors response: ${message}`, e);
+ }
+ });
+ };
+
+ this.stompClient.activate();
+ }
+}
diff --git a/react/features/visitors/middleware.ts b/react/features/visitors/middleware.ts
index 5bd23a7745..b72e15c749 100644
--- a/react/features/visitors/middleware.ts
+++ b/react/features/visitors/middleware.ts
@@ -36,6 +36,7 @@ import { INotificationProps } from '../notifications/types';
import { open as openParticipantsPane } from '../participants-pane/actions';
import { joinConference } from '../prejoin/actions';
+import { VisitorsListWebsocketClient } from './VisitorsListWebsocketClient';
import { SUBSCRIBE_VISITORS_LIST, UPDATE_VISITORS_IN_QUEUE_COUNT } from './actionTypes';
import {
approveRequest,
@@ -139,10 +140,11 @@ MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
}
case CONFERENCE_WILL_LEAVE: {
WebsocketClient.getInstance().disconnect();
+ VisitorsListWebsocketClient.getInstance().disconnect();
break;
}
case SUBSCRIBE_VISITORS_LIST: {
- if (isVisitorsListEnabled(getState()) && !WebsocketClient.getInstance().isActive()) {
+ if (isVisitorsListEnabled(getState()) && !VisitorsListWebsocketClient.getInstance().isActive()) {
_subscribeVisitorsList(getState, dispatch);
}
break;
@@ -326,6 +328,14 @@ function _subscribeQueueStats(stateful: IStateful, dispatch: IStore['dispatch'])
toState(stateful)['features/base/jwt'].jwt);
}
+/**
+ * Subscribes to the visitors list via WebSocket for real-time updates. This function establishes a WebSocket
+ * connection to track visitors in a conference.
+ *
+ * @param {IStore.getState} getState - Function to retrieve the current Redux state.
+ * @param {IStore.dispatch} dispatch - Function to dispatch Redux actions.
+ * @returns {void}
+ */
function _subscribeVisitorsList(getState: IStore['getState'], dispatch: IStore['dispatch']) {
const state = getState();
const { visitors: visitorsConfig } = state['features/base/config'];
@@ -349,8 +359,8 @@ function _subscribeVisitorsList(getState: IStore['getState'], dispatch: IStore['
logger.debug('Starting visitors list subscription');
- WebsocketClient.getInstance()
- .connectVisitorsListWithInitial(
+ VisitorsListWebsocketClient.getInstance()
+ .connectVisitorsList(
`wss://${visitorsConfig.queueService}/visitors-list/websocket`,
queueEndpoint,
topicEndpoint,
diff --git a/react/features/visitors/websocket-client.ts b/react/features/visitors/websocket-client.ts
index 64344bac8b..a7d9857ea2 100644
--- a/react/features/visitors/websocket-client.ts
+++ b/react/features/visitors/websocket-client.ts
@@ -20,11 +20,11 @@ export interface VisitorResponse extends QueueServiceResponse {
* Uses STOMP for authenticating (https://stomp.github.io/).
*/
export class WebsocketClient {
- private stompClient: Client | undefined;
+ protected stompClient: Client | undefined;
private static instance: WebsocketClient;
- private retriesCount = 0;
+ protected retriesCount = 0;
private _connectCount = 0;
@@ -147,96 +147,4 @@ export class WebsocketClient {
get connectCount(): number {
return this._connectCount;
}
-
- /**
- * Connects to the visitors list with initial queue subscription, then switches to topic deltas.
- *
- * @param {string} queueServiceURL - The service URL to use.
- * @param {string} queueEndpoint - The queue endpoint for initial list.
- * @param {string} topicEndpoint - The topic endpoint for deltas.
- * @param {Function} initialCallback - Callback executed with initial visitors list.
- * @param {Function} deltaCallback - Callback executed with delta updates.
- * @param {string} token - The token to be used for authorization.
- * @param {Function?} connectCallback - Callback executed when connected.
- * @returns {void}
- */
- connectVisitorsListWithInitial(queueServiceURL: string,
- queueEndpoint: string,
- topicEndpoint: string,
- initialCallback: (visitors: Array<{ n: string; r: string; }>) => void,
- deltaCallback: (updates: Array<{ n: string; r: string; s: string; }>) => void,
- token: string | undefined,
- connectCallback?: () => void) {
- this.stompClient = new Client({
- brokerURL: queueServiceURL,
- forceBinaryWSFrames: true,
- appendMissingNULLonIncoming: true
- });
-
- const errorConnecting = (error: any) => {
- logger.error(`Error connecting to ${queueServiceURL} ${JSON.stringify(error)}`);
- };
-
- this.stompClient.onWebSocketError = errorConnecting;
-
- this.stompClient.onStompError = frame => {
- logger.error('STOMP error received', frame);
- errorConnecting(frame.headers.message);
- };
-
- if (token) {
- this.stompClient.connectHeaders = {
- Authorization: `Bearer ${token}`
- };
- }
-
- this.stompClient.onConnect = () => {
- if (!this.stompClient) {
- return;
- }
-
- logger.debug('Connected to visitors list websocket');
- connectCallback?.();
-
- let initialReceived = false;
- const cachedDeltas: Array<{ n: string; r: string; s: string; }> = [];
-
- // Subscribe first for deltas so we don't miss any while waiting for the initial list
- this.stompClient.subscribe(topicEndpoint, deltaMessage => {
- try {
- const updates: Array<{ n: string; r: string; s: string; }> = JSON.parse(deltaMessage.body);
-
- if (!initialReceived) {
- cachedDeltas.push(...updates);
- } else {
- deltaCallback(updates);
- }
- } catch (e) {
- logger.error(`Error parsing visitors delta response: ${deltaMessage}`, e);
- }
- });
-
- // Subscribe for the initial list after topic subscription is active
- const queueSubscription = this.stompClient.subscribe(queueEndpoint, message => {
- try {
- const visitors: Array<{ n: string; r: string; }> = JSON.parse(message.body);
-
- logger.debug(`Received initial visitors list with ${visitors.length} visitors`);
- initialReceived = true;
- initialCallback(visitors);
-
- queueSubscription.unsubscribe();
-
- if (cachedDeltas.length) {
- deltaCallback(cachedDeltas);
- cachedDeltas.length = 0;
- }
- } catch (e) {
- logger.error(`Error parsing initial visitors response: ${message}`, e);
- }
- });
- };
-
- this.stompClient.activate();
- }
}