Strophe.js
    Preparing search index...

    Helper class that handles WebSocket Connections

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

    Hierarchy (View Summary)

    Implements

    Index
    _conn: default

    The Connection that owns this transport.

    _messageHandler: (message: MessageEvent) => void
    socket: WebsocketLike | WebSocket
    strip: string

    The wrapper element name whose children Connection unwraps before dispatch. BOSH overloads it as a boolean toggle, hence the union.

    • Private function to close the WebSocket.

      Closes the socket if it is still open and deletes it

      Returns void

    • Private function called by Connection.connect

      Creates a WebSocket for a connection and assigns Callbacks to it. Does nothing if there already is a WebSocket.

      Returns void

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

      Parameters

      • bodyWrap: Element

        The received stanza.

      Returns number | void

    • Private function called by Connection.disconnect Disconnects and sends a last stanza if one is given

      Parameters

      • Optionalpres: Element | Builder

        This stanza will be sent before disconnecting.

      Returns void

    • Private function to handle websockets closing.

      Parameters

      • Optionale: CloseEvent

      Returns void

    • Private function to handle websockets errors.

      Parameters

      • error: Event

        The websocket error.

      Returns void

    • 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

      • message: MessageEvent

      Returns void

    • 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

      • message: MessageEvent

        The websocket message event

      Returns void

    • Called by _onInitialMessage in order to replace itself with the general message handler. This method is overridden by WorkerWebsocket, which manages a websocket connection via a service worker and doesn't have direct access to the socket.

      Returns void

    • Reset the connection.

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

      Returns void

    • 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

      • stanza: string

      Returns string