@stomp/stompjs
- Version 7.1.1
- Published
- 425 kB
- No dependencies
- Apache-2.0 license
Install
npm i @stomp/stompjs
yarn add @stomp/stompjs
pnpm add @stomp/stompjs
Overview
STOMP client for Javascript and Typescript
Index
Classes
Client
- abort()
- ack()
- activate()
- active
- appendMissingNULLonIncoming
- beforeConnect
- begin()
- brokerURL
- commit()
- configure()
- connected
- connectedVersion
- connectHeaders
- connectionTimeout
- deactivate()
- debug
- discardWebsocketOnCommFailure
- disconnectHeaders
- forceBinaryWSFrames
- forceDisconnect()
- heartbeatIncoming
- heartbeatOutgoing
- heartbeatStrategy
- logRawCommunication
- maxReconnectDelay
- maxWebSocketChunkSize
- nack()
- onChangeState
- onConnect
- onDisconnect
- onStompError
- onUnhandledFrame
- onUnhandledMessage
- onUnhandledReceipt
- onWebSocketClose
- onWebSocketError
- publish()
- reconnectDelay
- reconnectTimeMode
- splitLargeFrames
- state
- stompVersions
- subscribe()
- unsubscribe()
- watchForReceipt()
- webSocket
- webSocketFactory
StompConfig
- appendMissingNULLonIncoming
- beforeConnect
- brokerURL
- connectHeaders
- connectionTimeout
- debug
- discardWebsocketOnCommFailure
- disconnectHeaders
- forceBinaryWSFrames
- heartbeatIncoming
- heartbeatOutgoing
- heartbeatStrategy
- logRawCommunication
- maxReconnectDelay
- maxWebSocketChunkSize
- onChangeState
- onConnect
- onDisconnect
- onStompError
- onUnhandledFrame
- onUnhandledMessage
- onUnhandledReceipt
- onWebSocketClose
- onWebSocketError
- reconnectDelay
- reconnectTimeMode
- splitLargeFrames
- stompVersions
- webSocketFactory
Interfaces
Enums
Type Aliases
Classes
class Client
class Client {}
STOMP Client Class.
Part of
@stomp/stompjs
.
constructor
constructor(conf?: StompConfig);
Create an instance.
property active
readonly active: boolean;
if the client is active (connected or going to reconnect)
property appendMissingNULLonIncoming
appendMissingNULLonIncoming: boolean;
A bug in ReactNative chops a string on occurrence of a NULL. See issue [https://github.com/stomp-js/stompjs/issues/89]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.
property beforeConnect
beforeConnect: (client: Client) => void | Promise<void>;
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]Client#deactivate in this callback.
As of version 5.1, this callback can be [async](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function) (i.e., it can return a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/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.
property brokerURL
brokerURL: string;
The URL for the STOMP broker to connect to. Typically like
"ws://broker.329broker.com:15674/ws"
or"wss://broker.329broker.com:15674/ws"
.Only one of this or [Client#webSocketFactory]Client#webSocketFactory need to be set. If both are set, [Client#webSocketFactory]Client#webSocketFactory will be used.
If your environment does not support WebSockets natively, please refer to [Polyfills]https://stomp-js.github.io/guide/stompjs/rx-stomp/ng2-stompjs/pollyfils-for-stompjs-v5.html.
property connected
readonly connected: boolean;
true
if there is an active connection to STOMP Broker
property connectedVersion
readonly connectedVersion: string;
version of STOMP protocol negotiated with the server, READONLY
property connectHeaders
connectHeaders: StompHeaders;
Connection headers, important keys -
login
,passcode
,host
. Though STOMP 1.2 standard marks these keys to be present, check your broker documentation for details specific to your broker.
property connectionTimeout
connectionTimeout: number;
Will retry if Stomp connection is not established in specified milliseconds. Default 0, which switches off automatic reconnection.
property debug
debug: debugFnType;
By default, debug messages are discarded. To log to
console
following can be used:client.debug = function(str) {console.log(str);};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.).
property discardWebsocketOnCommFailure
discardWebsocketOnCommFailure: boolean;
Browsers do not immediately close WebSockets when
.close
is issued. This may cause reconnection to take a significantly long time in case of some types of failures. In case of incoming heartbeat failure, this experimental flag instructs the library to discard the socket immediately (even before it is actually closed).
property disconnectHeaders
disconnectHeaders: StompHeaders;
Disconnection headers.
property forceBinaryWSFrames
forceBinaryWSFrames: boolean;
Usually the [type of WebSocket frame]https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send#Parameters is automatically decided by type of the payload. Default is
false
, which should work with all compliant brokers.Set this flag to force binary frames.
property heartbeatIncoming
heartbeatIncoming: number;
Incoming heartbeat interval in milliseconds. Set to 0 to disable.
property heartbeatOutgoing
heartbeatOutgoing: number;
Outgoing heartbeat interval in milliseconds. Set to 0 to disable.
property heartbeatStrategy
heartbeatStrategy: TickerStrategy;
Outgoing heartbeat strategy. See https://github.com/stomp-js/stompjs/pull/579
Can be worker or interval strategy, but will always use
interval
if web workers are unavailable, for example, in a non-browser environment.Using Web Workers may work better on long-running pages and mobile apps, as the browser may suspend Timers in the main page. Try the
Worker
mode if you discover disconnects when the browser tab is in the background.When used in a JS environment, use 'worker' or 'interval' as valid values.
Defaults to
interval
strategy.
property logRawCommunication
logRawCommunication: boolean;
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.**
property maxReconnectDelay
maxReconnectDelay: number;
Maximum time to wait between reconnects, in milliseconds. Defaults to 15 minutes. Only relevant when [Client#reconnectTimeMode]Client#reconnectTimeMode not LINEAR (e.g., EXPONENTIAL). Set to 0 for no limit on wait time.
property maxWebSocketChunkSize
maxWebSocketChunkSize: number;
See [splitLargeFrames]Client#splitLargeFrames. This has no effect if [splitLargeFrames]Client#splitLargeFrames is
false
.
property onChangeState
onChangeState: (state: ActivationState) => void;
It will be called on state change.
When deactivating, it may go from ACTIVE to INACTIVE without entering DEACTIVATING.
property onConnect
onConnect: frameCallbackType;
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.
property onDisconnect
onDisconnect: frameCallbackType;
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]Client#onWebSocketClose more appropriate to watch STOMP broker disconnects.
property onStompError
onStompError: frameCallbackType;
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.
property onUnhandledFrame
onUnhandledFrame: frameCallbackType;
property onUnhandledMessage
onUnhandledMessage: messageCallbackType;
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]Client#unsubscribe from an endpoint.
The actual IMessage will be passed as parameter to the callback.
property onUnhandledReceipt
onUnhandledReceipt: frameCallbackType;
STOMP brokers can be requested to notify when an operation is actually completed. Prefer using [Client#watchForReceipt]Client#watchForReceipt. See [Client#watchForReceipt]Client#watchForReceipt for examples.
The actual IFrame will be passed as parameter to the callback.
property onWebSocketClose
onWebSocketClose: closeEventCallbackType<any>;
Callback, invoked when underlying WebSocket is closed.
Actual [CloseEvent]https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent is passed as parameter to the callback.
property onWebSocketError
onWebSocketError: wsErrorCallbackType<any>;
Callback, invoked when underlying WebSocket raises an error.
Actual [Event]https://developer.mozilla.org/en-US/docs/Web/API/Event is passed as parameter to the callback.
property reconnectDelay
reconnectDelay: number;
automatically reconnect with delay in milliseconds, set to 0 to disable.
property reconnectTimeMode
reconnectTimeMode: ReconnectionTimeMode;
Reconnection wait time mode, either linear (default) or exponential. Note: See [Client#maxReconnectDelay]Client#maxReconnectDelay for setting the maximum delay when exponential
client.configure({reconnectTimeMode: ReconnectionTimeMode.EXPONENTIAL,reconnectDelay: 200, // It will wait 200, 400, 800 ms...maxReconnectDelay: 10000, // Optional, when provided, it will not wait more that these ms})
property splitLargeFrames
splitLargeFrames: boolean;
This switches on a non-standard behavior while sending WebSocket packets. It splits larger (text) packets into chunks of [maxWebSocketChunkSize]Client#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.
false
by default.Binary frames are never split.
property state
state: ActivationState;
Activation state.
It will usually be ACTIVE or INACTIVE. When deactivating, it may go from ACTIVE to INACTIVE without entering DEACTIVATING.
property stompVersions
stompVersions: Versions;
STOMP versions to attempt during STOMP handshake. By default, versions
1.2
,1.1
, and1.0
are attempted.Example:
// Try only versions 1.1 and 1.0client.stompVersions = new Versions(['1.1', '1.0'])
property webSocket
readonly webSocket: IStompSocket;
Underlying WebSocket instance, READONLY.
property webSocketFactory
webSocketFactory: () => IStompSocket;
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]https://stomp-js.github.io/guide/stompjs/rx-stomp/ng2-stompjs/pollyfils-for-stompjs-v5.html. If your STOMP Broker supports WebSockets, prefer setting [Client#brokerURL]Client#brokerURL.
If both this and [Client#brokerURL]Client#brokerURL are set, this will be used.
Example:
// use a WebSocketclient.webSocketFactory= function () {return new WebSocket("wss://broker.329broker.com:15674/ws");};// Typical usage with SockJSclient.webSocketFactory= function () {return new SockJS("http://broker.329broker.com/stomp");};
method abort
abort: (transactionId: string) => void;
Abort a transaction. It is preferable to abort a transaction by calling [abort]ITransaction#abort directly on ITransaction returned by [client.begin]Client#begin.
var tx = client.begin(txId);//...tx.abort();
method ack
ack: (messageId: string, subscriptionId: string, headers?: StompHeaders) => void;
ACK a message. It is preferable to acknowledge a message by calling [ack]IMessage#ack directly on the IMessage handled by a subscription callback:
var callback = function (message) {// process the message// acknowledge itmessage.ack();};client.subscribe(destination, callback, {'ack': 'client'});
method activate
activate: () => void;
Initiate the connection with the broker. If the connection breaks, as per [Client#reconnectDelay]Client#reconnectDelay, it will keep trying to reconnect. If the [Client#reconnectTimeMode]Client#reconnectTimeMode is set to EXPONENTIAL it will increase the wait time exponentially
Call [Client#deactivate]Client#deactivate to disconnect and stop reconnection attempts.
method begin
begin: (transactionId?: string) => ITransaction;
Start a transaction, the returned ITransaction has methods - [commit]ITransaction#commit and [abort]ITransaction#abort.
transactionId
is optional, if not passed the library will generate it internally.
method commit
commit: (transactionId: string) => void;
Commit a transaction.
It is preferable to commit a transaction by calling [commit]ITransaction#commit directly on ITransaction returned by [client.begin]Client#begin.
var tx = client.begin(txId);//...tx.commit();
method configure
configure: (conf: StompConfig) => void;
Update configuration.
method deactivate
deactivate: (options?: { force?: boolean }) => Promise<void>;
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]Client#activate.
Experimental: pass
force: true
to immediately discard the underlying connection. This mode will skip both the STOMP and the Websocket shutdown sequences. In some cases, browsers take a long time in the Websocket shutdown if the underlying connection had gone stale. Using this mode can speed up. When this mode is used, the actual Websocket may linger for a while and the broker may not realize that the connection is no longer in use.It is possible to invoke this method initially without the
force
option and subsequently, say after a wait, with theforce
option.
method forceDisconnect
forceDisconnect: () => void;
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]Client#deactivate as well.
method nack
nack: ( messageId: string, subscriptionId: string, headers?: StompHeaders) => void;
NACK a message. It is preferable to acknowledge a message by calling [nack]IMessage#nack directly on the IMessage handled by a subscription callback:
var callback = function (message) {// process the message// an error occurs, nack itmessage.nack();};client.subscribe(destination, callback, {'ack': 'client'});
method publish
publish: (params: IPublishParams) => void;
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.
body
must be String. You will need to covert the payload to string in case it is not string (e.g. JSON).To send a binary message body, use
binaryBody
parameter. It should be a [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array). Sometimes brokers may not support binary frames out of the box. Please check your broker documentation.content-length
header is automatically added to the STOMP Frame sent to the broker. SetskipContentLengthHeader
to indicate thatcontent-length
header should not be added. For binary messages,content-length
header is always added.Caution: The broker will, most likely, report an error and disconnect if the message body has NULL octet(s) and
content-length
header is missing.client.publish({destination: "/queue/test", headers: {priority: 9}, body: "Hello, STOMP"});// Only destination is mandatory parameterclient.publish({destination: "/queue/test", body: "Hello, STOMP"});// Skip content-length header in the frame to the brokerclient.publish({"/queue/test", body: "Hello, STOMP", skipContentLengthHeader: true});var binaryData = generateBinaryData(); // This need to be of type Uint8Array// setting content-type header is not mandatory, however a good practiceclient.publish({destination: '/topic/special', binaryBody: binaryData,headers: {'content-type': 'application/octet-stream'}});
method subscribe
subscribe: ( destination: string, callback: messageCallbackType, headers?: StompHeaders) => StompSubscription;
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
headers
argument.callback = function(message) {// called when the client receives a STOMP message from the serverif (message.body) {alert("got message with body " + message.body)} else {alert("got empty message");}});var subscription = client.subscribe("/queue/test", callback);// Explicit subscription idvar mySubId = 'my-subscription-id-001';var subscription = client.subscribe(destination, callback, { id: mySubId });
method unsubscribe
unsubscribe: (id: string, headers?: StompHeaders) => void;
It is preferable to unsubscribe from a subscription by calling
unsubscribe()
directly on StompSubscription returned byclient.subscribe()
:var subscription = client.subscribe(destination, onmessage);// ...subscription.unsubscribe();See: https://stomp.github.com/stomp-specification-1.2.html#UNSUBSCRIBE UNSUBSCRIBE Frame
method watchForReceipt
watchForReceipt: (receiptId: string, callback: frameCallbackType) => void;
STOMP brokers may carry out operation asynchronously and allow requesting for acknowledgement. To request an acknowledgement, a
receipt
header needs to be sent with the actual request. The value (say receipt-id) for this header needs to be unique for each use. Typically, a sequence, a UUID, a random number or a combination may be used.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:
// Subscribing with acknowledgementlet receiptId = randomText();client.watchForReceipt(receiptId, function() {// Will be called after server acknowledges});client.subscribe(TEST.destination, onMessage, {receipt: receiptId});// Publishing with acknowledgementreceiptId = randomText();client.watchForReceipt(receiptId, function() {// Will be called after server acknowledges});client.publish({destination: TEST.destination, headers: {receipt: receiptId}, body: msg});
class CompatClient
class CompatClient extends Client {}
Available for backward compatibility, please shift to using Client.
**Deprecated**
Part of
@stomp/stompjs
.To upgrade, please follow the [Upgrade Guide](https://stomp-js.github.io/guide/stompjs/upgrading-stompjs.html)
property heartbeat
heartbeat: { incoming: number; outgoing: number };
Available for backward compatibility, renamed to [Client#heartbeatIncoming]Client#heartbeatIncoming [Client#heartbeatOutgoing]Client#heartbeatOutgoing.
**Deprecated**
property maxWebSocketFrameSize
maxWebSocketFrameSize: number;
It is no op now. No longer needed. Large packets work out of the box.
property onreceipt
onreceipt: frameCallbackType;
Available for backward compatibility, renamed to [Client#onUnhandledReceipt]Client#onUnhandledReceipt. Prefer using [Client#watchForReceipt]Client#watchForReceipt.
**Deprecated**
property onreceive
onreceive: messageCallbackType;
Available for backward compatibility, renamed to [Client#onUnhandledMessage]Client#onUnhandledMessage.
**Deprecated**
property version
readonly version: string;
Available for backward compatibility, renamed to [Client#connectedVersion]Client#connectedVersion.
**Deprecated**
property ws
readonly ws: any;
Available for backward compatibility, renamed to [Client#webSocket]Client#webSocket.
**Deprecated**
method connect
connect: (...args: any[]) => void;
Available for backward compatibility, please shift to using [Client#activate]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]Client#connectHeaders - connectCallback, see [Client#onConnect]Client#onConnect - errorCallback, see [Client#onStompError]Client#onStompError - closeEventCallback, see [Client#onWebSocketClose]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)
method disconnect
disconnect: (disconnectCallback?: any, headers?: StompHeaders) => void;
Available for backward compatibility, please shift to using [Client#deactivate]Client#deactivate.
**Deprecated**
See: [Client#onDisconnect]Client#onDisconnect, and [Client#disconnectHeaders]Client#disconnectHeaders
To upgrade, please follow the [Upgrade Guide](../additional-documentation/upgrading.html)
method send
send: ( destination: string, headers?: { [key: string]: any }, body?: string) => void;
Available for backward compatibility, use [Client#publish]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]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)
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)
class Stomp
class Stomp {}
property WebSocketClass
static WebSocketClass: any;
In case you need to use a non standard class for WebSocket.
For example when using within NodeJS environment:
StompJs = require('../../esm5/');Stomp = StompJs.Stomp;Stomp.WebSocketClass = require('websocket').w3cwebsocket;**Deprecated**
It will be removed in next major version. Please switch to Client using [Client#webSocketFactory]Client#webSocketFactory.
method client
static client: (url: string, protocols?: string[]) => CompatClient;
This method creates a WebSocket client that is connected to the STOMP server located at the url.
var url = "ws://localhost:61614/stomp";var client = Stomp.client(url);**Deprecated**
It will be removed in next major version. Please switch to Client using [Client#brokerURL]Client#brokerURL.
method over
static over: (ws: any) => CompatClient;
This method is an alternative to [Stomp#client]Stomp#client to let the user specify the WebSocket to use (either a standard HTML5 WebSocket or a similar object).
In order to support reconnection, the function Client._connect should be callable more than once. While reconnecting a new instance of underlying transport (TCP Socket, WebSocket or SockJS) will be needed. So, this function alternatively allows passing a function that should return a new instance of the underlying socket.
var client = Stomp.over(function(){return new WebSocket('ws://localhost:15674/ws')});**Deprecated**
It will be removed in next major version. Please switch to Client using [Client#webSocketFactory]Client#webSocketFactory.
class StompConfig
class StompConfig {}
Configuration options for STOMP Client, each key corresponds to field by the same name in Client. This can be passed to the constructor of Client or to [Client#configure]Client#configure.
Part of
@stomp/stompjs
.
property appendMissingNULLonIncoming
appendMissingNULLonIncoming?: boolean;
See [Client#appendMissingNULLonIncoming]Client#appendMissingNULLonIncoming.
property beforeConnect
beforeConnect?: (client: Client) => void | Promise<void>;
See [Client#beforeConnect]Client#beforeConnect.
property brokerURL
brokerURL?: string;
See [Client#brokerURL]Client#brokerURL.
property connectHeaders
connectHeaders?: StompHeaders;
See [Client#connectHeaders]Client#connectHeaders.
property connectionTimeout
connectionTimeout?: number;
See [Client#connectionTimeout]Client#connectionTimeout.
property debug
debug?: debugFnType;
See [Client#debug]Client#debug.
property discardWebsocketOnCommFailure
discardWebsocketOnCommFailure?: boolean;
See [Client#discardWebsocketOnCommFailure]Client#discardWebsocketOnCommFailure.
property disconnectHeaders
disconnectHeaders?: StompHeaders;
See [Client#disconnectHeaders]Client#disconnectHeaders.
property forceBinaryWSFrames
forceBinaryWSFrames?: boolean;
See [Client#forceBinaryWSFrames]Client#forceBinaryWSFrames.
property heartbeatIncoming
heartbeatIncoming?: number;
See [Client#heartbeatIncoming]Client#heartbeatIncoming.
property heartbeatOutgoing
heartbeatOutgoing?: number;
See [Client#heartbeatOutgoing]Client#heartbeatOutgoing.
property heartbeatStrategy
heartbeatStrategy?: TickerStrategy;
See [Client#heartbeatStrategy]Client#heartbeatStrategy.
property logRawCommunication
logRawCommunication?: boolean;
See [Client#logRawCommunication]Client#logRawCommunication.
property maxReconnectDelay
maxReconnectDelay?: number;
See [Client#maxReconnectDelay]Client#maxReconnectDelay
property maxWebSocketChunkSize
maxWebSocketChunkSize?: number;
See [Client#maxWebSocketChunkSize]Client#maxWebSocketChunkSize.
property onChangeState
onChangeState?: (state: ActivationState) => void;
See [Client#onChangeState]Client#onChangeState.
property onConnect
onConnect?: frameCallbackType;
See [Client#onConnect]Client#onConnect.
property onDisconnect
onDisconnect?: frameCallbackType;
See [Client#onDisconnect]Client#onDisconnect.
property onStompError
onStompError?: frameCallbackType;
See [Client#onStompError]Client#onStompError.
property onUnhandledFrame
onUnhandledFrame?: frameCallbackType;
See [Client#onUnhandledFrame]Client#onUnhandledFrame.
property onUnhandledMessage
onUnhandledMessage?: messageCallbackType;
See [Client#onUnhandledMessage]Client#onUnhandledMessage.
property onUnhandledReceipt
onUnhandledReceipt?: frameCallbackType;
See [Client#onUnhandledReceipt]Client#onUnhandledReceipt.
property onWebSocketClose
onWebSocketClose?: closeEventCallbackType<any>;
See [Client#onWebSocketClose]Client#onWebSocketClose.
property onWebSocketError
onWebSocketError?: wsErrorCallbackType<any>;
See [Client#onWebSocketError]Client#onWebSocketError.
property reconnectDelay
reconnectDelay?: number;
See [Client#reconnectDelay]Client#reconnectDelay.
property reconnectTimeMode
reconnectTimeMode?: ReconnectionTimeMode;
See [Client#reconnectTimeMode]Client#reconnectTimeMode
property splitLargeFrames
splitLargeFrames?: boolean;
See [Client#splitLargeFrames]Client#splitLargeFrames.
property stompVersions
stompVersions?: Versions;
See [Client#stompVersions]Client#stompVersions.
property webSocketFactory
webSocketFactory?: () => any;
See [Client#webSocketFactory]Client#webSocketFactory.
class StompHeaders
class StompHeaders {}
STOMP headers. Many functions calls will accept headers as parameters. The headers sent by Broker will be available as [IFrame#headers]IFrame#headers.
key
andvalue
must be valid strings. In addition,key
must not containCR
,LF
, or:
.Part of
@stomp/stompjs
.
class Versions
class Versions {}
Supported STOMP versions
Part of
@stomp/stompjs
.
constructor
constructor(versions: string[]);
Takes an array of versions, typical elements '1.2', '1.1', or '1.0'
You will be creating an instance of this class if you want to override supported versions to be declared during STOMP handshake.
property V1_0
static V1_0: string;
Indicates protocol version 1.0
property V1_1
static V1_1: string;
Indicates protocol version 1.1
property V1_2
static V1_2: string;
Indicates protocol version 1.2
property versions
versions: string[];
method protocolVersions
protocolVersions: () => string[];
Used while creating a WebSocket
method supportedVersions
supportedVersions: () => string;
Used as part of CONNECT STOMP Frame
Interfaces
interface IFrame
interface IFrame {}
It represents a STOMP frame. Many of the callbacks pass an IFrame received from the STOMP broker. For advanced usage you might need to access [headers]IFrame#headers.
Part of
@stomp/stompjs
.IMessage is an extended IFrame.
property binaryBody
readonly binaryBody: Uint8Array;
body as Uint8Array
property body
readonly body: string;
body of the frame as string
property command
command: string;
STOMP Command
property headers
headers: StompHeaders;
Headers, key value pairs.
property isBinaryBody
isBinaryBody: boolean;
Is this frame binary (based on whether body/binaryBody was passed when creating this frame).
interface IMessage
interface IMessage extends IFrame {}
Instance of Message will be passed to [subscription callback]Client#subscribe and [Client#onUnhandledMessage]Client#onUnhandledMessage. Since it is an extended IFrame, you can access [headers]IFrame#headers and [body]IFrame#body as properties.
Part of
@stomp/stompjs
.See [Client#subscribe]Client#subscribe for example.
property ack
ack: (headers?: StompHeaders) => void;
When subscribing with manual acknowledgement, call this method on the message to ACK the message.
See [Client#ack]Client#ack for an example.
property nack
nack: (headers?: StompHeaders) => void;
When subscribing with manual acknowledgement, call this method on the message to NACK the message.
See [Client#nack]Client#nack for an example.
interface IPublishParams
interface IPublishParams {}
Parameters for [Client#publish]Client#publish. Aliased as publishParams as well.
Part of
@stomp/stompjs
.
property binaryBody
binaryBody?: Uint8Array;
binary body (optional)
property body
body?: string;
body (optional)
property destination
destination: string;
destination end point
property headers
headers?: StompHeaders;
headers (optional)
property skipContentLengthHeader
skipContentLengthHeader?: boolean;
By default, a
content-length
header will be added in the Frame to the broker. Set it totrue
for the header to be skipped.
interface ITransaction
interface ITransaction {}
A Transaction is created by calling [Client#begin]Client#begin
Part of
@stomp/stompjs
.
property abort
abort: () => void;
Abort this transaction. See [Client#abort]Client#abort for an example.
property commit
commit: () => void;
Commit this transaction. See [Client#commit]Client#commit for an example.
property id
id: string;
You will need to access this to send, ack, or nack within this transaction.
interface StompSubscription
interface StompSubscription {}
Call [Client#subscribe]Client#subscribe to create a StompSubscription.
Part of
@stomp/stompjs
.
property id
id: string;
Id associated with this subscription.
property unsubscribe
unsubscribe: (headers?: StompHeaders) => void;
Unsubscribe. See [Client#unsubscribe]Client#unsubscribe for an example.
Enums
enum ActivationState
enum ActivationState { ACTIVE = 0, DEACTIVATING = 1, INACTIVE = 2,}
Possible activation state
enum ReconnectionTimeMode
enum ReconnectionTimeMode { LINEAR = 0, EXPONENTIAL = 1,}
Possible reconnection wait time modes
member EXPONENTIAL
EXPONENTIAL = 1
member LINEAR
LINEAR = 0
enum StompSocketState
enum StompSocketState { CONNECTING = 0, OPEN = 1, CLOSING = 2, CLOSED = 3,}
Possible states for the IStompSocket
enum TickerStrategy
enum TickerStrategy { Interval = 'interval', Worker = 'worker',}
Possible ticker strategies for outgoing heartbeat ping
Type Aliases
type closeEventCallbackType
type closeEventCallbackType<T = any> = (evt: T) => void;
This callback will receive a [CloseEvent]https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent as parameter.
Part of
@stomp/stompjs
.
type debugFnType
type debugFnType = (msg: string) => void;
This callback will receive a
string
as a parameter.Part of
@stomp/stompjs
.
type Frame
type Frame = IFrame;
Alias for IFrame
type frameCallbackType
type frameCallbackType = ((frame: IFrame) => void) | (() => void);
This callback will receive a IFrame as parameter.
Part of
@stomp/stompjs
.
type Message
type Message = IMessage;
Aliased to IMessage.
Part of
@stomp/stompjs
.
type messageCallbackType
type messageCallbackType = (message: IMessage) => void;
This callback will receive a IMessage as parameter.
Part of
@stomp/stompjs
.
type publishParams
type publishParams = IPublishParams;
Backward compatibility, switch to IPublishParams.
type wsErrorCallbackType
type wsErrorCallbackType<T = any> = (evt: T) => void;
This callback will receive an [Event]https://developer.mozilla.org/en-US/docs/Web/API/Event as parameter.
Part of
@stomp/stompjs
.
Package Files (12)
Dependencies (0)
No dependencies.
Dev Dependencies (19)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@stomp/stompjs
.
- Markdown[](https://www.jsdocs.io/package/@stomp/stompjs)
- HTML<a href="https://www.jsdocs.io/package/@stomp/stompjs"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 5909 ms. - Missing or incorrect documentation? Open an issue for this package.