Establish a Client Connection

Let's understand how to write code for the client-side.

We'll cover the following

Client-side code

Our goal in this section is to write a client code that can invoke the join/3 function we now have on the server. There are a few steps to make that happen:

  • We need to define a client socket and use it to establish a connection to the socket on the server. Then, we need to define a new Channel object on the client, and use it to join the Channel on the server.

  • Phoenix ships with phoenix.js—a JavaScript file that knows all about working with sockets and Channels. It’s indispensable for writing JavaScript client code for Channels, and our first task is to make it available in the browser’s console window.

Get hands-on with 1200+ tech skills courses.