Simple React Node Websocket chat server and client
The WebSocket API is an advanced technology that makes it possible to open a two-way interactive communication session between the user's browser and a server. With this API, you can send messages to a server and receive event-driven responses without having to poll the server for a reply.
This appliction integrates with redux by passing a thunk to the onmessage recieve function.
constwebSocket=Singleton.getInstance();constreceive=(onMessageCb)=>{webSocket.onmessage=(event)=>onMessageCb(JSON.parse(event.data));};constsend=(type,payload)=>webSocket.send(JSON.stringify({ type, payload }));webSocket.onopen=()=>resolve({ send, receive });webSocket.onclose=()=>{webSocket.close();reject(newError("WebSocket Closed"));}...constmiddleware=[thunkMiddleware.withExtraArgument({ send }),logger];conststore=createStore(rootReducer,initialState,applyMiddleware(...middleware),);receive(store.dispatch);