Private helper class that handles BOSH Connections
The Strophe.Bosh class is used internally by Strophe.Connection
to encapsulate BOSH sessions. It is not meant to be used from user's code.
BOSH-Connections will have all stanzas wrapped in a
tag when
passed to xmlInput() or xmlOutput().
To strip this tag, User code can set strip to true:
// You can set strip on the prototype
Strophe.Bosh.prototype.strip = true;
// Or you can set it on the Bosh instance (which is ._proto on the connection instance.
const conn = new Strophe.Connection();
conn._proto.strip = true;
This will enable stripping of the body tag in both
xmlInput and xmlOutput.
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:
Name
Type
Description
jid
string
The full JID that is bound by the session.
sid
string
The SID of the BOSH session.
rid
number
The current RID of the BOSH session. This RID
will be used by the next request.
callback
function
The connect callback function.
wait
number
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.
hold
number
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).
wind
number
The optional HTTBIND window value. This is the
allowed range of request ids that are valid. The default is 5.
Private function that initializes the BOSH connection.
Creates and sends the Request that initializes the BOSH connection.
Parameters:
Name
Type
Description
wait
number
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.
hold
number
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).
True, if there are no Requests queued, False otherwise.
Type
boolean
(private) _hitError(reqStatus)
Private function to handle the error count.
Requests are resent automatically until their error count reaches
5. Each time an error is encountered, this function is called to
increment the count and disconnect if the count is too high.
Private handler for Strophe.Request state changes.
This function is called when the XMLHttpRequest readyState changes.
It contains a lot of error handling logic for the many ways that
requests can fail, and calls the request callback when requests
succeed.
Private function to get a stanza out of a request.
Tries to extract a stanza out of a Request Object.
When this fails the current connection will be disconnected.
The full JID that is bound by the session.
This parameter is optional but recommended, specifically in cases
where prebinded BOSH sessions are used where it's important to know
that the right session is being restored.
callback
function
The connect callback function.
wait
number
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.
hold
number
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).
wind
number
The optional HTTBIND window value. This is the
allowed range of request ids that are valid. The default is 5.
Private function to send initial disconnect sequence.
This is the first step in a graceful disconnect. It sends
the BOSH server a terminate body and includes an unavailable
presence if authentication has completed.