Skip to content

maxbeizer/nodevember_chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NodevemberChat

Requirements

Steps

Part I

$ mix phoenix.new nodevember_chat --no-ecto
$ iex -S mix phoenix.server

Part II

Uncomment channel macro in web/channels/user_socket.ex to send "rooms:*" messages to the RoomChannel.

Part III

Add RoomChannel to web/channels and define a the join function

defmodule NodevemberChat.RoomChannel do
  use Phoenix.Channel

  def join("rooms:lobby", _message, socket) do
    {:ok, socket}
  end
end

Part IV

Ensure that socket.js gets loaded and tell the socket to join the "rooms:lobby" channel/topic. Note the live code reloading and the join log in the console.

Part V

Add jQuery and markup for chat. Add JS to push to channel and receive events from channel.

Part VI

Add the handle_in function in the RoomChannel to broadcast message to clients. Also add the handle_out function for fun.

You could also broadcast to the chat from Iex via the Endpoint:

NodevemberChat.Endpoint.broadcast! "rooms:lobby", "new_msg", %{body: "from Iex"}

Part VII

Add the secret_key_base: System.get_env("SECRET_KEY_BASE") to config/prod.exs and remove call to the config/prod.secret.exs call at the bottom of that file.

$ heroku apps:create nodevemberchat --buildpack https://github.com/hashnuke/heroku-buildpack-elixir
$ heroku buildpacks:add https://github.com/gjaldon/heroku-buildpack-phoenix-static.git
$ heroku config:set SECRET_KEY_BASE=somesecretkey
$ git push heroku master
$ herok apps:open

To start your Phoenix app:

  1. Install dependencies with mix deps.get
  2. Start Phoenix endpoint with mix phoenix.server

Now you can visit localhost:4000 from your browser.

Ready to run in production? Please check our deployment guides.

Learn more

About

An example chat application for Nodevember

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published