SocketIO

Small analog socket.io

Installation

Add this to your application's shard.yml:

dependencies:
  socket_io:
    github: forsaken1/socket-io.cr

Usage

With Kemal:

require "kemal"
require "socket_io"

socket_io = SocketIO::Base.new

handler = socket_io.on_connection do |session| # session : SocketIO::WebSocket
  session.on("client_event") do |message|
    puts message
    session.emit("some_event", { message: "Hello!" })
  end
end

socket_io.emit :tick, { array: [1, 2, 3, 4], hash: { field: "Field" } } # send to all client

Kemal.config.add_handler handler
Kemal.run

On client

Use JS analog SocketIO.js

Contributing

  1. Fork it ( https://github.com/forsaken1/socket-io.cr/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