zapnito / elm-phoenix

An Elm client for Phoenix Channels

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

elm-phoenix

An Elm client for Phoenix Channels.

This package makes it easy to connect to Phoenix Channels, but in a more declarative manner than the Phoenix Socket Javascript library. Simply provide a Socket and a list of Channels you want to join and this library handles the unpleasent parts like opening a connection, joining channels, reconnecting after a network error and managing replies.

Getting Started

Declare a socket you want to connect to and the channels you want to join. The effect manager will open the socket connection, join the channels. See Phoenix.Socket and Phoenix.Channel for more configuration details.

import Phoenix
import Phoenix.Socket as Socket
import Phoenix.Channel as Channel

type Msg = NewMsg Value | ...

socket =
    Socket.init "ws://localhost:4000/socket/websocket"

channel =
    Channel.init "room:lobby"
        -- register an handler for messages with a "new_msg" event
        |> Channel.on "new_msg" NewMsg

subscriptions model =
    Phoenix.connect socket [channel]

Example

A simple example chat application can be found here.

Installation:

Since this package is an effect manager it is at the moment not aviable via elm package. Thus the recommended way to install the package is to simply clone the project and to specify the relative path to the project in the elmBrunch part of the the brunch-config.js (example).

About

An Elm client for Phoenix Channels

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Elm 65.9%Language:Elixir 27.4%Language:JavaScript 5.4%Language:HTML 1.2%