NgxsWebsocketPluginModuleplugin to your root app module:
url: Url of the web socket connection. Can be passed here or by the
typeKey: Object property that maps the web socket message to a action type. Default:
serializer: Serializer used before sending objects to the web socket. Default:
deserializer: Deserializer used for messages arriving from the web socket. Default:
messagesstate where we store our chat messages:
SendWebSocketMessagewith the payload that you want to send to the server. Let's try it out:
messageevent. For example, the server code could be as follows:
typeproperty on server side, otherwise you will get an error -
Type ... not found on message. If you don't want to use a property called
typeas the key then you can specify your own property name when calling
ConnectWebSocketaction. This will typically happen at startup or if you need to authenticate before, after authentication is done. You can optionally pass the URL here.
ConnectWebSocket: Dispatch this action when you want to init the web socket. Optionally pass URL here.
DisconnectWebSocket: Dispatch this Action to disconnect a web socket.
WebSocketConnected: Action dispatched when a web socket is connected.
WebSocketDisconnected: Action dispatched when a web socket is disconnected. Use its handler for reconnecting.
SendWebSocketMessage: Send a message to the server.
WebsocketMessageError: Action dispatched by this plugin when an error ocurrs upon receiving a message.
WebSocketConnectionUpdated: Action dispatched by this plugin when a new connection is created on top of an existing one. Existing connection is closing.
typeproperty (or another key that you can provide in the
typeKeyproperty when calling
forRoot). This plugin will receive a message from the server and dispatch the message as an action with the corresponding
typevalue. If the
typeproperty doesn't match any client-side
@Actionmethods (with an Action with the corresponding
static typeproperty value) then no State will respond to the message.