Просмотр исходного кода

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 лет назад
Родитель
Сommit
a856b012c6
1 измененных файлов: 12 добавлений и 15 удалений
  1. 12
    15
      modules/xmpp/ChatRoom.js

+ 12
- 15
modules/xmpp/ChatRoom.js Просмотреть файл

1857
         this.lobby?.lobbyRoom && promises.push(this.lobby.leave());
1857
         this.lobby?.lobbyRoom && promises.push(this.lobby.leave());
1858
 
1858
 
1859
         promises.push(new Promise((resolve, reject) => {
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
                 clearTimeout(timeout);
1864
                 clearTimeout(timeout);
1872
                 if (doReject) {
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
                 } else {
1869
                 } else {
1877
                     resolve();
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
             this.doLeave();
1878
             this.doLeave();
1882
         }));
1879
         }));
1883
 
1880
 

Загрузка…
Отмена
Сохранить