{"id":13463461,"url":"https://github.com/ngauthier/tubesock","last_synced_at":"2025-03-25T06:32:04.859Z","repository":{"id":7406697,"uuid":"8737456","full_name":"ngauthier/tubesock","owner":"ngauthier","description":"Websocket interface on Rack Hijack w/ Rails support","archived":false,"fork":false,"pushed_at":"2019-09-18T14:17:47.000Z","size":60,"stargazers_count":619,"open_issues_count":11,"forks_count":43,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-03-01T10:37:57.112Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"bignerdranch/piebits-demo","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ngauthier.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-03-12T20:18:21.000Z","updated_at":"2025-01-23T23:59:31.000Z","dependencies_parsed_at":"2022-08-28T01:22:17.024Z","dependency_job_id":null,"html_url":"https://github.com/ngauthier/tubesock","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngauthier%2Ftubesock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngauthier%2Ftubesock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngauthier%2Ftubesock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngauthier%2Ftubesock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ngauthier","download_url":"https://codeload.github.com/ngauthier/tubesock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245414392,"owners_count":20611359,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T13:00:53.861Z","updated_at":"2025-03-25T06:32:04.550Z","avatar_url":"https://github.com/ngauthier.png","language":"Ruby","readme":"# Tubesock - !! This gem is no longer updated. We recommend you use Rails's built-in [ActionCable](https://guides.rubyonrails.org/action_cable_overview.html) !!\n\n[![Build Status](https://travis-ci.org/ngauthier/tubesock.png)](https://travis-ci.org/ngauthier/tubesock) [![Code Climate](https://codeclimate.com/github/ngauthier/tubesock.png)](https://codeclimate.com/github/ngauthier/tubesock)\n\nTubesock lets you use websockets from rack and rails 4+ by using Rack's new hijack interface to access the underlying socket connection.\n\nIn 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 \u003e 2.0.0.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'tubesock'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install tubesock\n\n## Usage\n\n### Rack\n\nTo use Tubesock with rack, you need to hijack the rack environment and then return an asynchronous response. For example:\n\n```ruby\nrequire 'tubesock'\n\nclass Server\n  def call(env)\n    if env[\"HTTP_UPGRADE\"] == 'websocket'\n      tubesock = Tubesock.hijack(env)\n      tubesock.onmessage do |message|\n        puts \"Got #{message}\"\n      end\n      tubesock.listen\n      [ -1, {}, [] ]\n    else\n      [404, {'Content-Type' =\u003e 'text/plain'}, ['Not Found']]\n    end\n  end\nend\n```\n\nThen you could do the following in your config.ru file to use this class:\n\n```ruby\nrun Server.new\n```\n\n### Rails 4+\n\nOn Rails 4 there is a module you can use called `Tubesock::Hijack`. In a controller:\n\n```ruby\nclass ChatController \u003c ApplicationController\n  include Tubesock::Hijack\n\n  def chat\n    hijack do |tubesock|\n      tubesock.onopen do\n        tubesock.send_data \"Hello, friend\"\n      end\n\n      tubesock.onmessage do |data|\n        tubesock.send_data \"You said: #{data}\"\n      end\n    end\n  end\nend\n```\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","funding_links":[],"categories":["Web Apps, Services \u0026 Interaction"],"sub_categories":["HTTP Pub/Sub"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fngauthier%2Ftubesock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fngauthier%2Ftubesock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fngauthier%2Ftubesock/lists"}