The fully qualified url to your Phoenix socket endpoint.
Optional
queryParams: { [key: string]: string }Optional object of key/value pairs to be appended to the url as query parameters.
Optional
timeoutInMs: numberOptional timeout value in milliseconds, if not provided the default 60 second timeout will be used.
A callback to be called whenever the WebSocket successfully connects or reconnects.
A callback to be called whenever the WebSocket is disconnected.
The current status of the WebSocket connection.
Protected
nextAn array of all the topics you are currently successfully connected to. Does not include topics that have been disconnected, or that are in the process of connecting.
Attempt to open the websocket connection.
A promise which will resolve when the connection is successfully opened. If the websocket is already connected, this will resolve immediately.
Close the current websocket connection.
Optional
clearTopics: boolean = trueIf true, all topics will be unsubscribed from and removed as part of the disconnection. If false, the topics will remain subscribed to and will automatically be resubscribed to if the socket is reconnected.
Disconnects the websocket if it isn't already, and then cleans up event listeners.
This will also be called by PhoenixWebsocket's Symbol.dispose() if the using
keyword is preferred over explicitly calling dispose().
Protected
onOptional
event: CloseEventProtected
onProtected
onProtected
onSend a message and optional payload to the given topic.
The topic to send the message to. You must already be subscribed to this topic a topic before you can send a message to it.
The message to send.
Optional
payload: { [key: string]: any }An optional payload to be sent along with the message.
A promise which will resolve with the reply sent from the server.
Set the log level for this PhoenixWebsocket instance. If you would like nothing to be logged to the browser console, you can set this to PhoenixWebsocketLogLevels.Quiet.
When unchanged, this will log information connection and subscription status to the console by default.
The log level to use.
Subscribe to the passed in topic. This will attempt to subscribe immediately if the websocket connection is already open, otherwise it will try to subscribe once the connection is opened.
Optionally pass in a topicMessageHandler to handle incoming messages for the topic. If this is left undefined, then it is assumed you will only interact with the topic via messages and responses.
If an 'error' status is received from the server in response to the join request, then the promise will be reject with the payload of the error response.
The topic to subscribe to.
Optional
payload: { [key: string]: any }An optional payload object to be sent along with the join request.
Optional
messageHandlers: { [message: string]: TopicMessageHandler }An optional object containing mappings of messages to message handler callbacks, which are called when the given message is received.
Optional
reconnectHandler: (reconnectPromise: Promise<void>) => voidAn optional callback which will be called with the connection promise of any subsequent reconnection attempts (useful when, for example, you expect that a topic connection may or may not result in error, and you want to implement custom logic on these errors). Specifically will not be called with the initial connection Promise returned by this method.
Subscribe to the passed in topic. This will attempt to subscribe immediately if the websocket connection is already open, otherwise it will try to subscribe once the connection is opened.
Optionally pass in a topicMessageHandler to handle incoming messages for the topic. If this is left undefined, then it is assumed you will only interact with the topic via messages and responses.
If an 'error' status is received from the server in response to the join request, then the promise will be reject with the payload of the error response.
The topic to subscribe to.
Optional
payload: { [key: string]: any }An optional payload object to be sent along with the join request.
Optional
messageHandlers: Map<string, TopicMessageHandler>An optional object containing mappings of messages to message handler callbacks, which are called when the given message is received.
Optional
reconnectHandler: (reconnectPromise: Promise<void>) => voidAn optional callback which will be called with the connection promise of any subsequent reconnection attempts (useful when, for example, you expect that a topic connection may or may not result in error, and you want to implement custom logic on these errors). Specifically will not be called with the initial connection Promise returned by this method.
Unsubscribe from the passed in topic.
The topic to unsubscribe from.
Represents a connection instance to a Phoenix Sockets endpoint.