Skip to content

Instantly share code, notes, and snippets.

@bdmac
Created January 2, 2017 22:23
Show Gist options
  • Save bdmac/7828c79d9d7fbbd080d0fcf4b8f5316c to your computer and use it in GitHub Desktop.
Save bdmac/7828c79d9d7fbbd080d0fcf4b8f5316c to your computer and use it in GitHub Desktop.
defmodule Jeangrey.PrivateBusinessUpdatesChannel do
use Jeangrey.Web, :channel
alias Jeangrey.Presence # <- Added this alias
def join("private-business-updates:" <> id....) do
# Existing code to authorize connection omitted...
....
send(self, :after_join) # <- Added this
{:ok, socket}
....
end
# New function
def handle_info(:after_join, socket) do
push socket, "presence_state", Presence.list(socket)
{:ok, _} = Presence.track(socket, socket.assigns.user_id, %{
online_at: inspect(System.system_time(:seconds))
})
{:noreply, socket}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment