ngxs / store

🚀 NGXS - State Management for Angular
http://ngxs.io
MIT License
3.53k stars 399 forks source link

expose WebSocketConnected WebSocketDisconnected for websocket-plugin #508

Closed xmlking closed 5 years ago

xmlking commented 6 years ago

As discussed here: https://github.com/ngxs/store/issues/503#event-1738178984 we need WebSocketConnected WebSocketDisconnected events published to action stream so that users can react to those events.

usecase

  1. when WebSocket Connected successfully, we want to trigger some initialization actions like Authentication , Data load etc.
  2. when WebSocket Disconnected, we may want to re-establish connection or notify user to login etc.
markwhitfeld commented 5 years ago

@xmlking Do you want to work on a PR for this?

kwalski commented 5 years ago

I am also trying to figure out how to check the connection status of Websocket (and retry if disconnected). @xmlking do you have any PR in progress or any ideas how to do this?

xmlking commented 5 years ago

sure will create a PR. would you like to name it as socketio-plugin ? I have full working minimal demo here https://github.com/xmlking/connect4

source : https://github.com/xmlking/ngx-starter-kit/tree/develop/libs/socketio-plugin

kwalski commented 5 years ago

@xmlking ngxs websocket plugin uses rxjs websocket under the hood, I am curious why you used socket.io client? Was it a dependency of your backend?

xmlking commented 5 years ago

I am using nestjs as my backend which default to socket.io for websocket implementation. Most of node community using socket.io for WS implementation, so I have to implement this plugin. We can back port features I added to original ws-plugin if make sense.

splincode commented 5 years ago

Fixed since 3.4.0