Sending messages on the socket

For us to be able to start sending messages and continue testing the overall functionality of our channels, we'll need some sort of input from the user to initiate the message across. To do that, we'll just add a dummy button to the page that allows us to ping the server from the client across the WebSocket. Add the following button code to that same template:

<button id="polls-ping" class="btn btn-primary">Ping Websocket</button>

We'll next need to hop back over to socket.js and add a new few lines of code that will be responsible for hooking this button up to be able to broadcast something out to the server. Open up assets/js/socket.js and add this to the bottom of the conditional (the enable-polls-channel ...

Get Phoenix Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.