我正在创建一个匹配2个用户的应用。我正在尝试使用socket.assigns
将Person B的电子邮件存储到Person 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
如何从Person A的频道向Person B广播一个事件,以便调用handle_in
方法?
答案 0 :(得分:1)
您需要使用您希望handle_out
调用的事件列表来调用Phoenix.Channel.intercept/1
。在您的情况下,您应该添加:
intercept ["match_found"]