How do channels put cowboy in longpoll/websocket mode?

Hello all!

According to the cowboy docs, if you want to use longpoll or websockets you have to provide a handler that returns :cowboy_loop or :cowboy_websocket from init.

This person was able to use websockets with plug and without phoenix. They used this snippet that according to José Valim is not officially supported, furthermore I was not able to find anything similar on phoenix’s source code so I assume that’s not how it’s done.

There is this macro wizardry on phoenix’s endpoint that I guess could have something to do with it but I can’t understand it. ( ._.)

Thus the title: How do channels put cowboy in longpoll/websocket mode?

Thanks!

Edit: Changed the link to the “macro wizardry” to point to a version tag and not to master. If you reading this in the future you are welcome.