浏览代码

Fix URL for sendBeacon. (#980)

* Fix URL for sendBeacon.

* Performs sendBeacon once or connection.disconnect().
dev1
Дамян Минков 6 年前
父节点
当前提交
3f7613748d
没有帐户链接到提交者的电子邮件
共有 1 个文件被更改,包括 11 次插入2 次删除
  1. 11
    2
      modules/xmpp/xmpp.js

+ 11
- 2
modules/xmpp/xmpp.js 查看文件

@@ -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
             }

正在加载...
取消
保存