consolidated/stompjs/src/compatibility/compat-client.ts
Available for backward compatibility, please shift to using Client.
Deprecated
Part of @stomp/stompjs
.
To upgrade, please follow the Upgrade Guide
Properties |
|
Methods |
|
Accessors |
Public maxWebSocketFrameSize |
Type : number
|
Default value : 16 * 1024
|
It is no op now. No longer needed. Large packets work out of the box. |
Public appendMissingNULLonIncoming |
Type : boolean
|
Default value : false
|
Inherited from
Client
|
Defined in
Client:144
|
A bug in ReactNative chops a string on occurrence of a NULL. See issue [https://github.com/stomp-js/stompjs/issues/89]{@link https://github.com/stomp-js/stompjs/issues/89}. This makes incoming WebSocket messages invalid STOMP packets. Setting this flag attempts to reverse the damage by appending a NULL. If the broker splits a large message into multiple WebSocket messages, this flag will cause data loss and abnormal termination of connection. This is not an ideal solution, but a stop gap until the underlying issue is fixed at ReactNative library. |
Public beforeConnect |
Type : function
|
Inherited from
Client
|
Defined in
Client:224
|
Callback, invoked on before a connection to the STOMP broker. You can change options on the client, which will impact the immediate connecting. It is valid to call Client#decativate in this callback. As of version 5.1, this callback can be async (i.e., it can return a Promise). In that case, connect will be called only after the Promise is resolved. This can be used to reliably fetch credentials, access token etc. from some other service in an asynchronous way. |
Public brokerURL |
Type : string | undefined
|
Inherited from
Client
|
Defined in
Client:43
|
The URL for the STOMP broker to connect to.
Typically like Only one of this or Client#webSocketFactory need to be set. If both are set, Client#webSocketFactory will be used. If your environment does not support WebSockets natively, please refer to Polyfills. |
Public connectHeaders |
Type : StompHeaders
|
Inherited from
Client
|
Defined in
Client:158
|
Connection headers, important keys - |
Public connectionTimeout |
Type : number
|
Default value : 0
|
Inherited from
Client
|
Defined in
Client:83
|
Will retry if Stomp connection is not established in specified milliseconds. Default 0, which switches off automatic reconnection. |
Public debug |
Type : debugFnType
|
Inherited from
Client
|
Defined in
Client:295
|
By default, debug messages are discarded. To log to
Currently this method does not support levels of log. Be aware that the output can be quite verbose and may contain sensitive information (like passwords, tokens etc.). |
Public discardWebsocketOnCommFailure |
Type : boolean
|
Default value : false
|
Inherited from
Client
|
Defined in
Client:305
|
Browsers do not immediately close WebSockets when |
Public forceBinaryWSFrames |
Type : boolean
|
Default value : false
|
Inherited from
Client
|
Defined in
Client:132
|
Usually the
type of WebSocket frame
is automatically decided by type of the payload.
Default is Set this flag to force binary frames. |
Public heartbeatIncoming |
Type : number
|
Default value : 10000
|
Inherited from
Client
|
Defined in
Client:96
|
Incoming heartbeat interval in milliseconds. Set to 0 to disable. |
Public heartbeatOutgoing |
Type : number
|
Default value : 10000
|
Inherited from
Client
|
Defined in
Client:101
|
Outgoing heartbeat interval in milliseconds. Set to 0 to disable. |
Public logRawCommunication |
Type : boolean
|
Inherited from
Client
|
Defined in
Client:280
|
Set it to log the actual raw communication with the broker. When unset, it logs headers of the parsed frames. Changes effect from the next broker reconnect. Caution: this assumes that frames only have valid UTF8 strings. |
Public maxWebSocketChunkSize |
Type : number
|
Default value : 8 * 1024
|
Inherited from
Client
|
Defined in
Client:122
|
See splitLargeFrames.
This has no effect if splitLargeFrames is |
Public onChangeState |
Type : function
|
Inherited from
Client
|
Defined in
Client:328
|
It will be called on state change. When deactivating, it may go from ACTIVE to INACTIVE without entering DEACTIVATING. |
Public onConnect |
Type : frameCallbackType
|
Inherited from
Client
|
Defined in
Client:232
|
Callback, invoked on every successful connection to the STOMP broker. The actual IFrame will be passed as parameter to the callback. Sometimes clients will like to use headers from this frame. |
Public onDisconnect |
Type : frameCallbackType
|
Inherited from
Client
|
Defined in
Client:245
|
Callback, invoked on every successful disconnection from the STOMP broker. It will not be invoked if the STOMP broker disconnected due to an error. The actual Receipt IFrame acknowledging the DISCONNECT will be passed as parameter to the callback. The way STOMP protocol is designed, the connection may close/terminate without the client receiving the Receipt IFrame acknowledging the DISCONNECT. You might find Client#onWebSocketClose more appropriate to watch STOMP broker disconnects. |
Public onStompError |
Type : frameCallbackType
|
Inherited from
Client
|
Defined in
Client:254
|
Callback, invoked on an ERROR frame received from the STOMP Broker. A compliant STOMP Broker will close the connection after this type of frame. Please check broker specific documentation for exact behavior. The actual IFrame will be passed as parameter to the callback. |
Public onUnhandledFrame |
Type : frameCallbackType
|
Inherited from
Client
|
Defined in
Client:201
|
Public onUnhandledMessage |
Type : messageCallbackType
|
Inherited from
Client
|
Defined in
Client:185
|
This function will be called for any unhandled messages. It is useful for receiving messages sent to RabbitMQ temporary queues. It can also get invoked with stray messages while the server is processing a request to Client#unsubscribe from an endpoint. The actual IMessage will be passed as parameter to the callback. |
Public onUnhandledReceipt |
Type : frameCallbackType
|
Inherited from
Client
|
Defined in
Client:194
|
STOMP brokers can be requested to notify when an operation is actually completed. Prefer using Client#watchForReceipt. See Client#watchForReceipt for examples. The actual IFrame will be passed as parameter to the callback. |
Public onWebSocketClose |
Type : closeEventCallbackType
|
Inherited from
Client
|
Defined in
Client:262
|
Callback, invoked when underlying WebSocket is closed. Actual CloseEvent is passed as parameter to the callback. |
Public onWebSocketError |
Type : wsErrorCallbackType
|
Inherited from
Client
|
Defined in
Client:270
|
Callback, invoked when underlying WebSocket raises an error. Actual Event is passed as parameter to the callback. |
Public reconnectDelay |
Type : number
|
Default value : 5000
|
Inherited from
Client
|
Defined in
Client:91
|
automatically reconnect with delay in milliseconds, set to 0 to disable. |
Public splitLargeFrames |
Type : boolean
|
Default value : false
|
Inherited from
Client
|
Defined in
Client:116
|
This switches on a non-standard behavior while sending WebSocket packets. It splits larger (text) packets into chunks of maxWebSocketChunkSize. Only Java Spring brokers seem to support this mode. WebSockets, by itself, split large (text) packets, so it is not needed with a truly compliant STOMP/WebSocket broker. Setting it for such a broker will cause large messages to fail.
Binary frames are never split. |
Public state |
Type : ActivationState
|
Default value : ActivationState.INACTIVE
|
Inherited from
Client
|
Defined in
Client:341
|
Activation state. It will usually be ACTIVE or INACTIVE. When deactivating, it may go from ACTIVE to INACTIVE without entering DEACTIVATING. |
Public stompVersions |
Default value : Versions.default
|
Inherited from
Client
|
Defined in
Client:54
|
STOMP versions to attempt during STOMP handshake. By default, versions Example:
|
Public webSocketFactory |
Type : | undefined
|
Inherited from
Client
|
Defined in
Client:77
|
This function should return a WebSocket or a similar (e.g. SockJS) object. If your environment does not support WebSockets natively, please refer to Polyfills. If your STOMP Broker supports WebSockets, prefer setting Client#brokerURL. If both this and Client#brokerURL are set, this will be used. Example:
|
Public connect | ||||||
connect(...args: any[])
|
||||||
Available for backward compatibility, please shift to using Client#activate. Deprecated The overloads:
params:
To upgrade, please follow the Upgrade Guide
Parameters :
Returns :
void
|
Public disconnect | ||||||||||||
disconnect(disconnectCallback?: any, headers: StompHeaders)
|
||||||||||||
Available for backward compatibility, please shift to using Client#deactivate. Deprecated See: Client#onDisconnect, and Client#disconnectHeaders To upgrade, please follow the Upgrade Guide
Parameters :
Returns :
void
|
Public send | ||||||||||||||||
send(destination: string, headers: literal type, body: string)
|
||||||||||||||||
Available for backward compatibility, use Client#publish. Send a message to a named destination. Refer to your STOMP broker documentation for types and naming of destinations. The headers will, typically, be available to the subscriber. However, there may be special purpose headers corresponding to your STOMP broker. Deprecated, use Client#publish Note: Body must be String. You will need to covert the payload to string in case it is not string (e.g. JSON)
To upgrade, please follow the Upgrade Guide
Parameters :
Returns :
void
|
Public abort | ||||||
abort(transactionId: string)
|
||||||
Inherited from
Client
|
||||||
Defined in
Client:816
|
||||||
Abort a transaction. It is preferable to abort a transaction by calling abort directly on ITransaction returned by client.begin.
Parameters :
Returns :
void
|
Public ack | ||||||||||||||||
ack(messageId: string, subscriptionId: string, headers: StompHeaders)
|
||||||||||||||||
Inherited from
Client
|
||||||||||||||||
Defined in
Client:835
|
||||||||||||||||
ACK a message. It is preferable to acknowledge a message by calling ack directly on the IMessage handled by a subscription callback:
Parameters :
Returns :
void
|
Public activate |
activate()
|
Inherited from
Client
|
Defined in
Client:387
|
Initiate the connection with the broker. If the connection breaks, as per Client#reconnectDelay, it will keep trying to reconnect. Call Client#deactivate to disconnect and stop reconnection attempts.
Returns :
void
|
Public begin | ||||||
begin(transactionId?: string)
|
||||||
Inherited from
Client
|
||||||
Defined in
Client:781
|
||||||
Start a transaction, the returned ITransaction has methods - commit and abort.
Parameters :
Returns :
ITransaction
|
Public commit | ||||||
commit(transactionId: string)
|
||||||
Inherited from
Client
|
||||||
Defined in
Client:799
|
||||||
Commit a transaction. It is preferable to commit a transaction by calling commit directly on ITransaction returned by client.begin.
Parameters :
Returns :
void
|
Public configure | ||||||
configure(conf: StompConfig)
|
||||||
Inherited from
Client
|
||||||
Defined in
Client:375
|
||||||
Update configuration.
Parameters :
Returns :
void
|
Public Async deactivate | ||||||||
deactivate(options: literal type)
|
||||||||
Inherited from
Client
|
||||||||
Defined in
Client:568
|
||||||||
Disconnect if connected and stop auto reconnect loop. Appropriate callbacks will be invoked if there is an underlying STOMP connection. This call is async. It will resolve immediately if there is no underlying active websocket, otherwise, it will resolve after the underlying websocket is properly disposed of. It is not an error to invoke this method more than once. Each of those would resolve on completion of deactivation. To reactivate, you can call Client#activate. Experimental: pass It is possible to invoke this method initially without the
Parameters :
Returns :
Promise<void>
|
Public forceDisconnect |
forceDisconnect()
|
Inherited from
Client
|
Defined in
Client:621
|
Force disconnect if there is an active connection by directly closing the underlying WebSocket. This is different from a normal disconnect where a DISCONNECT sequence is carried out with the broker. After forcing disconnect, automatic reconnect will be attempted. To stop further reconnects call Client#deactivate as well.
Returns :
void
|
Public nack | ||||||||||||||||
nack(messageId: string, subscriptionId: string, headers: StompHeaders)
|
||||||||||||||||
Inherited from
Client
|
||||||||||||||||
Defined in
Client:858
|
||||||||||||||||
NACK a message. It is preferable to acknowledge a message by calling nack directly on the IMessage handled by a subscription callback:
Parameters :
Returns :
void
|
Public publish | ||||||
publish(params: IPublishParams)
|
||||||
Inherited from
Client
|
||||||
Defined in
Client:670
|
||||||
Send a message to a named destination. Refer to your STOMP broker documentation for types and naming of destinations. STOMP protocol specifies and suggests some headers and also allows broker-specific headers.
To send a binary message body, use
Caution: The broker will, most likely, report an error and disconnect
if the message body has NULL octet(s) and
Parameters :
Returns :
void
|
Public subscribe | ||||||||||||||||
subscribe(destination: string, callback: messageCallbackType, headers: StompHeaders)
|
||||||||||||||||
Inherited from
Client
|
||||||||||||||||
Defined in
Client:747
|
||||||||||||||||
Subscribe to a STOMP Broker location. The callback will be invoked for each received message with the IMessage as argument. Note: The library will generate a unique ID if there is none provided in the headers.
To use your own ID, pass it using the
Parameters :
Returns :
StompSubscription
|
Public unsubscribe | ||||||||||||
unsubscribe(id: string, headers: StompHeaders)
|
||||||||||||
Inherited from
Client
|
||||||||||||
Defined in
Client:769
|
||||||||||||
It is preferable to unsubscribe from a subscription by calling
See: https://stomp.github.com/stomp-specification-1.2.html#UNSUBSCRIBE UNSUBSCRIBE Frame
Parameters :
Returns :
void
|
Public watchForReceipt | |||||||||
watchForReceipt(receiptId: string, callback: frameCallbackType)
|
|||||||||
Inherited from
Client
|
|||||||||
Defined in
Client:717
|
|||||||||
STOMP brokers may carry out operation asynchronously and allow requesting for acknowledgement.
To request an acknowledgement, a A complaint broker will send a RECEIPT frame when an operation has actually been completed. The operation needs to be matched based on the value of the receipt-id. This method allows watching for a receipt and invoking the callback when the corresponding receipt has been received. The actual IFrame will be passed as parameter to the callback. Example:
Parameters :
Returns :
void
|
reconnect_delay | ||||||
setreconnect_delay(value: number)
|
||||||
Available for backward compatibility, renamed to Client#reconnectDelay. Deprecated
Parameters :
Returns :
void
|
ws |
getws()
|
Available for backward compatibility, renamed to Client#webSocket. Deprecated
Returns :
any
|
version |
getversion()
|
Available for backward compatibility, renamed to Client#connectedVersion. Deprecated |
onreceive | ||||||
getonreceive()
|
||||||
Available for backward compatibility, renamed to Client#onUnhandledMessage. Deprecated
Returns :
messageCallbackType
|
||||||
setonreceive(value: messageCallbackType)
|
||||||
Available for backward compatibility, renamed to Client#onUnhandledMessage. Deprecated
Parameters :
Returns :
void
|
onreceipt | ||||||
getonreceipt()
|
||||||
Available for backward compatibility, renamed to Client#onUnhandledReceipt. Prefer using Client#watchForReceipt. Deprecated
Returns :
frameCallbackType
|
||||||
setonreceipt(value: frameCallbackType)
|
||||||
Available for backward compatibility, renamed to Client#onUnhandledReceipt. Deprecated
Parameters :
Returns :
void
|
heartbeat | ||||||
getheartbeat()
|
||||||
Available for backward compatibility, renamed to Client#heartbeatIncoming Client#heartbeatOutgoing. Deprecated |
||||||
setheartbeat(value: literal type)
|
||||||
Available for backward compatibility, renamed to Client#heartbeatIncoming Client#heartbeatOutgoing. Deprecated
Parameters :
Returns :
void
|
import { Client } from '../client.js';
import { StompHeaders } from '../stomp-headers.js';
import { frameCallbackType, messageCallbackType } from '../types.js';
import { HeartbeatInfo } from './heartbeat-info.js';
/**
* Available for backward compatibility, please shift to using {@link Client}.
*
* **Deprecated**
*
* Part of `@stomp/stompjs`.
*
* To upgrade, please follow the [Upgrade Guide](https://stomp-js.github.io/guide/stompjs/upgrading-stompjs.html)
*/
export class CompatClient extends Client {
/**
* It is no op now. No longer needed. Large packets work out of the box.
*/
public maxWebSocketFrameSize: number = 16 * 1024;
/**
* Available for backward compatibility, please shift to using {@link Client}
* and [Client#webSocketFactory]{@link Client#webSocketFactory}.
*
* **Deprecated**
*
* @internal
*/
constructor(webSocketFactory: () => any) {
super();
this.reconnect_delay = 0;
this.webSocketFactory = webSocketFactory;
// Default from previous version
this.debug = (...message: any[]) => {
console.log(...message);
};
}
private _parseConnect(...args: any[]): any {
let closeEventCallback;
let connectCallback;
let errorCallback;
let headers: StompHeaders = {};
if (args.length < 2) {
throw new Error('Connect requires at least 2 arguments');
}
if (typeof args[1] === 'function') {
[headers, connectCallback, errorCallback, closeEventCallback] = args;
} else {
switch (args.length) {
case 6:
[
headers.login,
headers.passcode,
connectCallback,
errorCallback,
closeEventCallback,
headers.host,
] = args;
break;
default:
[
headers.login,
headers.passcode,
connectCallback,
errorCallback,
closeEventCallback,
] = args;
}
}
return [headers, connectCallback, errorCallback, closeEventCallback];
}
/**
* Available for backward compatibility, please shift to using [Client#activate]{@link Client#activate}.
*
* **Deprecated**
*
* The `connect` method accepts different number of arguments and types. See the Overloads list. Use the
* version with headers to pass your broker specific options.
*
* overloads:
* - connect(headers, connectCallback)
* - connect(headers, connectCallback, errorCallback)
* - connect(login, passcode, connectCallback)
* - connect(login, passcode, connectCallback, errorCallback)
* - connect(login, passcode, connectCallback, errorCallback, closeEventCallback)
* - connect(login, passcode, connectCallback, errorCallback, closeEventCallback, host)
*
* params:
* - headers, see [Client#connectHeaders]{@link Client#connectHeaders}
* - connectCallback, see [Client#onConnect]{@link Client#onConnect}
* - errorCallback, see [Client#onStompError]{@link Client#onStompError}
* - closeEventCallback, see [Client#onWebSocketClose]{@link Client#onWebSocketClose}
* - login [String], see [Client#connectHeaders](../classes/Client.html#connectHeaders)
* - passcode [String], [Client#connectHeaders](../classes/Client.html#connectHeaders)
* - host [String], see [Client#connectHeaders](../classes/Client.html#connectHeaders)
*
* To upgrade, please follow the [Upgrade Guide](../additional-documentation/upgrading.html)
*/
public connect(...args: any[]): void {
const out = this._parseConnect(...args);
if (out[0]) {
this.connectHeaders = out[0];
}
if (out[1]) {
this.onConnect = out[1];
}
if (out[2]) {
this.onStompError = out[2];
}
if (out[3]) {
this.onWebSocketClose = out[3];
}
super.activate();
}
/**
* Available for backward compatibility, please shift to using [Client#deactivate]{@link Client#deactivate}.
*
* **Deprecated**
*
* See:
* [Client#onDisconnect]{@link Client#onDisconnect}, and
* [Client#disconnectHeaders]{@link Client#disconnectHeaders}
*
* To upgrade, please follow the [Upgrade Guide](../additional-documentation/upgrading.html)
*/
public disconnect(
disconnectCallback?: any,
headers: StompHeaders = {}
): void {
if (disconnectCallback) {
this.onDisconnect = disconnectCallback;
}
this.disconnectHeaders = headers;
super.deactivate();
}
/**
* Available for backward compatibility, use [Client#publish]{@link Client#publish}.
*
* Send a message to a named destination. Refer to your STOMP broker documentation for types
* and naming of destinations. The headers will, typically, be available to the subscriber.
* However, there may be special purpose headers corresponding to your STOMP broker.
*
* **Deprecated**, use [Client#publish]{@link Client#publish}
*
* Note: Body must be String. You will need to covert the payload to string in case it is not string (e.g. JSON)
*
* ```javascript
* client.send("/queue/test", {priority: 9}, "Hello, STOMP");
*
* // If you want to send a message with a body, you must also pass the headers argument.
* client.send("/queue/test", {}, "Hello, STOMP");
* ```
*
* To upgrade, please follow the [Upgrade Guide](../additional-documentation/upgrading.html)
*/
public send(
destination: string,
headers: { [key: string]: any } = {},
body: string = ''
): void {
headers = (Object as any).assign({}, headers);
const skipContentLengthHeader = headers['content-length'] === false;
if (skipContentLengthHeader) {
delete headers['content-length'];
}
this.publish({
destination,
headers: headers as StompHeaders,
body,
skipContentLengthHeader,
});
}
/**
* Available for backward compatibility, renamed to [Client#reconnectDelay]{@link Client#reconnectDelay}.
*
* **Deprecated**
*/
set reconnect_delay(value: number) {
this.reconnectDelay = value;
}
/**
* Available for backward compatibility, renamed to [Client#webSocket]{@link Client#webSocket}.
*
* **Deprecated**
*/
get ws(): any {
return this.webSocket;
}
/**
* Available for backward compatibility, renamed to [Client#connectedVersion]{@link Client#connectedVersion}.
*
* **Deprecated**
*/
get version() {
return this.connectedVersion;
}
/**
* Available for backward compatibility, renamed to [Client#onUnhandledMessage]{@link Client#onUnhandledMessage}.
*
* **Deprecated**
*/
get onreceive(): messageCallbackType {
return this.onUnhandledMessage;
}
/**
* Available for backward compatibility, renamed to [Client#onUnhandledMessage]{@link Client#onUnhandledMessage}.
*
* **Deprecated**
*/
set onreceive(value: messageCallbackType) {
this.onUnhandledMessage = value;
}
/**
* Available for backward compatibility, renamed to [Client#onUnhandledReceipt]{@link Client#onUnhandledReceipt}.
* Prefer using [Client#watchForReceipt]{@link Client#watchForReceipt}.
*
* **Deprecated**
*/
get onreceipt(): frameCallbackType {
return this.onUnhandledReceipt;
}
/**
* Available for backward compatibility, renamed to [Client#onUnhandledReceipt]{@link Client#onUnhandledReceipt}.
*
* **Deprecated**
*/
set onreceipt(value: frameCallbackType) {
this.onUnhandledReceipt = value;
}
private _heartbeatInfo: HeartbeatInfo = new HeartbeatInfo(this);
/**
* Available for backward compatibility, renamed to [Client#heartbeatIncoming]{@link Client#heartbeatIncoming}
* [Client#heartbeatOutgoing]{@link Client#heartbeatOutgoing}.
*
* **Deprecated**
*/
get heartbeat() {
return this._heartbeatInfo;
}
/**
* Available for backward compatibility, renamed to [Client#heartbeatIncoming]{@link Client#heartbeatIncoming}
* [Client#heartbeatOutgoing]{@link Client#heartbeatOutgoing}.
*
* **Deprecated**
*/
set heartbeat(value: { incoming: number; outgoing: number }) {
this.heartbeatIncoming = value.incoming;
this.heartbeatOutgoing = value.outgoing;
}
}