Jelajahi Sumber

Process outgoing queue after reconnecting

Danilo Bargen 7 tahun lalu
induk
melakukan
130a5ca50c
1 mengubah file dengan 11 tambahan dan 3 penghapusan
  1. 11 3
      src/services/webclient.ts

+ 11 - 3
src/services/webclient.ts

@@ -474,7 +474,7 @@ export class WebClientService {
      * For the WebRTC task, this is called when the DataChannel is open.
      * For the relayed data task, this is called once the connection is established.
      */
-    private onDataChannelOpen(resetFields: boolean) {
+    private onConnectionEstablished(resetFields: boolean) {
         // Reset fields if requested
         if (resetFields) {
             this._resetFields();
@@ -506,6 +506,14 @@ export class WebClientService {
 
         // Notify state service about data loading
         this.stateService.updateConnectionBuildupState('loading');
+
+        // Process pending messages
+        if (this.outgoingMessageQueue.length > 0) {
+            this.$log.debug(this.logTag, 'Sending', this.outgoingMessageQueue.length, 'pending messages');
+            for (const _ of this.outgoingMessageQueue.keys()) {
+                this.send(this.outgoingMessageQueue.pop());
+            }
+        }
     }
 
     /**
@@ -527,7 +535,7 @@ export class WebClientService {
                 WebClientService.DC_LABEL,
                 (event: Event) => {
                     this.$log.debug(this.logTag, 'SecureDataChannel open');
-                    this.onDataChannelOpen(resetFields);
+                    this.onConnectionEstablished(resetFields);
                 },
             );
 
@@ -553,7 +561,7 @@ export class WebClientService {
             });
 
             // The communication channel is now open! Fetch initial data
-            this.onDataChannelOpen(resetFields);
+            this.onConnectionEstablished(resetFields);
         }
     }