浏览代码

fix(xmpp) don't use jquery to add (before)unload handlers

master
Saúl Ibarra Corretgé 3 个月前
父节点
当前提交
d08120875f
共有 1 个文件被更改,包括 9 次插入4 次删除
  1. 9
    4
      modules/xmpp/xmpp.js

+ 9
- 4
modules/xmpp/xmpp.js 查看文件

219
         // Initialize features advertised in disco-info
219
         // Initialize features advertised in disco-info
220
         this.initFeaturesList();
220
         this.initFeaturesList();
221
 
221
 
222
+        this.connection.addHandler(this._onPrivateMessage.bind(this), null, 'message', null, null);
223
+
222
         // Setup a disconnect on unload as a way to facilitate API consumers. It
224
         // Setup a disconnect on unload as a way to facilitate API consumers. It
223
         // sounds like they would want that. A problem for them though may be if
225
         // sounds like they would want that. A problem for them though may be if
224
         // they wanted to utilize the connected connection in an unload handler
226
         // they wanted to utilize the connected connection in an unload handler
225
         // of their own. However, it should be fairly easy for them to do that
227
         // of their own. However, it should be fairly easy for them to do that
226
         // by registering their unload handler before us.
228
         // by registering their unload handler before us.
227
-        $(window).on(`${this.options.disableBeforeUnloadHandlers ? '' : 'beforeunload '}unload`, ev => {
229
+        const events = `${this.options.disableBeforeUnloadHandlers ? '' : 'beforeunload '}unload`;
230
+        const handleDisconnect = ev => {
228
             this.disconnect(ev).catch(() => {
231
             this.disconnect(ev).catch(() => {
229
-                // ignore errors in order to not brake the unload.
232
+                // Ignore errors in order to not break the unload.
230
             });
233
             });
231
-        });
234
+        };
232
 
235
 
233
-        this.connection.addHandler(this._onPrivateMessage.bind(this), null, 'message', null, null);
236
+        for (const event of events.split(' ')) {
237
+            window.addEventListener(event, handleDisconnect);
238
+        }
234
     }
239
     }
235
 
240
 
236
     /**
241
     /**

正在加载...
取消
保存