Browse Source

fix(ChatRoom): send cached presence when XMPP re-connects

dev1
paweldomas 5 years ago
parent
commit
39e7d3b4c8
1 changed files with 22 additions and 0 deletions
  1. 22
    0
      modules/xmpp/ChatRoom.js

+ 22
- 0
modules/xmpp/ChatRoom.js View File

12
 import Statistics from '../statistics/statistics';
12
 import Statistics from '../statistics/statistics';
13
 
13
 
14
 import Moderator from './moderator';
14
 import Moderator from './moderator';
15
+import XmppConnection from './XmppConnection';
15
 
16
 
16
 const logger = getLogger(__filename);
17
 const logger = getLogger(__filename);
17
 
18
 
110
         this.members = {};
111
         this.members = {};
111
         this.presMap = {};
112
         this.presMap = {};
112
         this.presHandlers = {};
113
         this.presHandlers = {};
114
+        this._removeConnListeners = [];
113
         this.joined = false;
115
         this.joined = false;
114
         this.role = null;
116
         this.role = null;
115
         this.focusMucJid = null;
117
         this.focusMucJid = null;
184
 
186
 
185
             preJoin.then(() => {
187
             preJoin.then(() => {
186
                 this.sendPresence(true);
188
                 this.sendPresence(true);
189
+                this._removeConnListeners.push(
190
+                    this.connection.addEventListener(
191
+                        XmppConnection.Events.CONN_STATUS_CHANGED,
192
+                        this.onConnStatusChanged.bind(this))
193
+                );
187
                 resolve();
194
                 resolve();
188
             });
195
             });
189
         });
196
         });
362
         });
369
         });
363
     }
370
     }
364
 
371
 
372
+    /**
373
+     * Handles Xmpp Connection status updates.
374
+     *
375
+     * @param {Strophe.Status} status - The Strophe connection status.
376
+     */
377
+    onConnStatusChanged(status) {
378
+        // Send cached presence when the XMPP connection is re-established.
379
+        if (status === XmppConnection.Status.CONNECTED) {
380
+            this.sendPresence();
381
+        }
382
+    }
383
+
365
     /**
384
     /**
366
      *
385
      *
367
      * @param pres
386
      * @param pres
1459
             const timeout = setTimeout(() => onMucLeft(true), 5000);
1478
             const timeout = setTimeout(() => onMucLeft(true), 5000);
1460
             const eventEmitter = this.eventEmitter;
1479
             const eventEmitter = this.eventEmitter;
1461
 
1480
 
1481
+            this._removeConnListeners.forEach(remove => remove());
1482
+            this._removeConnListeners = [];
1483
+
1462
             /**
1484
             /**
1463
              *
1485
              *
1464
              * @param doReject
1486
              * @param doReject

Loading…
Cancel
Save