To implement our server, we need to implement the three parts of our system described in the previous example. We will first create our data source, then our WebSocket server, and finally our services and their tests.
Implementing the server
DataSource
As we have no interest in keep the history of messages nor in implementing a login for our server (the users are going to just type a name and this name will be used), we can use a simple observable to implement our DataSource; this DataSource will contain only the messages sent from user to user and broadcast messages.
Our DataSource must have two methods: the first to push new messages, and the second to listen to incoming messages. We can use a RxJS Subject to implement this behavior as it lets us push data to our...