• Stars
    star
    623
  • Rank 72,088 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 11 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Websocket interface on Rack Hijack w/ Rails support

Tubesock - !! This gem is no longer updated. We recommend you use Rails's built-in ActionCable !!

Build Status Code Climate

Tubesock lets you use websockets from rack and rails 4+ by using Rack's new hijack interface to access the underlying socket connection.

In contrast to other websocket libraries, Tubesock does not use a reactor (read: no eventmachine). Instead, it leverages Rails 4's new full-stack concurrency support. Note that this means you must use a concurrent server. We recommend Puma > 2.0.0.

Installation

Add this line to your application's Gemfile:

gem 'tubesock'

And then execute:

$ bundle

Or install it yourself as:

$ gem install tubesock

Usage

Rack

To use Tubesock with rack, you need to hijack the rack environment and then return an asynchronous response. For example:

require 'tubesock'

class Server
  def call(env)
    if env["HTTP_UPGRADE"] == 'websocket'
      tubesock = Tubesock.hijack(env)
      tubesock.onmessage do |message|
        puts "Got #{message}"
      end
      tubesock.listen
      [ -1, {}, [] ]
    else
      [404, {'Content-Type' => 'text/plain'}, ['Not Found']]
    end
  end
end

Then you could do the following in your config.ru file to use this class:

run Server.new

Rails 4+

On Rails 4 there is a module you can use called Tubesock::Hijack. In a controller:

class ChatController < ApplicationController
  include Tubesock::Hijack

  def chat
    hijack do |tubesock|
      tubesock.onopen do
        tubesock.send_data "Hello, friend"
      end

      tubesock.onmessage do |data|
        tubesock.send_data "You said: #{data}"
      end
    end
  end
end

Contributing

  1. Fork it
  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 new Pull Request

More Repositories

1

hydra

Distributed testing framework
JavaScript
390
star
2

capybara-slow_finder_errors

Ruby
210
star
3

domino

View abstraction for integration testing
Ruby
94
star
4

sock-chat

Demo of Tubesock and Redis for threaded chatting
Ruby
56
star
5

intro-to-backbone-js

JavaScript
52
star
6

knowsql

SQL Tips and Tricks - Presentation and Benchmarks
Ruby
34
star
7

postgis-on-rails-example

http://ngauthier.com/2013/08/postgis-and-rails-a-simple-approach.html
Ruby
24
star
8

slow-actions

Inspect a rails application's log file to find slow actions
Ruby
23
star
9

hubot-github-heroku-deploy

Deploy from Github to Heroku with Hubot
Shell
21
star
10

nicks-toolbox

A collection of helpful scripts
Python
11
star
11

backbone-presentation

JavaScript
10
star
12

domino_rspec

example of using domino with rspec
Ruby
10
star
13

preact-ssr-demo

TypeScript
8
star
14

Grease-Your-Suite

Tips and tricks for faster testing
Ruby
8
star
15

find_or_redirect

Refactor finder code in controllers
Ruby
7
star
16

minitest-parallel

Run MiniTest suites in parallel
Ruby
6
star
17

view-abstraction-demo

Integration Test View Abstraction Demo
Ruby
6
star
18

jslintrb-v8

jslint bindings for ruby in v8
JavaScript
6
star
19

capybara-jasmine

Run Jasmine Tests via Capybara
JavaScript
6
star
20

forque

Make forking easy in ruby
Ruby
6
star
21

aptinstaller

Automatically install a project's dependencies via apt-get
Ruby
5
star
22

multitest

Run your ruby tests in parallel
Ruby
5
star
23

quick_menu

Quickly turn a bunch of links into a javascript dropdown menu
Ruby
5
star
24

rack_attack

Ruby
4
star
25

testing-go-presentation

Go
4
star
26

watch_me

Watch multiple log files in a single terminal window
4
star
27

robust-tests

JumpstartLab Training Course on Robust Testing
Ruby
4
star
28

erlangies

exercises from erlangdc
Erlang
4
star
29

adv-rails-patterns

Advanced Rails Patterns presentation
Ruby
3
star
30

ngauthier.github.com

Nick Gauthier's Blog
JavaScript
3
star
31

test-pilot-demo

Demo of the TestPilot integration testing pattern
Ruby
3
star
32

rails_structure_loading

Generate and load SQL structure files for your migrations
Ruby
3
star
33

dot_chat

DOT to SVG
Ruby
3
star
34

active-listener

Event listening and firing system for ruby
Ruby
3
star
35

ruby-on-rails-polymorphism-benchmarks

Benchmarking tests of using RoR polymorphic relationships through strings versus integers, with and without indices.
Ruby
3
star
36

bpm

Bash Package Manager
Shell
2
star
37

tclub

JHU Tae Kwon Do Club Web Site
2
star
38

channel-fakes-post

Go
2
star
39

backbone-raphael-traer

Presentation on Backbone, Raphael, and Traer
JavaScript
2
star
40

minimal-go-containers-post

Go
2
star
41

compact_table

Table display plugin that allows you to hide specific HTML until the user requests it
Ruby
2
star
42

domino_example

Example Rails application using Domino
Ruby
2
star
43

ribs

A library of backbone.js extended classes
CoffeeScript
2
star
44

performance-testing

A guide to performance testing in rails
Ruby
2
star
45

smashingmag-mobile-ux

1
star
46

traffic_patterns

TODO: one-line summary of your gem
Ruby
1
star
47

hydra-console

Run tests repeatedly without booting your environment
Ruby
1
star
48

outside-in-demo

demo app for outside in testing talk
Ruby
1
star
49

six-ws-of-testing

A philosophical exploration of testing
Ruby
1
star
50

capybara-java_script_lint

Run JSLint on Rails JavaScript assets through the asset pipeline with Capybara Webkit
Ruby
1
star