Constructor
new Websocket(connection)
Create and initialize a Strophe.WebSocket object. Currently only sets the connection Object.
Parameters:
Name | Type | Description |
---|---|---|
connection |
Connection | The Strophe.Connection that will use WebSockets. |
Members
socket
Methods
_abortAllRequests()
Private helper function that makes sure all pending requests are aborted.
(private) _buildStream() → {Builder}
Private helper function to generate the
Returns:
- A Strophe.Builder with a
element.
- Type
- Builder
(private) _checkStreamError(bodyWrap, connectstatus) → {boolean}
Private checks a message for stream:error
Parameters:
Name | Type | Description |
---|---|---|
bodyWrap |
Element | The received stanza. |
connectstatus |
number | The ConnectStatus that will be set on error. |
Returns:
- true if there was a streamerror, false otherwise.
- Type
- boolean
_closeSocket()
Private function to close the WebSocket.
Closes the socket if it is still open and deletes it
_connect()
Private function called by Strophe.Connection.connect
Creates a WebSocket for a connection and assigns Callbacks to it. Does nothing if there already is a WebSocket.
_connect_cb(bodyWrap)
Private function called by Strophe.Connection._connect_cb checks for stream:error
Parameters:
Name | Type | Description |
---|---|---|
bodyWrap |
Element | The received stanza. |
_disconnect(presopt)
Private function called by Strophe.Connection.disconnect Disconnects and sends a last stanza if one is given
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pres |
Element | Builder |
<optional> |
This stanza will be sent before disconnecting. |
_doDisconnect()
Private function to disconnect. Just closes the Socket for WebSockets
_emptyQueue() → {true}
Private function to check if the message queue is empty.
Returns:
- True, because WebSocket messages are send immediately after queueing.
- Type
- true
(private) _handleStreamStart(message)
Private function that checks the opening
Disconnects if there is an error and returns false, true otherwise.
Parameters:
Name | Type | Description |
---|---|---|
message |
Element | Stanza containing the |
_no_auth_received(callback)
Called on stream start/restart when no stream:features has been received.
Parameters:
Name | Type | Description |
---|---|---|
callback |
connectionCallback |
_onClose(eopt)
Private function to handle websockets closing.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
e |
CloseEvent |
<optional> |
_onDisconnectTimeout()
Private timeout handler for handling non-graceful disconnection.
This does nothing for WebSockets
_onError(error)
Private function to handle websockets errors.
Parameters:
Name | Type | Description |
---|---|---|
error |
Object | The websocket error. |
_onIdle()
Private function called by Strophe.Connection._onIdle sends all queued stanzas
_onInitialMessage(message)
Private function that handles the first connection messages.
On receiving an opening stream tag this callback replaces itself with the real message handler. On receiving a stream error the connection is terminated.
Parameters:
Name | Type | Description |
---|---|---|
message |
MessageEvent |
_onMessage(message)
Private function to handle websockets messages.
This function parses each of the messages as if they are full documents. [TODO : We may actually want to use a SAX Push parser].
Since all XMPP traffic starts with <stream:stream version='1.0' xml:lang='en' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='3697395463' from='SERVER'>
The first stanza will always fail to be parsed.
Additionally, the seconds stanza will always be stream:features with the stream NS defined in the previous stanza, so we need to 'force' the inclusion of the NS in this stanza.
Parameters:
Name | Type | Description |
---|---|---|
message |
MessageEvent | The websocket message event |
(private) _onOpen()
Private function to handle websockets connection setup. The opening stream tag is sent here.
_replaceMessageHandler()
Called by _onInitialMessage in order to replace itself with the general message handler. This method is overridden by Strophe.WorkerWebsocket, which manages a websocket connection via a service worker and doesn't have direct access to the socket.
_reset()
Reset the connection.
This function is called by the reset function of the Strophe Connection. Is not needed by WebSockets.
_send()
Private part of the Connection.send function for WebSocket Just flushes the messages that are in the queue
_sendRestart()
Send an xmpp:restart stanza.
_streamWrap(stanza)
PrivateFunction _streamWrap
Private helper function to wrap a stanza in a
Parameters:
Name | Type | Description |
---|---|---|
stanza |
string |