Strophe.js
    Preparing search index...

    Class Component

    Helper class that handles XEP-0114 external component connections.

    Like Websocket it is used internally by Connection to encapsulate a session and is not meant to be used from user code. Select it with the protocol: 'component' connection option and a tcp://host:port service URL.

    Implements

    Index
    _conn: default

    The Connection that owns this transport.

    strip: string

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

    • Private checks a received stream error and tears the connection down.

      Parameters

      Returns void

    • Private function called by Connection._connect_cb

      The component protocol has no stream:features to inspect, so there is nothing to check here. Kept for interface parity with the other transports.

      Parameters

      • _bodyWrap: Element

      Returns number | void

    • Private function called by Connection.disconnect Sends an optional last stanza, then the closing stream tag, then tears down the socket.

      Parameters

      • Optionalpres: Element | Builder

        This stanza will be sent before disconnecting.

      Returns void

    • Inspect the server's reply to our handshake. An empty <handshake/> means success and the component is CONNECTED; a <stream:error/> (e.g. <not-authorized/>) means the shared secret was wrong.

      Parameters

      • stanza: Element

        The first stanza received after sending the handshake.

      Returns void

    • Called on stream start/restart when no authentication mechanism is offered. Not reachable on the component path (there is no SASL), but kept for interface parity.

      Parameters

      • Optionalcallback: (this: default) => void

      Returns void

    • Private function called when raw bytes arrive on the socket. Feeds them into the incremental stream parser.

      Parameters

      • chunk: Uint8Array

        The bytes received from the socket.

      Returns void

    • Private function to handle socket errors.

      Parameters

      • error: Error

        The socket error.

      Returns void

    • Private function called by Connection._onIdle Serializes queued stanzas and writes them to the socket, stamping a from attribute under the component's domain when one is absent (the server validates that a component stamps from, per XEP-0114).

      Returns void

    • Private function to handle incoming stanzas once authenticated. Wraps the stanza and routes it through the normal handler machinery, exactly as Websocket#_onMessage does.

      Parameters

      • stanza: Element

        A complete top-level stanza element.

      Returns void

    • Private function to handle a successful TCP connection. Sends the component stream header (XEP-0114 §2).

      Returns void

    • Handle a fatal XML parse error on the inbound stream.

      Parameters

      • error: Error

        The parse error.

      Returns void

    • Route a complete inbound stanza. Before the handshake completes this is the handshake result; afterwards it's ordinary traffic.

      Parameters

      • stanza: Element

        A complete top-level stanza element.

      Returns void

    • Handle the server's opening stream header. Captures the stream id and replies with the SHA-1 handshake (XEP-0114 §3).

      Parameters

      • attrs: Record<string, string>

        The attributes of the server's stream:stream header.

      Returns void

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

      Returns void

    • Compute and send the XEP-0114 handshake digest, hex( SHA1( STREAM_ID + SHARED_SECRET ) ) in lowercase.

      Parameters

      • streamId: string

        The stream id from the server's stream header.

      Returns void

    • Send an xmpp:restart stanza.

      Components never restart their stream, so this only flushes any queued data. Included for interface parity with the other transports.

      Returns void

    • Serialize an element to a string, reusing Strophe's own serializer so output matches the other transports.

      Parameters

      • elem: Element

      Returns string

    • Parse the component service URL into a host and port.

      Accepts tcp://host:port (the recommended plaintext form) and tolerates a bare host:port. The port defaults to 5347, the conventional component listener port.

      Returns { host: string; port: number }

    • Ensure an outgoing stanza carries a from attribute under the component's domain, which XEP-0114 requires the server to validate. An explicit from (e.g. a sub-JID of the component) is left untouched.

      Parameters

      • stanza: Element

        The outgoing stanza element.

      Returns void

    • The opening <stream:stream> header sent to the server. to is the component's own domain, per XEP-0114.

      Returns string

    • A self-closed representation of the stream header, purely for the xmlOutput debug hook (the real header sent on the wire never closes).

      Returns Element

    • Tear the connection down exactly once.

      A single parsed chunk can surface several teardown triggers back to back: a <stream:error/> immediately followed by the closing </stream:stream>, or a socket error and then its close event. Each would otherwise call Connection#_doDisconnect again and fire a second DISCONNECTED. The first call through here wins; later ones are no-ops.

      Parameters

      • status: number

        A Status to report before disconnecting, or null to disconnect without a preceding status change (e.g. a plain stream close).

      • Optionalcondition: string

        The accompanying error condition, if any.

      Returns void