websocketelixirphoenix-frameworkcowboyphoenix-channels

random extra websocket connection to phoenix app?


Simple user websocket with a single channel. I copied this code word for almost out of the how to section in the phoenix guidelines.

enter image description here

The first request is mine - it contains the user auth token from a facebook login response. As you can see this comes from phoenix.js file and it works just fine... I am able to send and receive messages - no problem.

The second seems to be coming from somewhere else entirely and I have no clue why!?

frame.js which is not a file of mine, so must be part of some sort of node_module dependancy, The js is condensed into one line and not exactly legible.

I also get this in the logs every 5 seconds or so:

phoenix_1  | [info] CONNECT GametimeWeb.UserSocket
phoenix_1  |   Transport: :websocket
phoenix_1  |   Connect Info: %{}
phoenix_1  |   Parameters: %{"token" => "", "vsn" => "2.0.0"}
phoenix_1  | :invalid - this is the response the socket returns I have jsut inspected it and printed to logs.
phoenix_1  | [debug] invalid
phoenix_1  | [info] Replied GametimeWeb.UserSocket :error

What am I doing wrong here?

Phoenix 1.4.10

UserSocket:

defmodule GametimeWeb.UserSocket do
  use Phoenix.Socket

  require Logger

  ## Channels
  channel "sports:*", GametimeWeb.SportsChannel

  # Socket params are passed from the client and can
  # be used to verify and authenticate a user. After
  # verification, you can put default assigns into
  # the socket that will be set for all channels, ie
  #
  #     {:ok, assign(socket, :user_id, verified_user_id)}
  #
  # To deny connection, return `:error`.
  #

  def connect(%{"token" => token}, socket) do
    # max_age: 1209600 is equivalent to two weeks in seconds
    case Phoenix.Token.verify(socket, "user socket salt", token, max_age: 1209600) do
      {:ok, user_id} ->
        {:ok, assign(socket, :user, user_id)}
      {:error, reason} ->
        Logger.debug IO.inspect(reason)
        :error
    end
  end

endpoint code:

defmodule GametimeWeb.Endpoint do
  use Phoenix.Endpoint, otp_app: :gametime

  socket "/socket", GametimeWeb.UserSocket,
    websocket: true, # or list of options
    longpoll: false

Solution

  • That is the helper socket for the live reload feature. It won't be opened when MIX_ENV is prod.

    screenshot of ws messages