官方包 · 框架
从 Hanami 发送实时事件
把 pusher gem 注册为 Hanami 2 provider,从 action 和 operation 发送 Hibira 事件,并在 action 中签署频道订阅。
pusherRubyGems ↗
最快的方式:装好 Hibira 插件,粘贴一段提示词
在你的 AI 编程助手装好插件,再粘贴提示词。助手会帮你登录、需要时创建免费应用、写好代码并发送测试事件。 GitHub ↗
安装插件
claude plugin marketplace add hibira-io/agent-plugin claude plugin install hibira@hibira粘贴这段提示词
Add Hibira Hanami (pusher) to this project. Follow https://hibira.io/guides/hanami, adapted to how this project is already set up. If I have no Hibira app yet, create a Free one that allows http://localhost so I can test right away. Keep the app key and secret in environment variables, add placeholders to .env.example, and never commit real values or send the secret to a browser. When you are done, send a test event, show me it arriving, and list the files you changed.
- provider 注册一个 client,action 和 operation 通过 Deps 获取。
- 由 action 为 pusher-js 和 Laravel Echo 签署私有和 presence 频道。
登录后,示例代码会自动填入您的集群主机。 登录
安装
bundle add pusher配置
# config/providers/hibira.rb Hanami.app.register_provider(:hibira) do prepare { require "pusher" } start do register "hibira", Pusher::Client.new( app_id: target["settings"].hibira_app_id, key: target["settings"].hibira_app_key, secret: target["settings"].hibira_app_secret, host: "ws.hibira.io", port: 443, use_tls: true ) end end # config/settings.rb: setting :hibira_app_id, setting :hibira_app_key, setting :hibira_app_secret使用
# app/actions/pusher/auth.rb (config/routes.rb: post "/pusher/auth", to: "pusher.auth") module Bookshelf module Actions module Pusher class Auth < Bookshelf::Action include Deps["hibira"] def handle(request, response) # check the signed-in user may join request.params[:channel_name] first response.format = :json response.body = hibira.authenticate(request.params[:channel_name], request.params[:socket_id]).to_json end end end end end # anywhere: hibira.trigger("orders", "order.shipped", { id: 1042 })
开始之前
- 应用密钥只会在创建应用或轮换密钥时显示一次。请只放在服务器上,不要放进浏览器或游戏的构建包。
- Free 套餐需要把页面加载的每个来源都加入应用的“允许的来源”(开发时是 http://localhost:3000,之后是您的域名)。"*" 需要付费套餐。
请使用控制台中应用的 Key;Secret 只放在你的服务器上。频道、事件与授权端点的用法与 Pusher 完全相同。 免费创建账号 →