lucky icon indicating copy to clipboard operation
lucky copied to clipboard

Feature Request: Add out-of-the-box support for websockets

Open jwoertink opened this issue 7 years ago • 10 comments

For anyone that comes looking for websocket support, you can dive in to the built in websocket support for now.

https://gitter.im/luckyframework/Lobby?at=5b5a51a61be9bb57bcc749bd

However, this is obviously something we should support out of the box with Lucky. I've never actually used websockets, so I don't know if they use HTTP methods or not, but looking at Kemal docs I would assume something like

class SomeAction < WebsocketAction
  route "/" do
    # maybe context.on_message
    # or have access to socket.on_message here?
  end
end

jwoertink avatar Jul 27 '18 02:07 jwoertink

I don't know if they use HTTP methods or not

The WebSocket protocol is different from HTTP, but allows proxying in combination with an Upgrade: websocket header.

Having a look through Lucky::Routeable, ContextHelper, pages and friends, and keeping in mind what Rails does in ActionCable, and Phoenix with channels, I think it could look something like this:

class SomeAction < WebSocketAction
  route do 
    send_from SomeActionChannel, data: 'foo'
  end
end

This assumes the following:

  • an instance of a WebSocket "manager" of sorts that keeps track of all the subscribed sockets
  • a WebSocketAction class to mirror Action
  • A WebSocketChannel as equivalent to pages

This feels more in line with how Lucky does other stuff than the Kemal example.

@paulcsmith How do you feel about this? Interested in WS support at all?

citizen428 avatar Oct 14 '18 16:10 citizen428

@citizen428 I think something like that sounds awesome. I think the best bet would be to have a third part shard until we figure out exactly what Channels should look like. Something like what https://github.com/cable-cr/cable. That way the community can try various things out and we can merge together the best ideas

paulcsmith avatar Sep 03 '19 19:09 paulcsmith

@paulcsmith Agreed re third party shard, especially given that their README states the following:

Better integrate with Lucky, maybe with generators, or something else?

Let's try to rope in @fernandes and see if there's collaboration potential 🙂

citizen428 avatar Sep 09 '19 15:09 citizen428

hey @citizen428 thanks for pinging me

yeah, absolutely, cable-cr itself is just, a library heheh to be useful, it's good to be used in something like.. Lucky, for sure :)

Like actioncable, just need one route to be "mounted" at the app, it comes with a handler, that can be used as inspiration

If @jwoertink / @paulcsmith / @citizen428 wants to collaborate on lucky-cable, we create a repo on the org and you hop in there, wdyt?

fernandes avatar Sep 09 '19 21:09 fernandes

@paulcsmith Maybe we could start with you creating the lucky-cable repo for us and adding me and @fernandes as contributors to that or something?

citizen428 avatar Oct 10 '19 12:10 citizen428

@citizen428 good idea. I'll level it lucky-cable-preview so it is clear and invite you both. I'll also keep it private for now until you two feel it is in a state where you think people could start using it!

paulcsmith avatar Oct 15 '19 19:10 paulcsmith

I spoke too soon! I can't create a private repo. @citizen428 @fernandes would one of you be ok creating a repo and adding me to it? I'd be happy to collaborate on it with reviews or answering questions. I won't have much time to write code though :(

paulcsmith avatar Oct 15 '19 19:10 paulcsmith

added both you guys 😉

fernandes avatar Oct 15 '19 19:10 fernandes

I'm in! Feel free to ping me or hit me up on Gitter!

paulcsmith avatar Oct 15 '19 19:10 paulcsmith

Thanks @paulcsmith @fernandes

citizen428 avatar Oct 17 '19 04:10 citizen428