Unmatched topic when I'm trying the channel example

I have a room_channel

defmodule AuthWeb.RoomChannel do
  use Phoenix.Channel

  def join("room", _message, socket) do
    {:ok, socket}
  end
  def join("room" <> _private_room_id, _params, _socket) do
    {:error, %{reason: "unauthorized"}}
  end
end

In the user socket I have room_channel

channel "room", AuthWeb.RoomChannel

In the socket.js file I have this

let channel = socket.channel("room", {})
channel.join()
  .receive("ok", resp => { console.log("Joined successfully", resp) })
  .receive("error", resp => { console.log("Unable to join", resp) })

export default socket

But when I’m doing this

wscat -c 'localhost:4000/phoenix/live_reload/socket/websocket?vsn=2.0.0'
Connected (press CTRL+C to quit)
> ["1", "1", "room", "phx_join", {}]
< [null,"1","room","phx_reply",{"response":{"reason":"unmatched topic"},"status":"error"}]

what am I missing here?

That looks like the phoenix_live_reload socket rather than your application socket.

1 Like

Yeah but I have defined this in my app.js file

import socket from "./socket"

Do I need anything else? Right now only one websocket its showing. Just didn’t realize that it was live_reload socket

I haven’t tested this one but it should be similar to this wscat -c ws://localhost:4000/socket

I’m getting 404 error

Can you try this one? wscat -c ws://localhost:4000/socket/websocket.

➜  senti git:(main) ✗ wscat -c ws://localhost:4000/socket/websocket
Connected (press CTRL+C to quit)

actually this doesn’t work. After that I tried this:

wscat -c 'ws://localhost:4000/socket/websocket?vsn=2.0.0'

After this I am able to connect with channel. Thanks for help