ソースを参照

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,18 +219,23 @@ export default class XMPP extends Listenable {
219 219
         // Initialize features advertised in disco-info
220 220
         this.initFeaturesList();
221 221
 
222
+        this.connection.addHandler(this._onPrivateMessage.bind(this), null, 'message', null, null);
223
+
222 224
         // Setup a disconnect on unload as a way to facilitate API consumers. It
223 225
         // sounds like they would want that. A problem for them though may be if
224 226
         // they wanted to utilize the connected connection in an unload handler
225 227
         // of their own. However, it should be fairly easy for them to do that
226 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 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
     /**

読み込み中…
キャンセル
保存