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(visitors): avoid lost deltas when subscribing

Hristo Terezov370a88476508
diff --git a/react/features/visitors/websocket-client.ts b/react/features/visitors/websocket-client.ts
index 23db9e05d9..64344bac8b 100644
--- a/react/features/visitors/websocket-client.ts
+++ b/react/features/visitors/websocket-client.ts
@@ -198,27 +198,39 @@ export class WebsocketClient {
logger.debug('Connected to visitors list websocket');
connectCallback?.();
- // First subscribe to queue for initial list
+ 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);
- // Unsubscribe from queue and subscribe to topic for deltas
queueSubscription.unsubscribe();
- this.stompClient?.subscribe(topicEndpoint, deltaMessage => {
- try {
- const updates: Array<{ n: string; r: string; s: string; }> = JSON.parse(deltaMessage.body);
-
- deltaCallback(updates);
-
- } catch (e) {
- logger.error(`Error parsing visitors delta response: ${deltaMessage}`, e);
- }
- });
+ if (cachedDeltas.length) {
+ deltaCallback(cachedDeltas);
+ cachedDeltas.length = 0;
+ }
} catch (e) {
logger.error(`Error parsing initial visitors response: ${message}`, e);
}