{"id":15175172,"url":"https://github.com/vivekmiyani/offline_broadcaster","last_synced_at":"2025-10-01T12:31:04.677Z","repository":{"id":56886217,"uuid":"341493683","full_name":"vivekmiyani/offline_broadcaster","owner":"vivekmiyani","description":"Deliver messages to offline users when they comes online.","archived":true,"fork":false,"pushed_at":"2021-03-01T06:12:34.000Z","size":21,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-09-19T05:17:35.962Z","etag":null,"topics":["activerecord","deliver-messages","gem","ruby","ruby-on-rails","rubygems"],"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/vivekmiyani.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-23T09:10:16.000Z","updated_at":"2023-05-18T11:25:23.000Z","dependencies_parsed_at":"2022-08-20T23:10:52.276Z","dependency_job_id":null,"html_url":"https://github.com/vivekmiyani/offline_broadcaster","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/vivekmiyani%2Foffline_broadcaster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vivekmiyani%2Foffline_broadcaster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vivekmiyani%2Foffline_broadcaster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vivekmiyani%2Foffline_broadcaster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vivekmiyani","download_url":"https://codeload.github.com/vivekmiyani/offline_broadcaster/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219866621,"owners_count":16554249,"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":["activerecord","deliver-messages","gem","ruby","ruby-on-rails","rubygems"],"created_at":"2024-09-27T12:04:28.612Z","updated_at":"2025-10-01T12:30:59.363Z","avatar_url":"https://github.com/vivekmiyani.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OfflineBroadcaster\n- This gem aims to deliver messages/data or save into database for later delivery to the receiver according to their (online/offline) status.\n- The main advantage to use this gem is that we can eliminate message delivery logic from our application code. So we can directly do broadcast without worrying about the user status.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'offline_broadcaster'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nInstall migration yourself (as of now):\n\n```ruby\nclass CreateOfflineBroadcasterRecords \u003c ActiveRecord::Migration[6.1]\n  def change\n    create_table :offline_broadcaster_records do |t|\n      t.references :receiver, polymorphic: true\n      t.string     :channel\n      t.json       :data\n\n      t.timestamps\n    end\n  end\nend\n\n```\n\nRun migration:\n\n    $ rails db:migrate\n\n## Usage\n\n#### Create `Adapter` to listen for the messages:\n\n- It should inherit `OfflineBroadcaster::Adapter` (It can be placed inside model or wherever you want).\n- Overload collect method as below example.\n- So, whenever user receives a message this method will be called. Like, for online users it will be called immediately and for offline users it will be called once user comes online.\n\n```ruby\nclass User::OfflineManager \u003c OfflineBroadcaster::Adapter\n\n  # This method called when user comes online.\n  def self.collect(channel:, receiver:, data:)\n    # Here we can safely publish message to redis channel\n    # OR we can publish it on ActionCable channel.\n  end\nend\n\n```\n\n#### Add this to your `User` model:\n\n- While calling `acts_as_offline_receiver` pass `online_attribute` so gem can identify user status (In our case we have `online` column in our database).\n- And also need to pass adapter we just wrote.\n\n```ruby\nclass User \u003c ApplicationRecord\n  acts_as_offline_receiver online_attribute: :online, adapter: User::OfflineManager\nend\n```\n\n#### Let's test it:\n\n```ruby\nreceiver = User.last\nreceiver.online\n# =\u003e false\n\n# Send a message\nUser::OfflineManager.deliver(channel: 'greeting_channel', receiver: receiver, data: 'Hello online user!!')\nUser::OfflineManager.deliver(channel: 'greeting_channel', receiver: receiver, data: { message: 'Welcome!!' })\n# =\u003e # Some insert query will going to run.\n\n# Update the user status\nreceiver.update(online: true)\n# =\u003e User::OfflineManager#collect will be called.\n```\n\n## How it works?\n1. This gem will observe the given attribute changes (to identify user online/offline status).\n2. While sending a message if user is online then that message will be delivered immediately\n3. Otherwise, it will store that into database and when user comes online again those pending messages will be delivered.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/vivekmiyani/offline_broadcaster. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/vivekmiyani/offline_broadcaster/blob/master/CODE_OF_CONDUCT.md).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the OfflineBroadcaster project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/vivekmiyani/offline_broadcaster/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvivekmiyani%2Foffline_broadcaster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvivekmiyani%2Foffline_broadcaster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvivekmiyani%2Foffline_broadcaster/lists"}