{"id":13682655,"url":"https://github.com/websocket-rails/websocket-rails","last_synced_at":"2025-05-14T06:13:06.875Z","repository":{"id":2827568,"uuid":"3829913","full_name":"websocket-rails/websocket-rails","owner":"websocket-rails","description":"Plug and play websocket support for ruby on rails.","archived":false,"fork":false,"pushed_at":"2024-02-14T10:47:37.000Z","size":1416,"stargazers_count":1727,"open_issues_count":201,"forks_count":284,"subscribers_count":51,"default_branch":"master","last_synced_at":"2025-05-10T15:02:39.840Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/websocket-rails.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-03-26T05:23:16.000Z","updated_at":"2025-04-26T11:47:00.000Z","dependencies_parsed_at":"2024-06-18T13:27:32.086Z","dependency_job_id":null,"html_url":"https://github.com/websocket-rails/websocket-rails","commit_stats":{"total_commits":351,"total_committers":32,"mean_commits":10.96875,"dds":0.301994301994302,"last_synced_commit":"0ee9e97b19e1f8250c18ded08c71647a51669122"},"previous_names":["danknox/websocket-rails"],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/websocket-rails%2Fwebsocket-rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/websocket-rails%2Fwebsocket-rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/websocket-rails%2Fwebsocket-rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/websocket-rails%2Fwebsocket-rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/websocket-rails","download_url":"https://codeload.github.com/websocket-rails/websocket-rails/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254081163,"owners_count":22011566,"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-08-02T13:01:50.657Z","updated_at":"2025-05-14T06:13:06.823Z","avatar_url":"https://github.com/websocket-rails.png","language":"Ruby","funding_links":[],"categories":["Ruby","WebSocket","Tools per Language"],"sub_categories":["Ruby"],"readme":"# Websocket-Rails\n\n[![Build Status](https://travis-ci.org/websocket-rails/websocket-rails.png?branch=master)](https://travis-ci.org/websocket-rails/websocket-rails)\n[![Gem Version](https://badge.fury.io/rb/websocket-rails.png)](http://badge.fury.io/rb/websocket-rails)\n[![Code Climate](https://codeclimate.com/github/websocket-rails/websocket-rails.png)](https://codeclimate.com/github/websocket-rails/websocket-rails)\n\n\nIf you haven't done so yet, check out the [Project\nPage](http://websocket-rails.github.io) to get a feel for the project direction. Feedback is very much appreciated. Post an issue on the issue tracker or [shoot us an email](mailto:support@threedotloft.com) to give us your thoughts.\n\n**Find us on IRC #websocket-rails**\n\nStop by #websocket-rails on freenode if you would like to chat or have any\nquestions.\n\n## Recent Updates\n\nCheck out the [CHANGELOG](https://github.com/websocket-rails/websocket-rails/blob/master/CHANGELOG.md) to find out what's new.\n\nAs of version 0.2.0, non event machine based web servers such as Phusion\nPassenger are supported through the use of the [Standalone Server Mode](https://github.com/websocket-rails/websocket-rails/wiki/Standalone-Server-Mode).\n\n## Overview\n\nStart treating client side events as first class citizens inside your\nRails application with a built in WebSocket server. Sure, WebSockets\naren't quite universal yet. That's why we also support streaming HTTP.\nOh, and if you don't mind running a separate process, you can support\njust about any browser with Flash sockets.\n\n## Installation and Usage Guides\n\n* [Installation\n  Guide](https://github.com/websocket-rails/websocket-rails/wiki/Installation-and-Setup)\n* [Event\n  Router](https://github.com/websocket-rails/websocket-rails/wiki/The-Event-Router)\n* [WebsocketRails Controllers](https://github.com/websocket-rails/websocket-rails/wiki/WebsocketRails Controllers)\n* [Using the JavaScript\n  Client](https://github.com/websocket-rails/websocket-rails/wiki/Using-the-JavaScript-Client)\n* [Using\n  Channels](https://github.com/websocket-rails/websocket-rails/wiki/Working-with-Channels)\n* [Using Private Channels](https://github.com/websocket-rails/websocket-rails/wiki/Using-Private-Channels)\n* [The\n  DataStore](https://github.com/websocket-rails/websocket-rails/wiki/Using-the-DataStore)\n* [Reloading Controllers In Development](https://github.com/websocket-rails/websocket-rails/wiki/Reloading-Controllers-In-Development)\n* [Multiple Servers and Background Jobs](https://github.com/websocket-rails/websocket-rails/wiki/Multiple-Servers-and-Background-Jobs)\n* [Standalone Server Mode](https://github.com/websocket-rails/websocket-rails/wiki/Standalone-Server-Mode)\n\n## Handle Events With Class\n\nMap events to controller actions using an Event Router.\n\n````ruby\nWebsocketRails::EventMap.describe do\n  namespace :tasks do\n  \n    # using a Hash to specify the target\n    subscribe :create, :to =\u003e TaskController, :with_method =\u003e :create\n    \n    # using the same syntax as routes.rb\n    subscribe :update, 'task#update'\n    \n    # if your controller is not a top-level object\n    subscribe :create_admin, :to =\u003e Admin::TaskController, :with_method =\u003e :create\n\n    subscribe :update_admin, 'admin/task#update'\n\n  end\nend\n````\n\nTrigger events using our JavaScript client.\n\n````javascript\nvar task = {\n  name: 'Start taking advantage of WebSockets',\n  completed: false\n}\n\nvar dispatcher = new WebSocketRails('localhost:3000/websocket');\n\ndispatcher.trigger('tasks.create', task);\n````\n\nHandle events in your controller.\n\n````ruby\nclass TaskController \u003c WebsocketRails::BaseController\n  def create\n    # The `message` method contains the data received\n    task = Task.new message\n    if task.save\n      send_message :create_success, task, :namespace =\u003e :tasks\n    else\n      send_message :create_fail, task, :namespace =\u003e :tasks\n    end\n  end\nend\n````\n\nReceive the response in the client.\n\n````javascript\ndispatcher.bind('tasks.create_success', function(task) {\n  console.log('successfully created ' + task.name);\n});\n````\n\nOr just attach success and failure callbacks to your client events.\n\n````javascript\nvar success = function(task) { console.log(\"Created: \" + task.name); }\n\nvar failure = function(task) {\n  console.log(\"Failed to create Product: \" + product.name)\n}\n\ndispatcher.trigger('products.create', task, success, failure);\n````\n\nThen trigger them in your controller:\n\n````ruby\ndef create\n  task = Task.create message\n  if task.save\n    trigger_success task\n  else\n    trigger_failure task\n  end\nend\n````\n\nIf you're feeling truly lazy, just trigger the failure callback with an\nexception.\n\n````ruby\ndef create\n  task = Task.create! message\n  trigger_success task # trigger success if the save went alright\nend\n````\n\nThat controller is starting to look pretty clean.\n\nNow in the failure callback on the client we have access to the record\nand the errors.\n\n````javascript\nvar failureCallback = function(task) {\n  console.log( task.name );\n  console.log( task.errors );\n  console.log( \"You have \" + task.errors.length + \" errors.\" );\n}\n````\n\nYou can stop listening to an event now by using the unbind function.\n\n````javascript\ndispatcher.unbind('tasks.create_success');\n````\n\n## Channel Support\n\nKeep your users up to date without waiting for them to refresh the page.\nSubscribe them to a channel and update it from wherever you please.\n\nTune in on the client side.\n\n````javascript\nchannel = dispatcher.subscribe('posts');\nchannel.bind('new', function(post) {\n  console.log('a new post about '+post.title+' arrived!');\n});\n````\n\nBroadcast to the channel from anywhere inside your Rails application. An\nexisting controller, a model, a background job, or a new WebsocketRails\ncontroller.\n\n````ruby\nlatest_post = Post.latest\nWebsocketRails[:posts].trigger 'new', latest_post\n````\n\n## Private Channel Support\n\nNeed to restrict access to a particular channel? No problem. We've got\nthat. \n\nPrivate channels give you the ability to authorize a user's\nsubscription using the authorization mechanism of your choice.\n\nJust tell WebsocketRails which channels you would like to make private by using the `private_channel` method in the Event Router.\nThen handle the channel authorization by subscribing to the `websocket_rails.subscribe_private` event.\n\n````ruby\nWebsocketRails::EventMap.describe do\n  private_channel :secret_posts\n  \n  namespace :websocket_rails\n    subscribe :subscribe_private, :to =\u003e AuthorizationController, :with_method =\u003e :authorize_channels\n  end\n```` \n\nOr you can always mark any channel as private later on.\n\n````ruby\nWebsocketRails[:secret_posts].make_private\n````\n\nOn the client side, you can use the `dispatcher.subscribe_private()`\nmethod to subscribe to a private channel.\n\nRead the [Private Channel Wiki](https://github.com/websocket-rails/websocket-rails/wiki/Using-Private-Channels) for more information on subscribing to private channels from the JavaScript client and handling the authorization in your controller.\n\n## Credit where credit is due\n\nBig thanks to our [contributors](https://github.com/websocket-rails/websocket-rails/graphs/contributors) who have helped keep this project moving.\n\nSpecial thanks to [@nessche](https://github.com/nessche) who provided the improved routing DSL and RSpec matcher suite.\n\nThe `websocket-rails` organization logo was kindly provided by [Uken Games](http://www.uken.com/).\n\n## Development\n\nPlease check out the [Development Guide](https://github.com/websocket-rails/websocket-rails/wiki/Development) if you are interested in contributing. It should cover everything you need to get up and running.\n\n## Core Team\n\nThe current `websocket-rails` core team consists of the following individuals:\n\n* [@DanKnox](https://github.com/DanKnox)\n* [@Pitr](https://github.com/pitr)\n* [@moaa](https://github.com/moaa)\n\nNew contributors and pull requests are always welcome.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebsocket-rails%2Fwebsocket-rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebsocket-rails%2Fwebsocket-rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebsocket-rails%2Fwebsocket-rails/lists"}