You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Tiny module for Storeon which is adding functionality to work with WebSocket. This means that now you can send and receive events by WebSocket.
It is just 401 bytes module (it uses Size Limit to control the size) without any dependencies.
import{websocket}from'@storeon/websocket'consturl='ws://localhost:8080'conststore=createStoreon([/* all your modules */websocket(url)])// now all dispatched events will be send to server with address ws://localhost:8080
Installation
npm install @storeon/websocket
# or
yarn add @storeon/websocket
Second parameter is white list of events.
All events added to this array will be dispatched/sent.
typeinclude=Void|Array<String>
If no pass the include then all events will be dispatched/sent.
Third parameter is after how many millisecond try reconnect again if connection is lost (default 500):
typereconnectInterval=Void|Number
Fourth parameter is how often in millisecond module should check if connection is alive (default 2000):
typepingPongInterval=Void|Number
Only url is not optional parameter.
Server
The module is sending event like a string. So before sending it stringify all events.
After receiving message from server the module trying to parse this string to json with JSON.parse.
If received message is valid json then module dispatching it in storeon.
Each 2000 ms module send ping message to server and if server in 2000 ms doesn’t send back message pong
then module trying to reconnect to server.
If server close connection or send error then module trying to reconnect to server.
Example implementation of echo server please see in example.