3

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
Matt R
  • 39
  • 1
  • 4
  • Your join function misspells payload and socket.assigns. Do you still get the same error if you fix those? – Alvin Lindstam Apr 19 '17 at 05:36
  • You don't seem to be using the default js client? How do you send the json to the server? How did you verify that you are connected and have a live socket server side? – Alvin Lindstam Apr 19 '17 at 05:39
  • @AlvinLindstam Those misspellings were from my transcription of the code, but I solved the issue and it was because I wasn't specifying my imports correctly. I send the json to the server through a Python script, and I think the fact that I'm getting an unmatched topic response would verify that I'm connected serverside. – Matt R Apr 20 '17 at 19:35

0 Answers0