webchannels

Version, currently master branch1 version
  • master branchlatestMar 28, 2021

github.com/klirix/webchannels

No description declared in shard.yml.

7 stars
0 dependents
License: MIT

Installation

# Add this to your shard.yml
dependencies:
  webchannels:
    github: klirix/webchannels
    branch: master

master is a branch, not a release, so this tracks it rather than pinning a version.

Then run:

shards install

shard.yml

Crystal
0.36.1
License
MIT
Author
Askhat Saiapov <askhat.saiapov@gmail.com>

Dependencies

This version declares no dependencies.

README

# 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`:

   ```yaml
   dependencies:
     webchannels:
       github: klirix/webchannels
   ```

2. Run `shards install`

## Usage

```crystal
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`:
```crystal
require "http"

server = HTTP::Server.new([
  HTTP::WebsocketHandler.new &MyManifold.handler
])

server.listen 8080
```

with `kemal`:
```crystal
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 

```ruby
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

- [Askhat Saiapov](https://github.com/klirix) - creator and maintainer