aantron/dream

Discussion: Is Phoenix's Presence and Channel possible to port to Dream?

dangdennis opened this issue · 5 comments

This is more an open discussion than an issue.

With domains, I was successfully able to build an in-memory pubsub with domainslib channels at repo (though hardly production ready).

It makes sense then that porting over Phoenix Presence and Channel is possible when OCaml 5 is stable. Probably better that these are separate libs that can be plugged into Dream.

Use-case for Presence: easy to track user's online/offline status over websockets. When a user initiates a request to the Dream server, we can initialize a websocket and have that subscribe to a channel.

I'm hoping Dream can become a type-safe version of the Elixir Phoenix framework one day.

A while back, I've experimented with an implementation of channels for Dream: https://github.com/tcoopman/dream-channels

It's just an experiment and not ready at all, but it should be possible to build something more complete.

On the subject of dream-channels, Dream's WebSocket handling has become much more precise recently, with the low-level ping and pong and other bits exposed, as well as at least an API for reporting errors and remote closes intelligently (though it seems to be broken at the moment, #211, probably just needs some more things hooked together).

I ended up utilizing ably for my real time pubsub in my project via their http api.

But it would be cool to consider not having to pay ably or rely on a 3rd party, as well as be able to plug an Ably/Pusher adapter if so desired.

What's a decent starting API? I'm only familiar with Rescript/TS like API. What are good prior art out there? What kind of primitives do we work with? My noob idea: A super early version could involve just holding references to web sockets (as well as ensure they're removed when closed) inside some key-value data structure.

Looking at Phoenix PubSub, a supervision tree would alias a pubsub module directly in itself with a name id. Then other elixir processes can subscribe/publish to the pubsub-supervision tree.

https://hexdocs.pm/phoenix_pubsub/Phoenix.PubSub.html

Is it cool if i keep it open?

I’m more so waiting for ocaml 5 to ship with Dream to start using domainslib as an experiment.

Is it cool if i keep it open?

Yes :)