Phoenix’ Channels

An article, posted more than 7 years ago filed in coherence, elixer, erlang, vm, authentication, Phoenix, framework, fast, messaging, rails, ActionCable & websockets.
Phoenix’ Channels

I started exploring Phoenix for one thing only: Channels (or actually fast real time communication over websockets). In this post I explore how to use them (yes this is a follow up of My first Phoenix-app-post).

Preparing for the authentication problem

Websockets don’t pass session cookies. Because we don't have access to these we need to transfer the user's identity in a different way. One of the recommendations I found was passing a user_token using a ``-tag (adjusting templates/layout/app.html.eex):

We can access this with a simple query selector in javascript:

document.querySelector("meta[name=user_token]").content

But that’s for later. Let’s move to the server side, since we need something to connect to, a Socket.

Socket

In our default project there is alrea…

Continue reading...

My first Phoenix app

An article, posted almost 8 years ago filed in coherence, elixer, erlang, vm, authentication, Phoenix, framework, fast, messaging & rails.

Some time ago I actually initiated my very first Phoenix app, but was a bit disappointed by the lack of a rich box of gems (like that of ruby's) and/or I didn't have the time to invest heavily in researching all the possibilities. One of my new year resolution was to actively pursue more knowledge, hence I'm giving it a second shot.

Why Phoenix?

I'm a full-stack Rails developer, but I needed real time messaging. That is not something Rails is typically good at (although it works), but Elixir (with its Erlang base) is well known for, even in the ruby community. Phoenix wraps Elixir in a nice Rails-like package ready for web and API development.

Requirements

  • Authentication
  • Broadcasting filtered messages based on tags
  • Writing messages

Preparation

  1. Install Elixir (macOS & homebrew: brew install elixir) and make sure you have [node.js](https://nodejs.or…

Continue reading...

murb blog