VBandarupalli

VBandarupalli

Can we have Phoenix Channels for a cowboy2 websocket handlers

Is it possible to have a channel for a websocket created using cowboy2.

I have two sockets in my application. One of the websocket is using cowboy2. I am not able to create the channel for the websocket.
My websocket endpoint is /ws/feeds

I have this in my sys.config

{"/ws", 
        'Elixir.Phoenix.Endpoint.Cowboy2Handler',
        {'Elixir.Phoenix.Transports.WebSocket',
        {'Elixir.OctopusWeb.Endpoint',
        'Elixir.OctopusWeb.FeedsSocket',websocket}}},

Endpoint.ex

  socket "/ws", OctopusWeb.FeedsSocket,
    websocket: false,
    longpoll: false

FeedsSocket

defmodule OctopusWeb.FeedsSocket do
  use Phoenix.Socket

  require Logger

  channel "feeds_channel", OctopusWeb.FeedsChannel

  transport(
    :websocket,
    Phoenix.Transports.WebSocket,
    serializer: [{HydraWeb.Web.Transports.BinarySerializer, "~> 1.0.0"}]
  )


  def connect(_params, socket) do
    Logger.debug("feeds socket connected")
    {:ok, socket}
  end

  def id(_socket), do: nil
end

Feedschannel.ex

defmodule OctopusWeb.FeedsChannel do
  use Phoenix.Channel

  require Logger

  def join("feeds_channel", req, socket) do
    Logger.debug("feeds channel connected")

    {:ok, socket}
  end
end

Please help me where I went wrong.

First Post!

Exadra37

Exadra37

Change websocket to true.

Where Next?

Popular in Questions Top

stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New

Other popular topics Top

belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New

We're in Beta

About us Mission Statement