When might you have multiple socket handlers?

One thing about Phoenix Channels that I’ve never really understood is the purpose of Phoenix.Socket. From the docs and guides, I simply understand it as, “The place where you lay out the mapping of topics for your channels”. I create a MyAppWeb.UserSocket module, and leave it at that.

I think one question that might help me understand it better is: Would there ever be a use case for having more than one socket handler in a Phoenix app? When would you opt for multiple socket handlers vs just separate channels?

If the application needs to support both LiveView as well as direct channels, then you probably need different sockets. If you need non phoenix channel websockets like GraphQL subscriptions or other websocket specs, then you need multiple sockets.

1 Like