浏览代码

fix(ChatRoom) make sure EMUC is destroyed

If leaving a room results in a timeout, we wouldn't be cleaning up the EMUC
state, which will prevent us from joining the room again, as it would detect it
as a duplicate.
dev1
Saúl Ibarra Corretgé 3 年前
父节点
当前提交
a856b012c6
共有 1 个文件被更改,包括 12 次插入15 次删除
  1. 12
    15
      modules/xmpp/ChatRoom.js

+ 12
- 15
modules/xmpp/ChatRoom.js 查看文件

@@ -1857,27 +1857,24 @@ export default class ChatRoom extends Listenable {
1857 1857
         this.lobby?.lobbyRoom && promises.push(this.lobby.leave());
1858 1858
 
1859 1859
         promises.push(new Promise((resolve, reject) => {
1860
-            const timeout = setTimeout(() => onMucLeft(true), 5000);
1861
-            const eventEmitter = this.eventEmitter;
1860
+            let timeout = -1;
1862 1861
 
1863
-            this.clean();
1864
-
1865
-            /**
1866
-             *
1867
-             * @param doReject
1868
-             */
1869
-            function onMucLeft(doReject = false) {
1870
-                eventEmitter.removeListener(XMPPEvents.MUC_LEFT, onMucLeft);
1862
+            const onMucLeft = (doReject = false) => {
1863
+                this.eventEmitter.removeListener(XMPPEvents.MUC_LEFT, onMucLeft);
1871 1864
                 clearTimeout(timeout);
1872 1865
                 if (doReject) {
1873
-                    // the timeout expired
1874
-                    reject(new Error('The timeout for the confirmation about '
1875
-                        + 'leaving the room expired.'));
1866
+                    // The timeout expired. Make sure we clean the EMUC state.
1867
+                    this.connection.emuc.doLeave(this.roomjid);
1868
+                    reject(new Error('The timeout for the confirmation about leaving the room expired.'));
1876 1869
                 } else {
1877 1870
                     resolve();
1878 1871
                 }
1879
-            }
1880
-            eventEmitter.on(XMPPEvents.MUC_LEFT, onMucLeft);
1872
+            };
1873
+
1874
+            timeout = setTimeout(() => onMucLeft(true), 5000);
1875
+
1876
+            this.clean();
1877
+            this.eventEmitter.on(XMPPEvents.MUC_LEFT, onMucLeft);
1881 1878
             this.doLeave();
1882 1879
         }));
1883 1880
 

正在加载...
取消
保存