Project

tamashii

0.01
No commit activity in last 3 years
No release in over 3 years
The WebSocket framework implement inspired by ActionCable
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Project Readme

Tamashii Gem Version Build Status Test Coverage Code Climate

Tamashii is a package designed for IoT. You can write the WebSocket server and client easily by using this gem.

Installation

Add the following code to your Gemfile

gem 'tamashii'

And then execute:

$ bundle install

Or install it yourself with:

$ gem install tamashii

Usage

There are two section in Tamashii, Server and Client, is responsible for the WebSocket server and client, respectively.

Server

Server section is a server designed based on Rack, it can not only be easily compatible with the web server, such as Puma, Passenger, but also be used as a module in the Rails and other projects.

To start the server, generate config.ru and add the following code to it.

require 'tamashii/server'

run Tamashii::Server::Base.new

Then, you can start the server with:

$ rackup

If you want to start the server with other web server, such as Puma:

$ puma

You can refer to the project in tamashii-manager in the IoT server application.

Connection

In Tamashii, we only need to focus on how to connect with WebSocket users to exchange information, on the process of multi-process web server problems have been resolved in Tamashii.

We can create a Client object to handle the behavior of each user.

Tamashii::Server.config do |config|
  config.connection_class = Client
end

In Client , there are four events that need to be handled.

  • on_open : when the user is connected to the server
  • on_message : when the server receives the message from user
  • on_error : when the server gets an error
  • on_close : when the connection is shut down

In most cases, we only need to deal with parts of on_message , the other events can be handled as needed.

class Client
  def on_message(data)
    # Processing for the received Data (Binary)
  end
end

By default Tamashii will broadcast the received message to other clients automatically.

Client

The client is in another repository: tamashii-client

Development

To get the source code

$ git clone git@github.com:tamashii-io/tamashii.git

Initialize the development environment

$ ./bin/setup

Run the spec

$ rspec

Installation the version of development on localhost

$ bundle exec rake install

Contribution

Please report to us on GitHub if there is any bug or suggested modified.

The project was developed by 5xruby Inc.