Constructor
new Bosh(connection)
Parameters:
Name | Type | Description |
---|---|---|
connection |
Connection | The Connection that will use BOSH. |
Members
_requests :Array.<Request>
Type:
- Array.<Request>
strip
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 Bosh.prototype.strip = true;
// Or you can set it on the Bosh instance (which is
._proto
on the connection instance. const conn = new Connection(); conn._proto.strip = true;
This will enable stripping of the body tag in both xmlInput and xmlOutput.
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
strip |
boolean |
<optional> |
false |
Methods
_abortAllRequests()
Private helper function that makes sure all pending requests are aborted.
_attach(jid, sid, rid, callback, wait, hold, wind)
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) _buildBody() → {Builder}
Private helper function to generate the wrapper for BOSH.
Returns:
- A Builder with a element.
- Type
- Builder
(private) _cacheSession()
Private handler for the beforeunload event. This handler is used to process the Bosh-part of the initial request.
(private) _callProtocolErrorHandlers(req)
Private function to call error handlers registered for HTTP errors.
Parameters:
Name | Type | Description |
---|---|---|
req |
Request | The request that is changing readyState. |
_connect(wait, hold, route)
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). |
route |
string |
_connect_cb(bodyWrap)
Private handler for initial connection request. This handler is used to process the Bosh-part of the initial request.
Parameters:
Name | Type | Description |
---|---|---|
bodyWrap |
Element | The received stanza. |
_disconnect(pres)
Private part of Connection.disconnect for Bosh
Parameters:
Name | Type | Description |
---|---|---|
pres |
Element | Builder | This stanza will be sent before disconnecting. |
_doDisconnect()
Private function to disconnect. Resets the SID and RID.
_emptyQueue() → {boolean}
Private function to check if the Request queue is empty.
Returns:
- 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.
Parameters:
Name | Type | Description |
---|---|---|
reqStatus |
number | The request status. |
_no_auth_received(callback)
Called on stream start/restart when no stream:features has been received and sends a blank poll request.
Parameters:
Name | Type | Description |
---|---|---|
callback |
connectionCallback |
_onDisconnectTimeout()
Private timeout handler for handling non-graceful disconnection. Cancels all remaining Requests and clears the queue.
_onIdle()
Private handler called by Connection._onIdle(). Sends all queued Requests or polls with empty Request if there are none.
(private) _onRequestStateChange(func, req)
Private handler for 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.
Parameters:
Name | Type | Description |
---|---|---|
func |
function | The handler for the request. |
req |
Request | The request that is changing readyState. |
(private) _processRequest(i)
Private function to process a request in the queue.
This function takes requests off the queue and sends them and restarts dead requests.
Parameters:
Name | Type | Description |
---|---|---|
i |
number | The index of the request in the queue. |
(private) _removeRequest(req)
Private function to remove a request from the queue.
Parameters:
Name | Type | Description |
---|---|---|
req |
Request | The request to remove. |
_reqToData(req) → {Element}
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.
Parameters:
Name | Type | Description |
---|---|---|
req |
Request | The Request. |
Returns:
- The stanza that was passed.
- Type
- Element
_reset()
Reset the connection. This function is called by the reset function of the Connection
(private) _restartRequest(i)
Private function to restart a request that is presumed dead.
Parameters:
Name | Type | Description |
---|---|---|
i |
number | The index of the request in the queue. |
_restore(jid, callback, wait, hold, wind)
Attempt to restore a cached BOSH session
Parameters:
Name | Type | Description |
---|---|---|
jid |
string | 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. |
_send()
Private part of the Connection.send function for BOSH Just triggers the RequestHandler to send the messages that are in the queue
_sendRestart()
Send an xmpp:restart stanza.
(private) _sendTerminate(presopt)
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.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pres |
Element | Builder |
<optional> |
(private) _throttledRequestHandler()
Private function to throttle requests to the connection window.
This function makes sure we don't send requests so fast that the request ids overflow the connection window in the case that one request died.
(private, static) _getRequestStatus(req, defopt)
Returns the HTTP status code from a Request
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
req |
Request | The Request instance. |
|
def |
number |
<optional> |
The default value that should be returned if no status value was found. |
(static) getSecondaryTimeoutMultplier() → {number}
Returns:
- Type
- number
(static) getTimeoutMultplier() → {number}
Returns:
- Type
- number
(static) setSecondaryTimeoutMultiplier(m)
Parameters:
Name | Type | Description |
---|---|---|
m |
number |
(static) setTimeoutMultiplier(m)
Parameters:
Name | Type | Description |
---|---|---|
m |
number |