lucky
lucky copied to clipboard
Feature Request: Add out-of-the-box support for websockets
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
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
WebSocketActionclass to mirrorAction - A
WebSocketChannelas 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 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 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 🙂
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?
@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 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!
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 :(
added both you guys 😉
I'm in! Feel free to ping me or hit me up on Gitter!
Thanks @paulcsmith @fernandes