Getting the messages
For both the general and the secret messages pages, we are going to be getting the same data. We are going to use RxJS to create an observable that wraps getting a single message back from the server as well as getting all currently sent messages back from the server.
Depending on the room string that's passed in, the GetMessages method joins either a secret room, just for logged in users, or the general room, available to all users. Having joined the room, we return an Observable instance where, on a particular event, we react. In the case of receiving the single message, we call the Observable instance's next method. This will be subscribed to by the client component, which will write this out. Similarly, we also subscribe ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access