Implementing a custom phoenix websocket transport for the upcoming phoenix 1.4

I am trying to build an application with a bit of custom header/request validation logic around socket connections (while still using channels).

How would I go about implementing a custom phoenix socket/transport module in the to be released phoenix 1.4? I mean, in 1.3, one could add different “transports” to the socket implementation by adding

transport :websocket, MyCustomTransport

which would let me change the module used for websocket connections.

Phoenix 1.4 introduces a more direct way of hooking up (and configuring) the socket module directly from the endpoint - which is nice - but where to hook in custom code for establishing a connection (or even a custom protocol)?

Am I expected (instead of coding up a new transport) to code up a custom module following @behaviour Phoenix.Socket and @behaviour Phoenix.Socket.Transport?

Thank you very much in advance!

5 Likes