The type of messages, that will be consumed by WebSocketController.send and WebSocketController.request methods.
The type, of messages, that will be produced by WebSocketController.messages$ observable.
Must be ArrayBuffer
, Blob
or string
.
The result of the serializer function and a parameter of the deserializer.
It is supposed that you send only messages of this type through the underlying WebSocket.
DO NOT COMBINE "string", "arraybuffer" and "blob": it is not supported.
(even that original WebSocket supports).
If you send binary data, send ONLY binary data. If you send text frames, send ONLY text frames.
A WebSocket constructor to use.
If passed, an authorization message will be sent whenever the socket opens. When not passed, socket state transition opened->authorized still happens, but instant.
Authorization request MUST have a response.
Creates a request, after which the socket will be authorized. Response to this request is emitted into WebSocketController.authorized$ and WebSocketController.messages$ observables.
If no value is returned, the socket is closed and not reopened.
Helps to determine if the authorization completed successfully. If not passed, any response is considered successful.
param for the auth response.
Sets the binaryType
property of the underlying WebSocket.
if UnderlyingDataType type param is set to be string
, and you communicate with server through text frames,
this parameter does not matter.
If UnderlyingDataType type param is set to be Blob
, binaryType must be 'blob'
.
If set to be ArrayBuffer
, binaryType must be 'arraybuffer'
Helps to preserve messages, when reconnection happens. When the message comes, but the socket is not ready
to consume it, the message goes to the buffer and being sent later, when the socket is ready.
The buffer is enabled by default.
If the message was dropped from the buffer (because of the overflow), the observable returned by
the WebSocketController.request function throws RxJs TimeoutError
Note, there are different buffers for authorized messages, subscribed messages,
and for messages that don't require eiter.
If set to the dropOld
, the new message will replace the oldest one, when there is no space left.
dropNew
- the newest one.
Default is defaultWebSocketBufferOverflow.
The size of both authorized and unauthorized buffers of messages. Zero means no buffer, the message will be dropped immediately, if it could not be sent.
Default is defaultWebSocketMessageBufferSize.
The protocol to use to connect, passed directly to a WebSocket constructor
If there is no response during requestTimeout
after sending the request, the rxjs TimeoutError
is
thrown into observable.
Default is defaultRequestTimeout
This param is used when your socket starts sending updates of some data only after you ask it for. To tell server, that you need regular updates, you send a subscribe request. To tell that you don't, you send unsubscribe request. Updates will be handled as ordinary messages - passed to the WebSocketController.messages$ observable.
When not passed, socket state transition authorized->subscribed still happens, but instant. Subscription requests MUST have a response.
Creates a request array, after sending every request of which the socket will be subscribed. Array of responses to these requests is emitted into the WebSocketController.subscribed$ observable and every response from array is emitted into WebSocketController.messages$ observables one by one.
A response on the message, created by the authorize.createRequest
.
If no authorizeIsResponseSuccessful
was provided, authResponse will be null.
if no value is returned, the socket is closed and not reopened.
Helps to determine if the subscription completed successfully. If not passed, any response is considered successful. Will be called for every subscribe response.
param for the auth response.
The url of the socket server to connect to, passed directly to a WebSocket constructor
Function to be called on every message, received by "onmessage" handler of underlying socket. If not stated, ResponseType must be equal to the UnderlyingDataType. If you want to communicate through JSON, pass JSON.parse method here.
The whole event, in case you need not only data.
Gets an id which helps find a corresponding request message.
A message to get id from.
If provided, WebSocketController.request will error with the response, when this function returns true on the response.
Function to be called on every message, passed to the WebSocketController.send method. If not stated, RequestType must be equal to the UnderlyingDataType. If you want to communicate through JSON, pass JSON.stringify method here.
A message to be serialized into UnderlyingDataType
Sets an id which helps find a corresponding response message.
A message to set the id to.
The number to be set. if getResponseId(message) === id, the message is considered response
Generated using TypeDoc
This interface describes websocket behaviour, serialization, deserialization, authorization, subscriptions etc. The auto reconnect settings are passed to the WebSocketController.open method.
It is supposed that you usually communicate with a server using request-response pattern. So every message being sent have an id and corresponding response have the exact same id. To delegate the control over id's, you pass WebSocketControllerConfig.setRequestId function, which transforms your message, so it has the id set, and you pass WebSocketControllerConfig.getResponseId function, to get response id. If you do not want to set id on a request message, you can use options param of the WebSocketController.send method.
The id must be number. If you need to use a string or something else, transform this number to the string in the set function, and back to the number in the get function.
Usage
TODO: how to use.