Skip to content

Commit

Permalink
moved some bosh code autside core
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordin committed Dec 10, 2013
1 parent c70e71d commit a3e940b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 42 deletions.
58 changes: 55 additions & 3 deletions src/bosh.js
Expand Up @@ -194,6 +194,17 @@ Strophe.Bosh.prototype = {
return bodyWrap;
},

/** PrivateFunction: _reset
* Reset the connection.
*
* This function is called by the reset function of the Strophe Connection
*/
_reset: function ()
{
this.rid = Math.floor(Math.random() * 4294967295);
this.sid = null;
},

/** PrivateFunction: _connect
* _Private_ function that initializes the BOSH connection.
*
Expand Down Expand Up @@ -232,6 +243,50 @@ Strophe.Bosh.prototype = {
this._throttledRequestHandler();
},

/** PrivateFunction: _attach
* Attach to an already created and authenticated BOSH session.
*
* This function is provided to allow Strophe to attach to BOSH
* sessions which have been created externally, perhaps by a Web
* application. This is often used to support auto-login type features
* without putting user credentials into the page.
*
* Parameters:
* (String) jid - The full JID that is bound by the session.
* (String) sid - The SID of the BOSH session.
* (String) rid - The current RID of the BOSH session. This RID
* will be used by the next request.
* (Function) callback The connect callback function.
* (Integer) wait - The optional HTTPBIND wait value. This is the
* time the server will wait before returning an empty result for
* a request. The default setting of 60 seconds is recommended.
* Other settings will require tweaks to the Strophe.TIMEOUT value.
* (Integer) hold - The optional HTTPBIND hold value. This is the
* number of connections the server will hold at one time. This
* should almost always be set to 1 (the default).
* (Integer) wind - The optional HTTBIND window value. This is the
* allowed range of request ids that are valid. The default is 5.
*/
_attach: function (jid, sid, rid, callback, wait, hold, wind)
{
this._conn.jid = jid;
this.sid = sid;
this.rid = rid;

this._conn.connect_callback = callback;

this._conn.domain = Strophe.getDomainFromJid(this._conn.jid);

this._conn.authenticated = true;
this._conn.connected = true;

this.wait = wait || this.wait;
this.hold = hold || this.hold;
this.window = wind || this.window;

this._conn._changeConnectStatus(Strophe.Status.ATTACHED, null);
},

/** PrivateFunction: _connect_cb
* _Private_ handler for initial connection request.
*
Expand Down Expand Up @@ -265,9 +320,6 @@ Strophe.Bosh.prototype = {
if (!this.sid) {
this.sid = bodyWrap.getAttribute("sid");
}
if (!this.stream_id) {
this.stream_id = bodyWrap.getAttribute("authid");
}
var wind = bodyWrap.getAttribute('requests');
if (wind) { this.window = parseInt(wind, 10); }
var hold = bodyWrap.getAttribute('hold');
Expand Down
42 changes: 3 additions & 39 deletions src/core.js
Expand Up @@ -1499,7 +1499,7 @@ Strophe.TimedHandler.prototype = {
*
* If you want to do this with a WebSocket connection you will still have to
* prefix the path with "ws" or "wss" to tell Strophe to use WebSockets, so
* to connect to "wss://HOSTNAME/xmpp-websocket", you would call
* to connect to "wss://HOSTNAME/xmpp-websocket", you would call
*
* > var conn = new Strophe.Connection("wss/xmpp-websocket");
*
Expand Down Expand Up @@ -1607,9 +1607,7 @@ Strophe.Connection.prototype = {
*/
reset: function ()
{
this.rid = Math.floor(Math.random() * 4294967295);

this.sid = null;
this._proto._reset();

// SASL
this.do_session = false;
Expand Down Expand Up @@ -1777,26 +1775,7 @@ Strophe.Connection.prototype = {
*/
attach: function (jid, sid, rid, callback, wait, hold, wind)
{
this.jid = jid;
this.sid = sid;
this.rid = rid;

this._proto.jid = jid;
this._proto.sid = sid;
this._proto.rid = rid;

this.connect_callback = callback;

this.domain = Strophe.getDomainFromJid(this.jid);

this.authenticated = true;
this.connected = true;

this.wait = wait || this.wait;
this.hold = hold || this.hold;
this.window = wind || this.window;

this._changeConnectStatus(Strophe.Status.ATTACHED, null);
this._proto.attach(jid, sid, rid, callback, wait, hold, wind);
},

/** Function: xmlInput
Expand Down Expand Up @@ -2397,21 +2376,6 @@ Strophe.Connection.prototype = {
this._authentication.sasl_digest_md5 = false;
this._authentication.sasl_anonymous = false;

// check to make sure we don't overwrite these if _connect_cb is
// called multiple times in the case of missing stream:features
if (!this.sid) {
this.sid = bodyWrap.getAttribute("sid");
}
if (!this.stream_id) {
this.stream_id = bodyWrap.getAttribute("authid");
}
var wind = bodyWrap.getAttribute('requests');
if (wind) { this.window = parseInt(wind, 10); }
var hold = bodyWrap.getAttribute('hold');
if (hold) { this.hold = parseInt(hold, 10); }
var wait = bodyWrap.getAttribute('wait');
if (wait) { this.wait = parseInt(wait, 10); }

this._authentication.legacy_auth = false;

// Check for the stream:features tag
Expand Down
11 changes: 11 additions & 0 deletions src/websocket.js
Expand Up @@ -119,6 +119,17 @@ Strophe.Websocket.prototype = {
return true;
},

/** PrivateFunction: _reset
* Reset the connection.
*
* This function is called by the reset function of the Strophe Connection.
* Is not needed by WebSockets.
*/
_reset: function ()
{
return;
},

/** PrivateFunction: _connect
* _Private_ function called by Strophe.Connection.connect
*
Expand Down

0 comments on commit a3e940b

Please sign in to comment.