HTML5 Web APIs
Exercise: WebSockets
The backend chat service provides a
WebSocket API at the URL
wss://chat.distsys.ch
. After having connected, a client receives event messages when a user's state changes or a message is sent.
- Use the JavaScript file store.js to store the fetched users and messages locally.
- Implement
subscribeUsers
and subscribeMessages
functions that connect to the corresponding WebSocket channels and update the local users and messages when event messages are received.
- Invoke the two subscription functions after having fetched the existing users and messages.
- Remove the polling mechanisms in the users and messages components.