Implementing the WebSocket client
So far, you have created the course_chat_room
view and its corresponding template for students to access the course chat room. You have implemented a WebSocket consumer for the chat server and tied it with URL routing. Now, you need to build a WebSocket client to establish a connection with the WebSocket in the course chat room template and be able to send/receive messages.
You are going to implement the WebSocket client with JavaScript to open and maintain a connection in the browser, and you will interact with the Document Object Model (DOM) using JavaScript.
You will perform the following tasks related to the WebSocket client:
- Open a WebSocket connection with the server when the page is loaded.
- Add messages to an HTML container when data is received through the WebSocket.
- Attach a listener to the submit button to send messages through the WebSocket when the user clicks the SEND button or presses the Enter key. ...