Strophe.js
    Preparing search index...

    Interface ConnectionOptions

    interface ConnectionOptions {
        contentType?: string;
        cookies?: Cookies;
        customHeaders?: string[];
        enableStreamManagement?: boolean;
        explicitResourceBinding?: boolean;
        keepalive?: boolean;
        mechanisms?: (new (...args: any[]) => default)[];
        protocol?: "ws" | "wss" | "component";
        streamManagement?: StreamManagementOptions;
        sync?: boolean;
        withCredentials?: boolean;
        worker?: string;
    }
    Index
    contentType?: string

    Used to change the default Content-Type, which is "text/xml; charset=utf-8". Can be useful to reduce the amount of CORS preflight requests that are sent to the server.

    cookies?: Cookies

    Allows you to pass in cookies that will be included in HTTP requests. Relevant to both the BOSH and Websocket transports.

    The passed in value must be a map of cookie names and string values.

    { "myCookie": { "value": "1234", "domain": ".example.org", "path": "/", "expires": expirationDate } }

    Note that cookies can't be set in this way for domains other than the one that's hosting Strophe (i.e. cross-domain). Those cookies need to be set under those domains, for example they can be set server-side by making a XHR call to that domain to ask it to set any necessary cookies.

    customHeaders?: string[]

    Used to provide custom HTTP headers to be included in the BOSH HTTP requests.

    enableStreamManagement?: boolean

    If enableStreamManagement is set to true, Strophe negotiates XEP-0198 Stream Management on websocket connections.

    Defaults to false. Not available over BOSH. In combination with the worker option, the SM session lives inside the shared worker (which sees every tab's traffic) and the connection only mirrors its state.

    explicitResourceBinding?: boolean

    If explicitResourceBinding is set to true, then the XMPP client needs to explicitly call Connection.bind once the XMPP server has advertised the urn:ietf:propertys:xml:ns:xmpp-bind feature.

    Making this step explicit allows client authors to first finish other stream related tasks, such as setting up an XEP-0198 Stream Management session, before binding the JID resource for this session.

    keepalive?: boolean

    Used to instruct Strophe to maintain the current BOSH session across interruptions such as webpage reloads.

    It will do this by caching the sessions tokens in sessionStorage, and when "restore" is called it will check whether there are cached tokens with which it can resume an existing session.

    mechanisms?: (new (...args: any[]) => default)[]

    Allows you to specify the SASL authentication mechanisms that this instance of Connection (and therefore your XMPP client) will support.

    The value must be an array of objects with SASLMechanism prototypes.

    If nothing is specified, then the following mechanisms (and their priorities) are registered:

    Mechanism       Priority
    ------------------------
    SCRAM-SHA-512   72
    SCRAM-SHA-384   71
    SCRAM-SHA-256   70
    SCRAM-SHA-1     60
    PLAIN           50
    OAUTHBEARER     40
    X-OAUTH2        30
    ANONYMOUS       20
    EXTERNAL        10
    
    protocol?: "ws" | "wss" | "component"

    Note: This option is only relevant to Websocket connections, and not BOSH

    If you want to connect to the current host with a WebSocket connection you can tell Strophe to use WebSockets through the "protocol" option. Valid values are ws for WebSocket and wss for Secure WebSocket. So to connect to "wss://CURRENT_HOSTNAME/xmpp-websocket" you would call

    const conn = new Strophe.Connection(
        "/xmpp-websocket/",
        {protocol: "wss"}
    );
    

    Note that relative URLs NOT starting with a "/" will also include the path of the current site.

    Also because downgrading security is not permitted by browsers, when using relative URLs both BOSH and WebSocket connections will use their secure variants if the current connection to the site is also secure (https).

    The 'component' value selects the Node-only XEP-0114 external component transport (see the Component class). It requires a tcp://host:port service URL and is not available in the browser build.

    streamManagement?: StreamManagementOptions

    Fine-tuning options for XEP-0198 Stream Management — see StreamManagementOptions. Only relevant together with ConnectionOptions.enableStreamManagement.

    sync?: boolean

    Used to control whether BOSH HTTP requests will be made synchronously or not. The default behaviour is asynchronous. If you want to make requests synchronous, make "sync" evaluate to true.

    const conn = new Strophe.Connection("/http-bind/", {sync: true});

    You can also toggle this on an already established connection.

    conn.options.sync = true;

    withCredentials?: boolean

    Used to indicate wether cookies should be included in HTTP requests (by default they're not). Set this value to true if you are connecting to a BOSH service and for some reason need to send cookies to it. In order for this to work cross-domain, the server must also enable credentials by setting the Access-Control-Allow-Credentials response header to "true". For most usecases however this setting should be false (which is the default). Additionally, when using Access-Control-Allow-Credentials, the Access-Control-Allow-Origin header can't be set to the wildcard "*", but instead must be restricted to actual domains.

    worker?: string

    Note: This option is only relevant to Websocket connections, and not BOSH

    Set this option to URL from where the shared worker script should be loaded.

    To run the websocket connection inside a shared worker. This allows you to share a single websocket-based connection between multiple Connection instances, for example one per browser tab.

    The script to use is dist/shared-connection-worker.js.