Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

SimpleChat

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.

 	const webSocket = Singleton.getInstance();
	const receive = (onMessageCb) => {
		webSocket.onmessage = (event) => onMessageCb(JSON.parse(event.data));
	};

	const send = (type, payload) =>
	webSocket.send(JSON.stringify({ type, payload }));
	webSocket.onopen = () => resolve({ send, receive });
	webSocket.onclose = () => { 
		webSocket.close();
		reject(new Error("WebSocket Closed"));
	}          
	...
  	const middleware=[thunkMiddleware.withExtraArgument({ send }), logger];
  	const store = createStore(
    		rootReducer,
    		initialState,
    		applyMiddleware(...middleware),
  	);
  	receive(store.dispatch);

About

Simple React/Redux Node Websocket chat server and client

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages