Browse Source

Uses sendBeacon to send presence unavailable on unload.

dev1
damencho 5 years ago
parent
commit
a61941fc9a
1 changed files with 22 additions and 1 deletions
  1. 22
    1
      modules/xmpp/xmpp.js

+ 22
- 1
modules/xmpp/xmpp.js View File

@@ -1,7 +1,7 @@
1 1
 /* global $ */
2 2
 
3 3
 import { getLogger } from 'jitsi-meet-logger';
4
-import { $msg, Strophe } from 'strophe.js';
4
+import { $msg, $pres, Strophe } from 'strophe.js';
5 5
 import 'strophejs-plugin-disco';
6 6
 
7 7
 import RandomUtil from '../util/RandomUtil';
@@ -535,6 +535,27 @@ export default class XMPP extends Listenable {
535 535
                     // comment it in or out depending on whether we want to run with
536 536
                     // it for some time.
537 537
                     this.connection.options.sync = true;
538
+
539
+                    // This is needed in some browsers where sync xhr sending
540
+                    // is disabled by default on unload
541
+                    if (navigator.sendBeacon) {
542
+                        const body = this.connection._proto._buildBody()
543
+                            .attrs({
544
+                                type: 'terminate'
545
+                            });
546
+                        const pres = $pres({
547
+                            xmlns: Strophe.NS.CLIENT,
548
+                            type: 'unavailable'
549
+                        });
550
+
551
+                        body.cnode(pres.tree());
552
+
553
+                        const res = navigator.sendBeacon(
554
+                            `https${this.connection.service}`,
555
+                            Strophe.serialize(body.tree()));
556
+
557
+                        logger.info(`Successfully send unavailable beacon ${res}`);
558
+                    }
538 559
                 }
539 560
             }
540 561
 

Loading…
Cancel
Save