Browser and Web APIs
Exercise: WebSockets
The backend chat service provides WebSocket connections at
wss://chat.distsys.ch/ws.
-
Replace the
renderMessages function with a renderMessage function that renders a single message, and update the fetchMessages function accordingly.
-
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
-
Remove the chat message polling and call the
receiveMessages function instead.
-
In the
postMessage function, use the WebSocket connection to send the new chat message.