webchannels
webchannels
This is an experimental package, things can and will change.
Basically soft-realtime channels powered by WebSockets for Crystal.
Heavily inspired by ActionCable and Phoenix Channels
Installation
-
Add the dependency to your
shard.yml
:dependencies: webchannels: github: klirix/webchannels
-
Run
shards install
Usage
require "webchannels"
class Echoes < WebChannels::WebChannel
def on_data(context, data)
Echoes.fanout(data)
end
end
class MyManifold < WebChannels::Manifold
channel "echo", Echoes
end
with http
:
require "http"
server = HTTP::Server.new([
HTTP::WebsocketHandler.new &MyManifold.handler
])
server.listen 8080
with kemal
:
require "kemal"
ws "/echo", &MyManifold.handler
Kemal.run
Development
A lot of things are to be completed.
TODO:
Authorization via on subscribe and authentication via data passed on channel joining or http context
Passing data to WebChannels via structs not strings. Find a way for better communication.
Decouple connection and channel to simplify logic and naming.
Stabilize and standardize protocol and think of a better name for the library
add topic subscription data processing.
as in
subscribe "news" { |data| process(data) }
Contributing
- Fork it (https://github.com/klirix/webchannels/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Askhat Saiapov - creator and maintainer
webchannels
- 7
- 0
- 0
- 0
- 0
- over 3 years ago
- March 13, 2021
MIT License
Sun, 24 Nov 2024 20:27:19 GMT