Real Time Phoenix Errata P17: Getting first sample working with Phoenix 1.6.x

Skimming ahead, much of the following is explained in Chapter 3, but new readers (like me!) will hit a roadblock in Chapter 2 with their first app not working without making some changes under the latest versions of Phoenix.

mix phx.new hello_sockets --no-ecto --no-live --no-dashboard --no-mailer
cd hello_sockets
mix phx.gen.channel Ping

Permit the generator to create the default socket handler, and follow the instructions to add it to the HelloSocketsWeb.Endpoint module. Also follow the instructions to import user_socket.js by uncommenting the line in assets/js/app.js.

Inside assets/js/user.socket.js, change the name of the channel being joined from “room:42” to “ping”.

Inside HelloSocketsWeb.PingChannel, change the first parameter of join/3 from “ping:lobby” to “ping”.

Inside HelloSocketsWeb.PingChannel, change the channel named “ping:*” to “ping”

In another thread, the author suggests pinning the version of Elixir and Phoenix so as to match the book. But I think it’s important that readers have confidence that they can immediately apply what they learn from this book in their own projects using the latest version of Phoenix.

I took the decision to add the “–no-live” flag when creating the Phoenix app in case having LiveView integrated made things more confusing. In previous versions of Phoenix, one had to explicitly add LiveView; now it comes as a default without the flag.

2 Likes