|
@@ -538,7 +538,11 @@ export default class XMPP extends Listenable {
|
538
|
538
|
|
539
|
539
|
// This is needed in some browsers where sync xhr sending
|
540
|
540
|
// is disabled by default on unload
|
541
|
|
- if (navigator.sendBeacon) {
|
|
541
|
+ if (navigator.sendBeacon && !this.connection.disconnecting
|
|
542
|
+ && this.connection.connected) {
|
|
543
|
+ this.connection._changeConnectStatus(Strophe.Status.DISCONNECTING);
|
|
544
|
+ this.connection.disconnecting = true;
|
|
545
|
+
|
542
|
546
|
const body = this.connection._proto._buildBody()
|
543
|
547
|
.attrs({
|
544
|
548
|
type: 'terminate'
|
|
@@ -551,10 +555,15 @@ export default class XMPP extends Listenable {
|
551
|
555
|
body.cnode(pres.tree());
|
552
|
556
|
|
553
|
557
|
const res = navigator.sendBeacon(
|
554
|
|
- `https${this.connection.service}`,
|
|
558
|
+ `https:${this.connection.service}`,
|
555
|
559
|
Strophe.serialize(body.tree()));
|
556
|
560
|
|
557
|
561
|
logger.info(`Successfully send unavailable beacon ${res}`);
|
|
562
|
+
|
|
563
|
+ this.connection._proto._abortAllRequests();
|
|
564
|
+ this.connection._doDisconnect();
|
|
565
|
+
|
|
566
|
+ return;
|
558
|
567
|
}
|
559
|
568
|
}
|
560
|
569
|
}
|