【发布时间】:2017-06-01 20:58:33
【问题描述】:
我正在制作一个匹配 2 个用户的应用。我正在尝试使用 socket.assigns 将人 B 的电子邮件存储到人 A 的套接字,反之亦然。
当人 A 向频道发出请求时,我可以使用 assign(socket, :matched_client_email, "personB@email.com") 毫无问题地更新套接字。但是,我不知道如何向B人的频道广播,以便我可以拨打assign(socket, :matched_client_email, "personA@email.com")
def handle_in("find_match", %{ "app" => app }, socket) do
...
push socket, "match_found", %{
email: matched_user.email,
first_name: first_name(matched_user.name),
profile_image: matched_user.profile_image,
}
VideoChat.Endpoint.broadcast(
"user_pool:#{matched_user.email}",
"match_found",
%{
email: current_user.email,
first_name: first_name(current_user.name),
profile_image: current_user.profile_image,
}
)
...
{:noreply, socket}
end
# never gets called
def handle_out("match_found", %{ "email" => email }, socket) do
Logger.info("HEREEEE #{email}")
assign(socket, :matched_client_email, email)
{:noreply, socket}
end
如何从人 A 的频道向人 B 广播事件,以便调用 handle_in 方法?
【问题讨论】:
-
模块里有没有给
Phoenix.Channel.intercept/1打电话? -
oooo 不知道,让我试试
-
你知道
handle_in和handle_out之间的区别吗? -
成功了!!!!谢谢
标签: sockets elixir phoenix-framework