This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
Pure Elm state manager for Phoenix channels
version 2.2.0
license MIT
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 2.2.0
Committed At 2017-04-10 03:41:01 UTC
elm-lang/websocket 1.0.2 <= v < 2.0.0 1.0.2
elm-lang/core 5.0.0 <= v < 6.0.0 5.1.1



This library is a pure Elm interpretation of the Phoenix.Socket library that comes bundled with the Phoenix web framework. It aims to abstract away the more tedious bits of communicating with Phoenix, such as joining channels, leaving channels, registering event handlers, and handling errors.


Phoenix connections are stateful. The Socket module will manage all of this for you, but you need to add some boilerplate to your project to wire everything up.

  1. Import all three Phoenix modules

    import Phoenix.Socket
    import Phoenix.Channel
    import Phoenix.Push
  2. Add a socket to your model

    type alias Model =
      { phxSocket : Phoenix.Socket.Socket Msg
  3. Initialize the socket. The default path for Phoenix in development is "ws://localhost:4000/socket/websocket".

    init =
      { phxSocket = Phoenix.Socket.init "PATH_TO_SERVER"
  4. Add a PhoenixMsg tag to your Msg type

    type Msg
      = UpdateSomething
      | DoSomethingElse
      | PhoenixMsg (Phoenix.Socket.Msg Msg)
  5. Add the following to your update function

    PhoenixMsg msg ->
        ( phxSocket, phxCmd ) = Phoenix.Socket.update msg model.phxSocket
        ( { model | phxSocket = phxSocket }
        , PhoenixMsg phxCmd
  6. Listen for messages

    subscriptions : Model -> Sub Msg
    subscriptions model =
      Phoenix.Socket.listen model.phxSocket PhoenixMsg

Take a look at examples/Chat.elm if you want to see an example.


Pull requests and issues are greatly appreciated! If you think there's a better way to implement this library, I'd love to hear your feedback. I basically tried to model this library after the official javascript one, but that may not be the best approach.