I'm currently writing an instant messaging server on Phoenix version 1.2.1 and Elixir 1.4.1 and running into an issue involving channels. I started the project with --no-html and --no-brunch if that affects anything.
when I attempt to send this JSON string to the server:
{ "topic": "mailbox:tom"
, "event": "join"
, "payload": {"hello": "world"}
, "ref": 1234}
I get Ignoring unmatched topic "mailbox:tom" in InstantMessenger.UserSocket
from the command prompt. Now my first thought was to check my user_socket.ex file but I wrote channel "mailbox:*", InstantMessenger.MailboxChannel
which according to the docs should match. I have no clue what could be wrong at this point to be honest so any help would be appreciated.
the code from my endpoint.ex file is:
socket "/socket" InstantMessenger.UserSocket
and from my user_socket.ex:
channel "mailbox:*", InstantMessenger.MailboxChannel
transport :websocket, Phoenix.Transports.WebSocket
def connect(params, socket) do
{:ok, assign(socket, :user_id, params["user_id"])}
end
def id(socket), do: "user_id#{socket.assigns.user_id}"
the join function from mailbox_channel.ex is
def join("mailbox:" <> user_id, payload, socket) do
if authorized?(paylload) && socket.assgns.user_id == user_id do
set_user_to_active(user_id)
{:ok, socket}
else
{:error, %{reason: "unauthorized"}}
end
end