Created
January 2, 2017 22:23
-
-
Save bdmac/7828c79d9d7fbbd080d0fcf4b8f5316c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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