|
@@ -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
|
/**
|