Skip to Content
Phoenix Web Development
book

Phoenix Web Development

by Brandon Richey
April 2018
Beginner to intermediate content levelBeginner to intermediate
406 pages
9h 33m
English
Packt Publishing
Content preview from Phoenix Web Development

Creating our chat channel

To start implementing chat in our application, we'll need to start building out the chat channel and setting up all of the framework code necessary for us to support the new channel. We'll need to start by adding the new channel to lib/vocial_web/channels/user_socket.ex:

channel "chat:*", VocialWeb.ChatChannel

We don't actually have a Chat Channel module yet, so that will be the next file that we will have to start building up. In the same directory, we'll create a chat_channel.ex file and start it off with a simple channel skeleton:

defmodule VocialWeb.ChatChannel do  use VocialWeb, :channel  def join("chat:lobby", _payload, socket) do    {:ok, socket}  endend

We'll also have to refactor our JavaScript in the socket.js ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Phoenix in Action

Phoenix in Action

Geoffrey Lessel
Real-Time Phoenix

Real-Time Phoenix

Stephen Bussey

Publisher Resources

ISBN: 9781787284197Supplemental Content