To implement the features we described before, we will use a simple architecture, and we will need only three files on our source code.
The first one is the
index.js file containing the initialization of our WebSocket server and receiving the messages from the chat users; the data from each user will be implemented as an observable. All data passed through this observable will call the service responsible for that message, and the attribute
service of each message will contain the name of the service.
All services are going to be implemented in a single file, called
services.js; each service in this file might return an observable and, in the case of an observable being returned, our client will start to listen to messages from that observable. Initially we will have only four services:
sendMessage(): This service sends message to the connected clients; it can be a private message or a broadcast message. The attribute of the message will contain the receiver of...