Converse converse.js

Class: Websocket

Websocket(connection)

Helper class that handles WebSocket Connections

The Strophe.WebSocket class is used internally by Strophe.Connection to encapsulate WebSocket sessions. It is not meant to be used from user's code.

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.

Source:

Members

socket

Source:

Methods

_abortAllRequests()

Private helper function that makes sure all pending requests are aborted.

Source:

(private) _buildStream() → {Builder}

Private helper function to generate the start tag for WebSockets

Source:
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.

Source:
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

Source:

_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.

Source:

_connect_cb(bodyWrap)

Private function called by Strophe.Connection._connect_cb checks for stream:error

Parameters:
Name Type Description
bodyWrap Element

The received stanza.

Source:

_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.

Source:

_doDisconnect()

Private function to disconnect. Just closes the Socket for WebSockets

Source:

_emptyQueue() → {true}

Private function to check if the message queue is empty.

Source:
Returns:
  • True, because WebSocket messages are send immediately after queueing.
Type
true

(private) _handleStreamStart(message)

Private function that checks the opening tag for errors.

Disconnects if there is an error and returns false, true otherwise.

Parameters:
Name Type Description
message Element

Stanza containing the tag.

Source:

_no_auth_received(callback)

Called on stream start/restart when no stream:features has been received.

Parameters:
Name Type Description
callback connectionCallback
Source:

_onClose(eopt)

Private function to handle websockets closing.

Parameters:
Name Type Attributes Description
e CloseEvent <optional>
Source:

_onDisconnectTimeout()

Private timeout handler for handling non-graceful disconnection.

This does nothing for WebSockets

Source:

_onError(error)

Private function to handle websockets errors.

Parameters:
Name Type Description
error Object

The websocket error.

Source:

_onIdle()

Private function called by Strophe.Connection._onIdle sends all queued stanzas

Source:

_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
Source:

_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

Source:

(private) _onOpen()

Private function to handle websockets connection setup. The opening stream tag is sent here.

Source:

_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.

Source:

_reset()

Reset the connection.

This function is called by the reset function of the Strophe Connection. Is not needed by WebSockets.

Source:

_send()

Private part of the Connection.send function for WebSocket Just flushes the messages that are in the queue

Source:

_sendRestart()

Send an xmpp:restart stanza.

Source:

_streamWrap(stanza)

PrivateFunction _streamWrap Private helper function to wrap a stanza in a tag. This is used so Strophe can process stanzas from WebSockets like BOSH

Parameters:
Name Type Description
stanza string
Source: