Connect and disconnect XMPP using strophe.js

function connect()
{
var jid = sessionStorage.getItem("jid"), password = sessionStorage.getItem("password");
var BOSH_SERVICE = Chat.BOSH_SERVICE;
var debugginMode = false;
Chat.connect(jid, password, BOSH_SERVICE, debugginMode);
}


function disconnect()
{
sessionStorage.removeItem('user_name');
sessionStorage.removeItem('jid');
sessionStorage.removeItem('password');
Chat.disconnect();
window.location="index.html";
}


var Chat = {
BOSH_SERVICE: 'http://IP:5280/http-bind',
connection: null,
connected: false,
debuggingMode: false,
connect: function (jid, password, BOSH_SERVICE, debugginMode) {
//alert(password);
Chat.BOSH_SERVICE = (BOSH_SERVICE) ? BOSH_SERVICE : Chat.BOSH_SERVICE;
Chat.debuggingMode = (debugginMode) ? debugginMode : true; //set to false after done testing!!
Chat.connection = new Strophe.Connection(Chat.BOSH_SERVICE);
Chat.connection.connect(jid, password, Chat.onConnect);
},
disconnect: function () {
Chat.connection.flush();
Chat.connection.disconnect();
Chat.connected = false;
},
}

Share This:

Leave a Reply

Your email address will not be published. Required fields are marked *