{"id":16061984,"url":"https://github.com/rossta/pushkin","last_synced_at":"2025-10-08T03:44:34.078Z","repository":{"id":2502973,"uuid":"3477819","full_name":"rossta/pushkin","owner":"rossta","description":"Pub/sub messaging through private channels using Faye. Based on PrivatePub.","archived":false,"fork":false,"pushed_at":"2012-07-27T12:04:41.000Z","size":120,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-15T10:57:02.644Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rossta.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-02-18T11:36:28.000Z","updated_at":"2020-07-06T14:02:59.000Z","dependencies_parsed_at":"2022-09-07T00:20:07.972Z","dependency_job_id":null,"html_url":"https://github.com/rossta/pushkin","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rossta%2Fpushkin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rossta%2Fpushkin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rossta%2Fpushkin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rossta%2Fpushkin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rossta","download_url":"https://codeload.github.com/rossta/pushkin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240254293,"owners_count":19772393,"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-10-09T04:21:15.717Z","updated_at":"2025-10-08T03:44:29.030Z","avatar_url":"https://github.com/rossta.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pushkin\n\nPushkin aims to provide Rails 3.1+ applications with publish/subscribe functionality through [Faye](http://faye.jcoglan.com/).\n\nThis gem is based on [Private Pub](https://github.com/ryanb/private_pub) as featured in [RailsCasts Episode 316](http://railscasts.com/episodes/316-private-pub).\n\n[![Build Status](https://secure.travis-ci.org/rossta/pushkin.png)](http://travis-ci.org/rossta/pushkin)\n\n##\n\nAdd the gem to your Gemfile and run the `bundle` command to install it.\n\n```ruby\ngem \"pushkin\"\n```\n\nRun the generator to create the initial files.\n\n```\nrails g pushkin:install\n```\n\nNext, start up Faye using the rackup file that was generated.\n\n```\nrackup pushkin.ru -s thin -E production\n```\n\n**In Rails 3.1** add the JavaScript file to your application.js file manifest.\n\n```javascript\n//= require pushkin\n```\n\nIt's not necessary to include faye.js since that will be handled automatically for you.\n\n## Serving Faye over HTTPS (with Thin)\n\nTo server Faye over HTTPS you could create a thin configuration file `config/private_pub_thin.yml` similar to the following:\n\n```yaml\n---\nport: 4443\nssl: true\nssl_key_file: /path/to/server.pem\nssl_cert_file: /path/to/certificate_chain.pem\nenvironment: production\nrackup: private_pub.ru\n```\n\nThe `certificate_chain.pem` file should contain your signed certificate, followed by intermediate certificates (if any) and the root certificate of the CA that signed the key.\n\nNext reconfigure the URL in `config/private_pub.yml` to look like `https://your.hostname.com:4443/faye`\n\nFinally start up Thin from the project root.\n\n```\nthin -C config/private_pub_thin.yml start\n```\n\n## Usage\n\nUse the `subscribe_to` helper method on any page to subscribe to a channel.\n\n```rhtml\n\u003c%= subscribe_to \"/messages/new\" %\u003e\n```\n\nUse the `publish_to` helper method to send JavaScript to that channel. This is usually done in a JavaScript AJAX template (such as a create.js.erb file).\n\n```rhtml\n\u003c% publish_to \"/messages/new\" do %\u003e\n  $(\"#chat\").append(\"\u003c%= j render(@messages) %\u003e\");\n\u003c% end %\u003e\n```\n\nThis JavaScript will be immediately evaluated on all clients who have subscribed to that channel. In this example they will see the new chat message appear in real-time without reloading the browser.\n\n\n## Alternative Usage\n\nIf you prefer to work through JSON instead of `.js.erb` templates, you can pass a hash to `publish_to` instead of a block and it will be converted `to_json` behind the scenes. This can be done anywhere (such as the controller).\n\n```ruby\nPrivatePub.publish_to \"/messages/new\", :chat_message =\u003e \"Hello, world!\"\n```\n\nAnd then handle this through JavaScript on the client side.\n\n```javascript\nPrivatePub.subscribe(\"/messages/new\", function(data, channel) {\n  $(\"#chat\").append(data.chat_message);\n});\n```\n\nThe Ruby `subscribe_to` helper call is still necessary with this approach to grant the user access to the channel. The JavaScript is just a callback for any custom behavior.\n\n\n## Configuration\n\nThe configuration is set separately for each environment in the generated `config/private_pub.yml` file. Here are the options.\n\n* `server`: The URL to use for the Faye server such as `http://localhost:9292/faye`.\n* `secret_token`: A secret hash to secure the server. Can be any string.\n* `signature_expiration`: The length of time in seconds before a subscription signature expires. If this is not set there is no expiration. Note: if Faye is on a separate server from the Rails app, the system clocks must be in sync for the expiration to work properly.\n\n\n## How It Works\n\nThe `subscribe_to` helper will output the following script which subscribes the user to a specific channel and server.\n\n```html\n\u003cscript type=\"text/javascript\"\u003e\n  PrivatePub.sign({\n    channel: \"/messages/new\",\n    timestamp: 1302306682972,\n    signature: \"dc1c71d3e959ebb6f49aa6af0c86304a0740088d\",\n    server: \"http://localhost:9292/faye\"\n  });\n\u003c/script\u003e\n```\n\nThe signature and timestamp checked on the Faye server to ensure users are only able to access channels you subscribe them to. The signature will automatically expire after the time specified in the configuration.\n\nThe `publish_to` method will send a post request to the Faye server (using `Net::HTTP`) instructing it to send the given data back to the browser.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frossta%2Fpushkin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frossta%2Fpushkin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frossta%2Fpushkin/lists"}