diff --git a/ui-ngx/src/app/core/ws/telemetry-websocket.service.ts b/ui-ngx/src/app/core/ws/telemetry-websocket.service.ts index ddf5018a69..bc63938775 100644 --- a/ui-ngx/src/app/core/ws/telemetry-websocket.service.ts +++ b/ui-ngx/src/app/core/ws/telemetry-websocket.service.ts @@ -50,6 +50,7 @@ import { UnreadCountSubCmd, UnreadSubCmd, UnsubscribeCmd, + WebsocketCmd, WebsocketDataMsg } from '@app/shared/models/telemetry/telemetry.models'; import { Store } from '@ngrx/store'; @@ -80,6 +81,12 @@ export class TelemetryWebsocketService extends WebsocketService(); + this.subscriberCmdIds.set(subscriber, cmdIds); + } + cmdIds.add(cmdId); } subscriptionCommand.cmdId = cmdId; this.cmdWrapper.cmds.push(subscriptionCommand); @@ -94,11 +101,14 @@ export class TelemetryWebsocketService extends WebsocketService { if (subscriptionCommand.cmdId && (subscriptionCommand instanceof EntityDataCmd || subscriptionCommand instanceof UnreadSubCmd)) { + this.syncCommandId(subscriptionCommand, subscriber); this.cmdWrapper.cmds.push(subscriptionCommand); } } ); this.publishCommands(); + } else { + this.pendingUpdates.add(subscriber); } } @@ -137,6 +147,13 @@ export class TelemetryWebsocketService extends WebsocketService implements WsServ lastCmdId = 0; subscribersCount = 0; subscribersMap = new Map(); + subscriberCmdIds = new Map>(); reconnectSubscribers = new Set(); + pendingUpdates = new Set(); wsUri: string; @@ -135,11 +137,13 @@ export abstract class WebsocketService implements WsServ } this.lastCmdId = 0; this.subscribersMap.clear(); + this.subscriberCmdIds.clear(); this.subscribersCount = 0; this.cmdWrapper.clear(); if (close) { this.reconnectAttempts = 0; this.lastShownCloseCode = null; + this.pendingUpdates.clear(); this.closeSocket(); } } @@ -223,6 +227,7 @@ export abstract class WebsocketService implements WsServ } ); this.reconnectSubscribers.clear(); + this.processPendingUpdates(); } else { this.publishCommands(); } @@ -298,4 +303,16 @@ export abstract class WebsocketService implements WsServ message, type: notificationType })); } + + private processPendingUpdates() { + if (this.pendingUpdates.size > 0) { + const subscribers = Array.from(this.pendingUpdates); + this.pendingUpdates.clear(); + for (const subscriber of subscribers) { + if (this.subscriberCmdIds.has(subscriber)) { + this.update(subscriber); + } + } + } + } }