Strophe.js
    Preparing search index...

    Helper class that handles a websocket connection inside a shared worker.

    Hierarchy (View Summary)

    Implements

    Index
    _conn: default

    The Connection that owns this transport.

    _messageHandler: (m: MessageEvent) => void
    strip: string

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

    worker: SharedWorker
    • Parameters

      • callback: (
            status: number,
            condition?: string | Element,
            response?: string | Element,
        ) => void

      Returns void

    • Parameters

      • status: number
      • Optionaljid: string
      • Optional_condition: string

      Returns void

    • Report that the connect flow completed (resource bound, or legacy auth/session establishment finished). Sent with or without SM: the worker adopts the bound JID as the shared one, releases tabs parked on the handshake, and starts a fresh SM session itself when this stream's features advertised support.

      Parameters

      • jid: string

        The server-assigned full JID.

      Returns void

    • Called when the worker reports that the shared socket closed or died. Unlike a page-owned websocket this can arrive while this tab believes it is still connecting. The worker owns the socket, and e.g. its connection attempt to the server can fail. The base implementation ignores closes in that state (it only knows real CloseEvents), which would leave this tab stuck in CONNECTING forever, so fail the connection attempt instead: the embedder's reconnect logic takes it from there.

      Parameters

      • Optionale: string | CloseEvent

        The close reason from the worker, or a close event.

      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 the worker when another tab sent a message or presence stanza over the shared connection. Handed to its own overridable hook — never into the inbound pipeline (_dataRecv), where it would hit stanza handlers, SM counting and xmlInput as if it were received traffic.

      Parameters

      • data: string

        The serialized stanza.

      Returns void

    • Liveness probe from the worker. Answered from this message handler — which runs even when the browser throttles this tab's timers — so a merely-backgrounded tab never looks dead to the worker.

      Returns void

    • Called by the worker when this tab is promoted to primary after the previous primary went away. Same socket — no reconnect happens.

      Parameters

      • Optionaljid: string

        The shared connection's JID.

      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

    • Called by the worker to assign this tab's role. A secondary shares the already-established session, so it must not treat inbound frames as its own connection handshake.

      Parameters

      • role: "primary" | "secondary"
      • Optionaljid: string

        The shared connection's JID.

      Returns void

    • Called by the worker when a fresh SM session was established.

      Parameters

      • id: string

        The SM-ID.

      • max: number

        The server's preferred maximum resumption time.

      • boundJid: string

        The JID that was bound when the session was enabled.

      Returns void

    • Called by the worker when resumption failed: the primary falls back to binding a resource on this same stream (the salvaged queue stays in the worker and is re-sent after the next ).

      Returns void

    • Ask the worker to negotiate XEP-0198 for the freshly authenticated stream (§2.3): it sends if it holds resumable state, otherwise it replies with _smNoState and the connection proceeds to bind a resource.

      Returns void

    • Called by the worker when the previous session was resumed. Every tab adopts the originally bound JID; the primary — which drove the connect flow — additionally restores the connection state and emits CONNECTED (the same actions a non-worker connection applies on ).

      Parameters

      • jid: string

        The worker's boundJid.

      • Optionalid: string

        The SM-ID of the resumed session.

      • Optionalmax: number

        The server's preferred maximum resumption time.

      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