jquery - Disconnect Strophe Connection on Page Unload -


i've written web-based muc client using strophe.js , jquery , i'm trying send unavailable presence room , disconnect user in jquery unload event window. if user navigates away or closes browser tab, should logged out of muc.

i've tested code i'm running in event through logout button have on page, i'm pretty sure stanza correct. think strophe having trouble sending stanza if browser window closing. there workaround here? i've tried onbeforeunload event (i know it's not entirely cross-browser compatible), doesn't seem work either.

any advice appreciated!

thanks, john

ensure switch sync mode, , call flush() before sending disconnect() call. here example:

var client = {   connect: function(spec) {     this.connection = new strophe.connection(spec.url);   },    disconnect: function() {     this.connection.options.sync = true; // switch using synchronous requests since typically called onunload.     this.connection.flush();     this.connection.disconnect();   } } 

then can bind onbeforeunload/onunload. (jquery example)

var client = new client; client.connect(); $(window).unload(function() {   client.disconnect(); }); 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -