Websocket subprotocols with phoenix channels

Hi everyone!

I’m trying to use phoenix websockets as a Transport for SIP.
For SIP implementation must use the websocket “sip” subprotocol. (Sec-WebSocket-Protocol: sip header for a handshake)

Quote from RFC:

The SIP WebSocket Client and SIP WebSocket Server negotiate usage of
the WebSocket SIP subprotocol during the WebSocket handshake
procedure as defined in Section 1.3 of [RFC6455]. The client MUST
include the value “sip” in the Sec-WebSocket-Protocol header in its
handshake request. The 101 reply from the server MUST contain “sip”
in its corresponding Sec-WebSocket-Protocol header.

I try to send the Sec-WebSocket-Protocol header to the handshake request, but the Phoenix answers without it.
How can I resolve this or add a custom header to the handshake response header?

1 Like

You may have to go down to the bare cowboy websocket. You can see an example of defining subprotocols here, https://ninenines.eu/docs/en/cowboy/2.1/guide/ws_handlers/

There’s some pretty good example repos of setting up plain cowboy websockets in Elixir. The init calkback changed in cowboy v2, make sure you get the right docs for whatever version of cowboy your using.

Support Websocket subprotocols added in Phoenix 1.5+
https://hexdocs.pm/phoenix/Phoenix.Endpoint.html#socket/3-websocket-configuration

1 Like