Hi guys,
Well i face this, dont know whether its an actual issue or not. Please explain this.
Initially the socket gets connected with the token passed, using that socket i have initialised UserChat. Now suddenly after few functionalities, sockets are refused connection.
They get connected and trying to reconnect again without token and got refused. What is going on. Please explain this.
[info] CONNECTED TO MyApp.UserSocket in 325µs
Transport: :websocket
Serializer: Phoenix.Socket.V2.JSONSerializer
Connect Info: %{}
Parameters: %{"token" => "SFMyNTY.g3QAAAACZAAEZGF0YWEBZAAGc2lnbmVkbgYALIZirm8B.bf7HXYzDMLRtWboqTxu5ewhrNFrT9loL2YHkuREm-zU", "vsn" => "2.0.0"}
[info] CONNECTED TO Phoenix.LiveView.Socket in 255µs
Transport: :websocket
Serializer: Phoenix.Socket.V2.JSONSerializer
Connect Info: %{session: nil}
Parameters: %{"vsn" => "2.0.0"}
:invalid
[info] REFUSED CONNECTION TO MyApp.UserSocket in 266µs => Getting refused again and again,
Transport: :websocket
Serializer: Phoenix.Socket.V2.JSONSerializer
Connect Info: %{}
Parameters: %{"token" => "", "vsn" => "2.0.0"}
:invalid => reponse from below method
def connect(%{"token" => token}, socket, _connect_info) do
case Phoenix.Token.verify(socket, "user socket", token, max_age: 1209600) do
{:ok, user_id} ->
{:ok, assign(socket, :current_user, user_id)}
{:error, reason} ->
IO.inspect reason
:error
end
end
How to resolve this “refused connection”,
[info] REFUSED CONNECTION TO MyApp.UserSocket in 266µs =>
Getting refused again and again,
socket.js
import {Socket} from "phoenix"
let socket = new Socket("/socket", {params: {token: window.userToken}})
socket.connect()
export default socket
i followed https://elixircasts.io/multiple-room-chat-application
app.js
import socket from "./socket"
import liveSocket from "./live_socket"
import UserChat from "./user_chat"
UserChat.init(socket)
It will be very helpful if someone explains this. Thanks again