Browser and Web APIs

Exercise: WebSockets

The backend chat service provides WebSocket connections at wss://chat.distsys.ch/ws.
  1. Replace the renderMessages function with a renderMessage function that renders a single message, and update the fetchMessages function accordingly.
  2. Implement a receiveMessages function that establishes a WebSocket connection to the chat service and registers the following event handlers:
    • onopen sends the authentication token as the first message
    • onmessage renders the received chat message
  3. Remove the chat message polling and call the receiveMessages function instead.
  4. In the postMessage function, use the WebSocket connection to send the new chat message.