### STOMP Client Constructor Example Source: https://stomp-js.github.io/api-docs/latest/classes/Client A detailed example of the STOMP client constructor in TypeScript. It initializes the client with default no-op callbacks for various STOMP events and sets initial properties like `logRawCommunication`. The `configure` method is called to apply any provided configuration. ```typescript public constructor(conf: StompConfig = {}) { // No op callbacks const noOp = () => {}; this.debug = noOp; this.beforeConnect = noOp; this.onConnect = noOp; this.onDisconnect = noOp; this.onUnhandledMessage = noOp; this.onUnhandledReceipt = noOp; this.onUnhandledFrame = noOp; this.onHeartbeatReceived = noOp; this.onHeartbeatLost = noOp; this.onStompError = noOp; this.onWebSocketClose = noOp; this.onWebSocketError = noOp; this.logRawCommunication = false; this.onChangeState = noOp; // These parameters would typically get proper values before connect is called this.connectHeaders = {}; this._disconnectHeaders = {}; // Apply configuration this.configure(conf); } ``` -------------------------------- ### Implement Custom setupReplyQueue - TypeScript Example Source: https://stomp-js.github.io/api-docs/latest/classes/RxStompRPCConfig Example implementation of a custom setupReplyQueue function that sets up a dedicated temporary reply queue. This function uses RxStomp.watch() to subscribe to a specific destination and return a hot Observable of messages arriving on that queue, suitable for brokers that require explicit subscription. ```TypeScript const setupReplyQueue: setupReplyQueueFnType = (replyQueueName, rxStomp) => { // Ensure the broker delivers replies to `replyQueueName` for this session. // Then return a hot Observable of all messages from that destination. return rxStomp.watch({ destination: replyQueueName }); }; ``` -------------------------------- ### RxStompRPC Constructor and Configuration Source: https://stomp-js.github.io/api-docs/latest/classes/RxStompRPC Initializes the RxStompRPC service, optionally configuring a reply queue name and a custom setup function for the reply queue. It allows for custom reply queue handling to ensure subscriptions remain active. ```typescript constructor( private rxStomp: RxStomp, private stompRPCConfig?: RxStompRPCConfig, ) { if (stompRPCConfig) { if (stompRPCConfig.replyQueueName) { this._replyQueueName = stompRPCConfig.replyQueueName; } if (stompRPCConfig.setupReplyQueue) { this._customReplyQueue = true; this._setupReplyQueue = stompRPCConfig.setupReplyQueue; } } } ``` -------------------------------- ### RxStomp Constructor with Pre-configured Client (TypeScript) Source: https://stomp-js.github.io/api-docs/latest/classes/RxStomp Illustrates how to instantiate RxStomp by injecting a pre-configured Client instance from '@stomp/stompjs'. This is useful for advanced customization or testing scenarios where the underlying STOMP client needs specific setup. ```typescript import { RxStomp } from '@stomp/rx-stomp'; import { Client, Message } from '@stomp/stompjs'; // Create and configure a STOMP client instance const stompClient = new Client({ brokerURL: 'ws://example.com/stomp', // ... other stompjs Client configurations }); // Instantiate RxStomp, passing the pre-configured client const rxStomp = new RxStomp(stompClient); // Now you can use rxStomp as usual (configure, activate, watch, publish, etc.) rxStomp.activate(); rxStomp.watch({ destination: '/user/queue/updates' }).subscribe({ next: (message: Message) => { console.log(`Received message: ${message.body}`); } }); // Remember to deactivate when finished // await rxStomp.deactivate(); ``` -------------------------------- ### Client#begin Source: https://stomp-js.github.io/api-docs/latest/classes/CompatClient Starts a new transaction. You can either let the library generate a transaction ID or provide your own. The returned ITransaction object has methods for committing or aborting the transaction. ```APIDOC ## POST /websites/stomp-js_github_io_api-docs/begin ### Description Starts a new transaction. The returned ITransaction object provides methods for commit and abort. If `transactionId` is not provided, the library generates a unique ID internally. ### Method POST ### Endpoint /begin ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **transactionId** (string) - Optional - Optional transaction ID. ### Request Example ```json { "transactionId": "my-transaction-id" } ``` ### Response #### Success Response (200) - **ITransaction** - An instance of ITransaction, providing commit and abort methods. #### Response Example ```json { "transactionId": "generated-or-provided-id" } ``` ``` -------------------------------- ### Publishing Messages with stomp-js Source: https://stomp-js.github.io/api-docs/latest/classes/Client Provides examples of sending messages to a STOMP broker using the `publish` method in stomp-js. Covers basic text messages, messages with custom headers, skipping the 'content-length' header, and sending binary data using `binaryBody`. Ensure brokers support binary frames before using `binaryBody`. ```javascript // Basic text message client.publish({ destination: "/queue/test", body: "Hello, STOMP" }); // Text message with additional headers client.publish({ destination: "/queue/test", headers: { priority: 9 }, body: "Hello, STOMP" }); // Skip content-length header client.publish({ destination: "/queue/test", body: "Hello, STOMP", skipContentLengthHeader: true }); // Binary message const binaryData = new Uint8Array([1, 2, 3, 4]); client.publish({ destination: '/topic/special', binaryBody: binaryData, headers: { 'content-type': 'application/octet-stream' } }); ``` -------------------------------- ### STOMP Client Configure Method Source: https://stomp-js.github.io/api-docs/latest/classes/Client Example of the `configure` method in TypeScript, which applies a given configuration object to the STOMP client. It uses `Object.assign` for bulk property updates and includes logic to handle potential issues with `maxReconnectDelay` relative to `reconnectDelay`. ```typescript public configure(conf: StompConfig): void { // bulk assign all properties to this (Object as any).assign(this, conf); // Warn on incorrect maxReconnectDelay settings if ( this.maxReconnectDelay > 0 && this.maxReconnectDelay < this.reconnectDelay ) { this.debug( `Warning: maxReconnectDelay (${this.maxReconnectDelay}ms) is less than reconnectDelay (${this.reconnectDelay}ms). Using reconnectDelay as the maxReconnectDelay delay.`, ); this.maxReconnectDelay = this.reconnectDelay; } } ``` -------------------------------- ### POST /transaction/begin Source: https://stomp-js.github.io/api-docs/latest/classes/Client Starts a new transaction and returns an ITransaction object with methods for commit and abort. If transactionId is not provided, the library generates a unique ID internally. ```APIDOC ## POST /transaction/begin ### Description Starts a new transaction. The returned ITransaction object provides methods for commit and abort. If transactionId is not provided, the library generates a unique ID internally. ### Method POST ### Endpoint /transaction/begin ### Parameters #### Request Body - **transactionId** (string) - Optional - Optional transaction ID. If not provided, a unique ID is auto-generated ### Request Example ``` const tx = client.begin(); // Auto-generated ID // Or explicitly specify a transaction ID const tx = client.begin("my-transaction-id"); ``` ### Response #### Success Response (200) - **transactionId** (ITransaction) - An instance of ITransaction with commit and abort methods ### Response Example ``` { "transactionId": "generated-or-provided-id", "commit": "function", "abort": "function" } ``` ``` -------------------------------- ### Implement RxStompRPC class with RPC and streaming methods Source: https://stomp-js.github.io/api-docs/latest/classes/RxStompRPC Complete RxStompRPC class implementation providing Remote Procedure Call functionality over STOMP. Handles request/reply pattern with automatic correlation-id generation, reply queue management, and support for both single and multiple replies. Includes configuration options for custom reply queue setup and naming. ```TypeScript import { filter, first, Observable, Observer, Subscription } from 'rxjs'; import { v4 as uuid } from 'uuid'; import { IMessage, IPublishParams, StompHeaders } from '@stomp/stompjs'; import { RxStomp } from './rx-stomp.js'; import { RxStompRPCConfig, setupReplyQueueFnType, } from './rx-stomp-rpc-config.js'; /** * Remote Procedure Call (RPC) helper over STOMP. * * RxStompRPC implements a simple request/reply pattern using STOMP frames: * - Requests are published to a destination you control. * - A reply destination is advertised via the `reply-to` header. * - Responses are matched back to the request using a `correlation-id` header. * * Usage summary * - Use `rpc(...)` when you expect exactly one reply; it completes after the first matching message. * - Use `stream(...)` when the server may send multiple messages (e.g., progress updates). * - If you provide a `correlation-id` in `params.headers`, it will be used; otherwise a UUID is generated. * - The `reply-to` header is set automatically to `replyQueueName` (default `/temp-queue/rpc-replies`). * * Reply queue strategy * - By default, replies are read from `rxStomp.unhandledMessage$`, which is suitable when the broker * routes temporary-queue replies without an explicit subscription. * - To subscribe to a dedicated queue or customize the reply stream, provide `{ setupReplyQueue }` * via {@link RxStompRPCConfig}. RxStompRPC will keep your observable "hot" internally. * * See the guide for end-to-end examples: * /guide/rx-stomp/ng2-stompjs/remote-procedure-call.html * * Part of `@stomp/rx-stomp` */ export class RxStompRPC { /** * Destination used in the `reply-to` header for all RPC calls. * You can override it through {@link RxStompRPCConfig.replyQueueName}. */ private _replyQueueName = '/temp-queue/rpc-replies'; /** * Factory that returns a hot Observable delivering all reply messages. * Defaults to a function that uses `rxStomp.unhandledMessage$`. * Override via {@link RxStompRPCConfig.setupReplyQueue}. */ private _setupReplyQueue: setupReplyQueueFnType = () => { return this.rxStomp.unhandledMessage$; }; /** * Shared stream of all messages arriving on the reply destination. * Lazily initialized on first call to {@link stream}. */ private _repliesObservable: Observable; /** * True when a custom reply queue setup function is supplied. * In that case, this class keeps a dummy subscription to prevent accidental teardown. */ private _customReplyQueue: boolean = false; // This is used to ensure that underlying subscription remains subscribed private _dummySubscription: Subscription; /** * Construct a new RxStompRPC. * * @param rxStomp The active {@link RxStomp} instance to use for publishing and receiving. * @param stompRPCConfig Optional hooks to customize reply queue name and setup. * * Notes * - If `replyQueueName` is provided, it is used in the `reply-to` header for all requests. * - If `setupReplyQueue` is provided, it must return a hot Observable of all reply messages. * RxStompRPC will subscribe internally to keep it alive across consumers. */ constructor( private rxStomp: RxStomp, stompRPCConfig?: RxStompRPCConfig ) { if (stompRPCConfig?.replyQueueName) { this._replyQueueName = stompRPCConfig.replyQueueName; } if (stompRPCConfig?.setupReplyQueue) { this._setupReplyQueue = stompRPCConfig.setupReplyQueue; this._customReplyQueue = true; } } /** * Perform a unary RPC request that resolves with the first matching reply. * Sends a single request using stream and returns an Observable that emits the first reply whose `correlation-id` matches the request. * The returned Observable completes after emitting the first message. * * @param params Request parameters including destination and body * @returns Observable that emits the first matching reply message */ public rpc(params: IPublishParams): Observable { return this.stream(params).pipe(first()); } /** * Perform an RPC request and receive a stream of matching replies. * A `correlation-id` is attached to the request and used to filter messages from the reply stream. * If you pass `headers['correlation-id']`, it is preserved; otherwise, a UUID is generated. * * @param params Request parameters including destination and body * @returns Observable that emits all matching reply messages */ public stream(params: IPublishParams): Observable { const correlationId = (params.headers?.['correlation-id'] as string) || uuid(); const replyToQueue = this._replyQueueName; const headers: StompHeaders = params.headers || {}; headers['correlation-id'] = correlationId; headers['reply-to'] = replyToQueue; this.rxStomp.publish({ ...params, headers, }); return this._getRepliesObservable().pipe( filter((message: IMessage) => { return message.headers['correlation-id'] === correlationId; }) ); } /** * Get or initialize the shared replies Observable. * Lazily creates and subscribes to the reply queue on first access. */ private _getRepliesObservable(): Observable { if (!this._repliesObservable) { this._repliesObservable = this._setupReplyQueue(this.rxStomp); if (this._customReplyQueue) { this._dummySubscription = this._repliesObservable.subscribe(); } } return this._repliesObservable; } } ``` -------------------------------- ### Client Configuration and Initialization Source: https://stomp-js.github.io/api-docs/latest/classes/Client This section outlines the configuration options and the process of initializing the STOMP client, including details on how the client handles WebSocket creation and connection attempts. ```APIDOC ## Client Initialization ### Description Initializes a new STOMP client instance with various configuration options. The client can establish a WebSocket connection either via a provided broker URL or a custom WebSocket factory. ### Method `new Client(options)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **options** (object) - Required - Configuration options for the client. * **stompVersions** (string[]) - Optional - An array of STOMP protocol versions to support. * **connectHeaders** (object) - Optional - Headers to be sent during the STOMP connection handshake. * **disconnectHeaders** (object) - Optional - Headers to be sent during the STOMP disconnection. * **heartbeatIncoming** (number) - Optional - The expected incoming heartbeat interval in milliseconds. * **heartbeatGracePeriods** (number) - Optional - Multiplier for incoming heartbeat grace periods. * **heartbeatOutgoing** (number) - Optional - The outgoing heartbeat interval in milliseconds. * **heartbeatStrategy** (function) - Optional - A custom strategy for managing heartbeats. * **splitLargeFrames** (boolean) - Optional - Whether to split large frames into smaller chunks. * **maxWebSocketChunkSize** (number) - Optional - The maximum size of WebSocket frame chunks. * **forceBinaryWSFrames** (boolean) - Optional - Whether to force binary frames for WebSockets. * **logRawCommunication** (boolean) - Optional - Whether to log raw WebSocket communication. * **appendMissingNULLonIncoming** (boolean) - Optional - Whether to append a NULL byte to incoming messages if missing. * **discardWebsocketOnCommFailure** (boolean) - Optional - Whether to discard the WebSocket on communication failure. * **onConnect** (function) - Optional - Callback function executed upon successful connection. * **onDisconnect** (function) - Optional - Callback function executed upon disconnection. * **onStompError** (function) - Optional - Callback function executed upon a STOMP-level error. * **onWebSocketClose** (function) - Optional - Callback function executed upon WebSocket closure. * **onWebSocketError** (function) - Optional - Callback function executed upon WebSocket error. * **onUnhandledMessage** (function) - Optional - Callback function for unhandled incoming messages. * **onUnhandledReceipt** (function) - Optional - Callback function for unhandled receipts. * **onUnhandledFrame** (function) - Optional - Callback function for unhandled incoming frames. * **onHeartbeatReceived** (function) - Optional - Callback function when a heartbeat is received. * **onHeartbeatLost** (function) - Optional - Callback function when a heartbeat is lost. * **brokerURL** (string) - Optional - The URL of the STOMP broker. * **webSocketFactory** (function) - Optional - A factory function to create WebSocket instances. ### Request Example ```json { "stompVersions": ["1.1", "1.2"], "connectHeaders": {"login": "user", "passcode": "password"}, "heartbeatIncoming": 5000, "heartbeatOutgoing": 5000, "brokerURL": "ws://localhost:61614/stomp" } ``` ### Response #### Success Response (200) N/A (Constructor does not return a value) #### Response Example N/A ``` -------------------------------- ### RxStompRPC Constructor Source: https://stomp-js.github.io/api-docs/latest/classes/RxStompRPC Initializes an RxStompRPC instance, configuring it to handle RPC requests and replies. ```APIDOC ## RxStompRPC Constructor ### Description Constructs a new RxStompRPC instance to manage remote procedure calls over STOMP. ### Method Constructor ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript const rxStomp = new RxStomp(); // Assuming rxStomp is already configured and connected const rpcClient = new RxStompRPC(rxStomp); ``` ### Response #### Success Response (Constructor) Initializes the RxStompRPC instance. #### Response Example N/A (Constructor) ### Notes - If `replyQueueName` is provided in `stompRPCConfig`, it will be used as the `reply-to` header for all outgoing requests. - If `setupReplyQueue` is provided in `stompRPCConfig`, it must return a hot Observable of all reply messages. RxStompRPC will subscribe internally to keep this observable alive across consumers. ``` -------------------------------- ### Ticker Class Constructor and Methods (TypeScript) Source: https://stomp-js.github.io/api-docs/latest/classes/Ticker Defines the Ticker class with a constructor that accepts an interval, a strategy, and a debug function. It includes public methods 'start' and 'stop' to manage the timing mechanism. The 'start' method takes a callback function that is invoked with the elapsed time, and 'stop' halts any ongoing timing. ```typescript import { debugFnType, TickerStrategy } from './types.js'; export class Ticker { private readonly _workerScript = ` var startTime = Date.now(); setInterval(function() { self.postMessage(Date.now() - startTime); }, ${this._interval}); `; private _worker?: Worker; private _timer?: any; constructor( private readonly _interval: number, private readonly _strategy = TickerStrategy.Interval, private readonly _debug: debugFnType, ) {} public start(tick: (elapsedTime: number) => void): void { this.stop(); if (this.shouldUseWorker()) { this.runWorker(tick); } else { this.runInterval(tick); } } public stop(): void { this.disposeWorker(); this.disposeInterval(); } private shouldUseWorker(): boolean { return ( typeof Worker !== 'undefined' && this._strategy === TickerStrategy.Worker ); } private runWorker(tick: (elapsedTime: number) => void): void { this._debug('Using runWorker for outgoing pings'); if (!this._worker) { this._worker = new Worker( URL.createObjectURL( new Blob([this._workerScript], { type: 'text/javascript' }), ), ); this._worker.onmessage = message => tick(message.data); } } private runInterval(tick: (elapsedTime: number) => void): void { this._debug('Using runInterval for outgoing pings'); if (!this._timer) { const startTime = Date.now(); this._timer = setInterval(() => { tick(Date.now() - startTime); }, this._interval); } } private disposeWorker(): void { if (this._worker) { this._worker.terminate(); delete this._worker; this._debug('Outgoing ping disposeWorker'); } } private disposeInterval(): void { if (this._timer) { clearInterval(this._timer); delete this._timer; this._debug('Outgoing ping disposeInterval'); } } } ``` -------------------------------- ### Initialize STOMP Client with Configuration Source: https://stomp-js.github.io/api-docs/latest/classes/Client Demonstrates how to create a new STOMP client instance. The constructor accepts an optional configuration object to set initial parameters like broker URL and reconnection delays. Default no-op callbacks are assigned to all event handlers. ```javascript const client = new Client({ brokerURL: 'wss://broker.example.com', reconnectDelay: 5000 }); ``` -------------------------------- ### Unhandled Receipt Callback Property Accessors Source: https://stomp-js.github.io/api-docs/latest/classes/CompatClient Gets or sets the callback for handling unhandled STOMP receipts. Deprecated property that maps to onUnhandledReceipt. Recommends using watchForReceipt() for new implementations. ```TypeScript get onreceipt(): frameCallbackType { return this.onUnhandledReceipt; } ``` -------------------------------- ### Constructor - Client Initialization Source: https://stomp-js.github.io/api-docs/latest/classes/Client Constructs a new STOMP client instance with optional configuration. The constructor initializes default values and sets up no-op callbacks for all events, allowing configuration to be passed during construction or updated later. ```APIDOC ## Constructor ### Description Constructs a new STOMP client instance with optional configuration object. ### Method Constructor ### Syntax ``` new Client(conf?: StompConfig) ``` ### Parameters #### Optional Parameters - **conf** (StompConfig) - Optional - Configuration object to initialize the client with ### Configuration Example ```javascript const client = new Client({ brokerURL: 'wss://broker.example.com', reconnectDelay: 5000 }); ``` ### Initialization Details The constructor initializes the following callback functions as no-op operations: - `debug` - `beforeConnect` - `onConnect` - `onDisconnect` - `onUnhandledMessage` - `onUnhandledReceipt` - `onUnhandledFrame` - `onHeartbeatReceived` - `onHeartbeatLost` - `onStompError` - `onWebSocketClose` - `onWebSocketError` - `onChangeState` Default values are also established for: - `logRawCommunication`: false - `connectHeaders`: {} - `_disconnectHeaders`: {} ``` -------------------------------- ### Unhandled Message Callback Property Accessors Source: https://stomp-js.github.io/api-docs/latest/classes/CompatClient Gets or sets the callback for handling unhandled STOMP messages. Deprecated property that maps to onUnhandledMessage. Provides backward compatibility for the legacy onreceive property name. ```TypeScript get onreceive(): messageCallbackType { return this.onUnhandledMessage; } set onreceive(value: messageCallbackType) { this.onUnhandledMessage = value; } ``` -------------------------------- ### STOMP Client Constructor Source: https://stomp-js.github.io/api-docs/latest/classes/Client Initializes a new STOMP client instance with optional configuration. The constructor sets up default values and establishes no-op callbacks for all events. Configuration can be passed during construction or updated later using the configure method. ```APIDOC ## Constructor ### Description Constructs a new STOMP client instance. The constructor initializes default values and sets up no-op callbacks for all events. Configuration can be passed during construction, or updated later using `configure`. ### Method Constructor ### Parameters #### Constructor Parameters - **conf** (StompConfig) - Optional - Optional configuration object to initialize the client with. ### Request Example ```typescript const client = new Client({ brokerURL: 'wss://broker.example.com', reconnectDelay: 5000 }); ``` ### Properties Initialized - **appendMissingNULLonIncoming** (boolean) - Automatically append missing NULL characters on incoming frames - **beforeConnect** (callback) - Function executed before connection establishment - **brokerURL** (string) - WebSocket URL of the STOMP broker - **connectHeaders** (object) - Custom headers to send during STOMP CONNECT frame - **connectionTimeout** (number) - Timeout in milliseconds for connection attempts - **debug** (function) - Debug logging callback function - **discardWebsocketOnCommFailure** (boolean) - Whether to discard WebSocket on communication failure - **forceBinaryWSFrames** (boolean) - Force binary WebSocket frames - **heartbeatIncoming** (number) - Server heartbeat interval in milliseconds - **heartbeatOutgoing** (number) - Client heartbeat interval in milliseconds - **heartbeatStrategy** (string) - Strategy for heartbeat handling - **heartbeatToleranceMultiplier** (number) - Multiplier for heartbeat tolerance - **logRawCommunication** (boolean) - Enable raw communication logging - **maxReconnectDelay** (number) - Maximum delay between reconnection attempts - **maxWebSocketChunkSize** (number) - Maximum WebSocket frame chunk size - **reconnectDelay** (number) - Initial delay between reconnection attempts in milliseconds - **reconnectTimeMode** (string) - Reconnection time mode (linear or exponential) - **splitLargeFrames** (boolean) - Split large frames into smaller chunks - **stompVersions** (array) - Supported STOMP versions (1.0, 1.1, 1.2) - **webSocketFactory** (function) - Custom WebSocket factory function ``` -------------------------------- ### Configure STOMP Protocol Versions Source: https://stomp-js.github.io/api-docs/latest/classes/CompatClient Specify which STOMP protocol versions the client should use during handshake negotiation. By default, versions 1.2, 1.1, and 1.0 are attempted in descending order. This example restricts the client to only versions 1.1 and 1.0. ```javascript // Configure the client to only use versions 1.1 and 1.0 client.stompVersions = new Versions(['1.1', '1.0']); ``` -------------------------------- ### Get Negotiated STOMP Protocol Version - TypeScript Source: https://stomp-js.github.io/api-docs/latest/classes/Client Retrieves the version of the STOMP protocol that was successfully negotiated with the server. This is a read-only property and is only available after a successful connection. Returns a string or undefined. ```typescript import { Client } from '@stomp/stompjs'; // Assuming 'client' is an instance of Client const client = new Client(); // ... client is connected ... const negotiatedVersion: string | undefined = client.connectedVersion; console.log('Connected STOMP version:', negotiatedVersion); ``` -------------------------------- ### Set Custom WebSocket Class in STOMP Source: https://stomp-js.github.io/api-docs/latest/classes/Stomp Demonstrates how to set a custom WebSocket class for the STOMP compatibility class, useful for environments like Node.js. Requires installing the 'websocket' package. ```typescript const StompJs = require('../../esm5/'); const Stomp = StompJs.Stomp; Stomp.WebSocketClass = require('websocket').w3cwebsocket; ``` -------------------------------- ### RxStomp Configuration Options Source: https://stomp-js.github.io/api-docs/latest/classes/RxStompConfig This section outlines the various optional parameters that can be provided to configure an RxStomp instance. ```APIDOC ## RxStomp Configuration Options This document outlines the configuration parameters for RxStomp. ### `RxStompConfig` Object An instance of `RxStompConfig` can be passed to `RxStomp#configure` to customize the behavior of the RxStomp client. All attributes are optional. #### `brokerURL` * **Type**: `string` * **Description**: The WebSocket URL of the STOMP broker endpoint. Example: `"ws://broker.domain.com:15674/ws"` or `"wss://broker.domain.com:15674/ws"`. Only one of this or `webSocketFactory` needs to be set. If both are set, `webSocketFactory` takes precedence. Maps to: `Client#brokerURL`. #### `stompVersions` * **Type**: `Versions` * **Description**: STOMP versions to attempt during the handshake. By default, versions `1.2`, `1.1`, and `1.0` are attempted. Example: `rxStompConfig.stompVersions = new Versions(['1.1', '1.0']);`. Maps to: `Client#stompVersions`. #### `logRawCommunication` * **Type**: `boolean` * **Description**: Enable logging of raw frames exchanged with the broker. When unset or false, only parsed frame headers are logged. Takes effect from the next (re)connection. Caution: Assumes frames contain valid UTF-8 strings. Maps to: `Client#logRawCommunication`. #### `debug` * **Type**: `debugFnType` (function) * **Description**: Custom debug logger for library messages. Example: `rxStompConfig.debug = (msg: string) => { console.log(new Date(), msg); };`. Maps to: `Client#debug`. #### `webSocketFactory` * **Type**: `function` * **Description**: Factory function to create and return a WebSocket-like object (e.g., WebSocket or SockJS). Prefer `brokerURL` if your broker exposes a standard WebSocket endpoint. If both this and `brokerURL` are set, this will be used. Example: `rxStompConfig.webSocketFactory = () => new WebSocket('wss://broker.domain.com:15674/ws');` or `rxStompConfig.webSocketFactory = () => new SockJS('https://broker.domain.com/stomp');`. Maps to: `Client#webSocketFactory`. #### `reconnectDelay` * **Type**: `number` * **Description**: Base delay (in milliseconds) between automatic reconnection attempts. Set to 0 to disable auto-reconnect. Maps to: `Client#reconnectDelay`. #### `reconnectTimeMode` * **Type**: `ReconnectionTimeMode` * **Description**: Strategy for spacing reconnection attempts. `ReconnectionTimeMode.LINEAR`: fixed delay equal to `reconnectDelay`. `ReconnectionTimeMode.EXPONENTIAL`: delay doubles after each attempt, capped by `maxReconnectDelay`. Maps to: `Client#reconnectTimeMode`. #### `maxReconnectDelay` * **Type**: `number` * **Description**: Maximum reconnection delay in milliseconds when using increasing reconnection strategies. Ignored when `reconnectTimeMode` is `fixed/linear` with a constant delay. Maps to: `Client#maxReconnectDelay`. #### `splitLargeFrames` * **Type**: `boolean` * **Description**: Enable a non-standards-compliant mode of splitting large text WebSocket frames. Useful for brokers that require chunked text frames (commonly certain Java Spring setups). Binary frames are never split. Maps to: `Client#splitLargeFrames`. #### `maxWebSocketChunkSize` * **Type**: `number` * **Description**: Maximum size (in bytes) of each WebSocket chunk when `splitLargeFrames` is enabled. Maps to: `Client#maxWebSocketChunkSize`. ``` -------------------------------- ### Initialize RxStomp Client with Optional Constructor Source: https://stomp-js.github.io/api-docs/latest/classes/RxStomp Constructs a new RxStomp instance, optionally wrapping an existing STOMP Client. Initializes internal state management with BehaviorSubjects for connection states, creates Subject observables for error and message streaming, and sets up default no-op handlers for beforeConnect and debug functions. ```typescript public constructor(stompClient?: Client) { this._stompClient = stompClient ? stompClient : new Client(); const noOp = () => {}; this._beforeConnect = noOp; this._correlateErrors = () => undefined; this._debug = noOp; this._connectionStatePre$ = new BehaviorSubject( RxStompState.CLOSED, ); this._connectedPre$ = this._connectionStatePre$.pipe( filter((currentState: RxStompState) => { return currentState === RxStompState.OPEN; }), ); this.connectionState$ = new BehaviorSubject( RxStompState.CLOSED, ); this.connected$ = this.connectionState$.pipe( filter((currentState: RxStompState) => { return currentState === RxStompState.OPEN; }), ); this.connected$.subscribe(() => { this._sendQueuedMessages(); }); this._serverHeadersBehaviourSubject$ = new BehaviorSubject(null); this.serverHeaders$ = this._serverHeadersBehaviourSubject$.pipe( filter((headers: null | StompHeaders) => { return headers !== null; }), ); this.stompErrors$ = new Subject