Chat using websocket native from NodeJS, actually implementing websocket to NodeJS using native . by romariobs
- Install Docker (https://docs.docker.com/install/)
- Install docker-compose (https://docs.docker.com/compose/install/)
- Start application with
docker-compose up --build
and wait... - Open the browser and enter the URL
http://localhost:3000
- Now you can use a simple UI with the websocket connected.
In this code we have a server with the capacity to send and receive messages through websockets. Over here you will encounter the following type messages:
- MSG_TO: When you send a message to someone in a channel: {'type': 'MSG_TO', 'message': '', 'from': 'USER', 'to': 'SOMEONE'}
- MSG_ALL: You will send a message to everyone in the channel: {'type': 'MSG_ALL', 'message': '', 'from': 'USER', 'to': ''}
- MSG_PM_TO: You will send a privately message to a user: {'type': 'MSG_PM_TO', 'message': '', 'from': 'USER', 'to': 'SOMEONE'}
- USER_CREATE: Try to join a new user to the channel: {'type': 'USER_CREATE', 'user': 'newUser'}
- USER_EXIT: User opt to exit from chat. {'type': 'USER_EXIT'}