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

Sending chat messages

To actually send chat messages back and forth things are going to be a bit more complicated than our voting code. We'll need to modify a little more of the code to allow this to work. In our assets/js/chat.js file, we'll need to add a few new utility functions. We'll need utility functions for:

  • Sending chat messages to the server
  • What to set up when we join the chat channel
  • A way to add messages to our ongoing list of chat messages

Sending chat messages to the server will be pretty simple overall, so we'll start with implementing that:

// Push a new message to the serverconst pushMessage = (channel, author, message) => {  channel    .push("new_message", { author, message }) .receive("ok", res => console.log("Message sent!")) ...
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