Chapter 12. Using Phoenix channels for real-time communication

 

This chapter covers

  • Making use of Phoenix’s real-time channels
  • Using channels to update an item’s bids in real time
  • Using Phoenix’s JavaScript helpers in association with channels

Believe it or not, this may be the most surprising chapter in the book. Not necessarily because of the content, but because of the disconnect between the perceived difficulty of real-time communication and updates and how easy Phoenix makes this with channels. I think it’s fair to say that in most books about web development, apart from Phoenix, covering a topic like this would take up multiple chapters and certainly would require more code than you’ll see here.

You’ll be using some JavaScript in this chapter, but only minimal knowledge will be required to follow along. Ready to get started? Let’s do it.

12.1. What are Phoenix channels?

You’ll use channels to update an item’s page with the current bid information. If another user enters a bid, the item’s page will be updated without your intervention to show that new bid. If you enter a new bid, that other user’s browser will reflect that bid without them (or the client) refreshing the web page.

12.2. Connecting a user to a channel and a topic

12.3. Sending real-time messages to a user

12.4. Updating all users when a new bid is made

Summary