/pusher_client

A websocket client to work with Pusher

Primary LanguageElixirMIT LicenseMIT

PusherClient Build Status

Websocket client to Pusher service

Usage

iex> {:ok, pid} = PusherClient.start_link("ws://localhost:8080", "app_key", "secret", stream_to: self)
{:ok, #PID<0.134.0>}
iex> PusherClient.subscribe!(pid, "channel")
:ok
iex> PusherClient.subscribe!(pid, "presence-channel", %PusherClient.User{id: "123", info: %{a: "b"}})
:ok
# self will receive messages like this:
%{channel: nil,
  data: %{"activity_timeout" => 120,
    "socket_id" => "b388664a-3278-11e4-90df-7831c1bf9520"},
  event: "pusher:connection_established"}

%{channel: "channel", data: %{}, event: "pusher:subscription_succeeded"}

That's it!

You can disconnect too:

iex> PusherClient.disconnect!(pid)
:stop