Skip to content

Instantly share code, notes, and snippets.

@thepug
Created January 3, 2011 19:47
Show Gist options
  • Save thepug/763846 to your computer and use it in GitHub Desktop.
Save thepug/763846 to your computer and use it in GitHub Desktop.
javascript code example for connecting with http_pre_bind
var PREBIND_URL = "/http-pre-bind";
var BOSH_URL = "/http-bind";
var conn = new Strophe.Connection(PREBIND_URL);
var prebindCallback = function(status) {
var $status = $(status);
var jid = $status.find("jid").text();
var sid = $status.find("body").attr("sid");
var rid = parseInt($status.find("body").attr("rid"), 10)+1;
conn.service = BOSH_URL;
conn.attach(jid, sid, rid, connectCallback);
};
connection_callback = prebindCallback;
//make ajax call to prebind
var prebindreq = "<body rid='"+
conn.rid+
"' to='"+
XMPP.DOMAIN+
"' wait='"+
XMPP.DEFAULT_WAIT+
"' hold='"+
XMPP.DEFAULT_HOLD+"' />";
jQuery.ajax({type:"POST",
processData:false,
url:PREBIND_URL,
data:prebindreq,
error: function(a,b,c) {
console.error("Error with pre-bind.");
},
success:connection_callback});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment