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

  1. Add the dependency to your shard.yml:

    dependencies:
      webchannels:
        github: klirix/webchannels
    
  2. 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

  1. Fork it (https://github.com/klirix/webchannels/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Repository

webchannels

Owner
Statistic
  • 7
  • 0
  • 0
  • 0
  • 0
  • over 3 years ago
  • March 13, 2021
License

MIT License

Links
Synced at

Sun, 24 Nov 2024 20:27:19 GMT

Languages