我正在尝试使用handle_info
跟踪加入用户的Presence
,但我注意到handle_info
永远不会被调用,尽管用户已成功加入并发送/接收消息..
defmodule App.UserChannel do
use App.Web, :channel
alias App.Presence
...
...
def handle_info(info, socket) do
IO.puts info
IO.puts "* * * "
{:ok, _} = Presence.track(socket, socket.assigns.user_id, %{
online_at: inspect(System.system_time(:seconds))
})
push socket, "presence_state", Presence.list(socket)
{:noreply, socket}
end
...
...
有什么想法吗?
在服务器端,在App.UserChannel
内,我如何知道某个用户是在线还是离线?
修改
我是否需要使用Elixir 1.3才能使Presence正常工作?我在Elixir 1.2.6,凤凰城(1.2.0-rc.1)
答案 0 :(得分:1)
你不需要Elixir 1.3,但在我在其他地方引用的关于这个问题(https://www.dailydrip.com/topics/elixir/drips/phoenix-presence-chat)的DailyDrip剧集中使用的例子中,我的连接函数有:
def join("room:lobby", msg, socket) do
send self, {:after_join, msg} # <---
{:ok, socket}
end
如果你没有,那就可以解释所提到的行为。