consolidated/stompjs/src/client.ts
STOMP Client Class.
Part of @stomp/stompjs
.
Properties |
|
Methods |
|
Accessors |
constructor(conf: StompConfig)
|
||||||
Defined in consolidated/stompjs/src/client.ts:389
|
||||||
Create an instance.
Parameters :
|
Public appendMissingNULLonIncoming |
Type : boolean
|
Default value : false
|
Defined in consolidated/stompjs/src/client.ts:190
|
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
|
Defined in consolidated/stompjs/src/client.ts:270
|
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
|
Defined in consolidated/stompjs/src/client.ts:45
|
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
|
Defined in consolidated/stompjs/src/client.ts:204
|
Connection headers, important keys - |
Public connectionTimeout |
Type : number
|
Default value : 0
|
Defined in consolidated/stompjs/src/client.ts:85
|
Will retry if Stomp connection is not established in specified milliseconds. Default 0, which switches off automatic reconnection. |
Public debug |
Type : debugFnType
|
Defined in consolidated/stompjs/src/client.ts:341
|
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
|
Defined in consolidated/stompjs/src/client.ts:351
|
Browsers do not immediately close WebSockets when |
Public forceBinaryWSFrames |
Type : boolean
|
Default value : false
|
Defined in consolidated/stompjs/src/client.ts:178
|
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
|
Defined in consolidated/stompjs/src/client.ts:125
|
Incoming heartbeat interval in milliseconds. Set to 0 to disable. |
Public heartbeatOutgoing |
Type : number
|
Default value : 10000
|
Defined in consolidated/stompjs/src/client.ts:130
|
Outgoing heartbeat interval in milliseconds. Set to 0 to disable. |
Public heartbeatStrategy |
Type : TickerStrategy
|
Default value : TickerStrategy.Interval
|
Defined in consolidated/stompjs/src/client.ts:147
|
Outgoing heartbeat strategy. See https://github.com/stomp-js/stompjs/pull/579 Can be worker or interval strategy, but will always use 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 When used in a JS environment, use 'worker' or 'interval' as valid values. Defaults to |
Public logRawCommunication |
Type : boolean
|
Defined in consolidated/stompjs/src/client.ts:326
|
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 maxReconnectDelay |
Type : number
|
Default value : 15 * 60 * 1000
|
Defined in consolidated/stompjs/src/client.ts:106
|
Maximum time to wait between reconnects, in milliseconds. Defaults to 15 minutes. Only relevant when Client#reconnectTimeMode not LINEAR (e.g., EXPONENTIAL). Set to 0 for no limit on wait time. |
Public maxWebSocketChunkSize |
Type : number
|
Default value : 8 * 1024
|
Defined in consolidated/stompjs/src/client.ts:168
|
See splitLargeFrames.
This has no effect if splitLargeFrames is |
Public onChangeState |
Type : function
|
Defined in consolidated/stompjs/src/client.ts:374
|
It will be called on state change. When deactivating, it may go from ACTIVE to INACTIVE without entering DEACTIVATING. |
Public onConnect |
Type : frameCallbackType
|
Defined in consolidated/stompjs/src/client.ts:278
|
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
|
Defined in consolidated/stompjs/src/client.ts:291
|
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
|
Defined in consolidated/stompjs/src/client.ts:300
|
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
|
Defined in consolidated/stompjs/src/client.ts:247
|
Public onUnhandledMessage |
Type : messageCallbackType
|
Defined in consolidated/stompjs/src/client.ts:231
|
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
|
Defined in consolidated/stompjs/src/client.ts:240
|
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
|
Defined in consolidated/stompjs/src/client.ts:308
|
Callback, invoked when underlying WebSocket is closed. Actual CloseEvent is passed as parameter to the callback. |
Public onWebSocketError |
Type : wsErrorCallbackType
|
Defined in consolidated/stompjs/src/client.ts:316
|
Callback, invoked when underlying WebSocket raises an error. Actual Event is passed as parameter to the callback. |
Public reconnectDelay |
Type : number
|
Default value : 5000
|
Defined in consolidated/stompjs/src/client.ts:93
|
automatically reconnect with delay in milliseconds, set to 0 to disable. |
Public reconnectTimeMode |
Type : ReconnectionTimeMode
|
Default value : ReconnectionTimeMode.LINEAR
|
Defined in consolidated/stompjs/src/client.ts:120
|
Reconnection wait time mode, either linear (default) or exponential. Note: See Client#maxReconnectDelay for setting the maximum delay when exponential |
Public splitLargeFrames |
Type : boolean
|
Default value : false
|
Defined in consolidated/stompjs/src/client.ts:162
|
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
|
Defined in consolidated/stompjs/src/client.ts:387
|
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
|
Defined in consolidated/stompjs/src/client.ts:56
|
STOMP versions to attempt during STOMP handshake. By default, versions Example: |
Public webSocketFactory |
Type : | undefined
|
Defined in consolidated/stompjs/src/client.ts:79
|
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 abort | ||||||
abort(transactionId: string)
|
||||||
Defined in consolidated/stompjs/src/client.ts:895
|
||||||
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)
|
||||||||||||||||
Defined in consolidated/stompjs/src/client.ts:914
|
||||||||||||||||
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()
|
Defined in consolidated/stompjs/src/client.ts:445
|
Initiate the connection with the broker. If the connection breaks, as per Client#reconnectDelay, it will keep trying to reconnect. If the Client#reconnectTimeMode is set to EXPONENTIAL it will increase the wait time exponentially Call Client#deactivate to disconnect and stop reconnection attempts.
Returns :
void
|
Public begin | ||||||
begin(transactionId?: string)
|
||||||
Defined in consolidated/stompjs/src/client.ts:860
|
||||||
Start a transaction, the returned ITransaction has methods - commit and abort.
Parameters :
Returns :
ITransaction
|
Public commit | ||||||
commit(transactionId: string)
|
||||||
Defined in consolidated/stompjs/src/client.ts:878
|
||||||
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)
|
||||||
Defined in consolidated/stompjs/src/client.ts:421
|
||||||
Update configuration.
Parameters :
Returns :
void
|
Public Async deactivate | ||||||||
deactivate(options: literal type)
|
||||||||
Defined in consolidated/stompjs/src/client.ts:644
|
||||||||
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()
|
Defined in consolidated/stompjs/src/client.ts:700
|
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)
|
||||||||||||||||
Defined in consolidated/stompjs/src/client.ts:937
|
||||||||||||||||
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)
|
||||||
Defined in consolidated/stompjs/src/client.ts:749
|
||||||
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)
|
||||||||||||||||
Defined in consolidated/stompjs/src/client.ts:826
|
||||||||||||||||
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)
|
||||||||||||
Defined in consolidated/stompjs/src/client.ts:848
|
||||||||||||
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)
|
|||||||||
Defined in consolidated/stompjs/src/client.ts:796
|
|||||||||
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
|
webSocket |
getwebSocket()
|
Defined in consolidated/stompjs/src/client.ts:195
|
Underlying WebSocket instance, READONLY.
Returns :
IStompSocket | undefined
|
disconnectHeaders | ||||||
getdisconnectHeaders()
|
||||||
Defined in consolidated/stompjs/src/client.ts:209
|
||||||
Disconnection headers.
Returns :
StompHeaders
|
||||||
setdisconnectHeaders(value: StompHeaders)
|
||||||
Defined in consolidated/stompjs/src/client.ts:213
|
||||||
Parameters :
Returns :
void
|
connected |
getconnected()
|
Defined in consolidated/stompjs/src/client.ts:252
|
Returns :
boolean
|
connectedVersion |
getconnectedVersion()
|
Defined in consolidated/stompjs/src/client.ts:356
|
version of STOMP protocol negotiated with the server, READONLY
Returns :
string | undefined
|
active |
getactive()
|
Defined in consolidated/stompjs/src/client.ts:365
|
if the client is active (connected or going to reconnect)
Returns :
boolean
|