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 1603de8f07..56518ed9cd 100644 --- a/ui-ngx/src/app/core/ws/telemetry-websocket.service.ts +++ b/ui-ngx/src/app/core/ws/telemetry-websocket.service.ts @@ -36,6 +36,7 @@ import { UnreadCountSubCmd, UnreadSubCmd, UnsubscribeCmd, + WebsocketCmd, WebsocketDataMsg } from '@app/shared/models/telemetry/telemetry.models'; import { Store } from '@ngrx/store'; @@ -66,6 +67,12 @@ export class TelemetryWebsocketService extends WebsocketService(); + this.subscriberCmdIds.set(subscriber, cmdIds); + } + cmdIds.add(cmdId); } subscriptionCommand.cmdId = cmdId; this.cmdWrapper.cmds.push(subscriptionCommand); @@ -80,11 +87,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); } } @@ -123,6 +133,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; @@ -121,11 +123,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(); } } @@ -209,6 +213,7 @@ export abstract class WebsocketService implements WsServ } ); this.reconnectSubscribers.clear(); + this.processPendingUpdates(); } else { this.publishCommands(); } @@ -284,4 +289,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); + } + } + } + } }