客户端库
用 HTML 实现实时 WebSocket 在任何网页加一行 script 标签:立即获得已连接的客户端,以及实时在线人数、消息列表和弹出通知,无需构建流程。
登录后,示例代码会自动填入您的集群主机。 登录
使用 AI 编程智能体? 复制 Agent 提示词 ↓
加入 script 标签
<script src ="https://hibira.io/embed/v1.js" data-key ="YOUR_APP_KEY" data-host ="ws.hibira.io" async > </script > 放入现成的小组件
<span data-hibira-online ="lobby" > 0</span > online
<ul data-hibira-feed ="news" data-event ="update" data-limit ="10" > </ul >
<div data-hibira-toast ="alerts" data-event ="alert" data-position ="bottom-right" > </div > 在自己的代码中使用客户端
(window .Hibira = window .Hibira || []).push ((client ) => {
client.subscribe ('orders' ).bind ('order-shipped' , (data ) => {
console .log ('Order shipped' , data);
});
});Agent 提示词 将这段提示词粘贴到 Claude Code、Cursor、GitHub Copilot 或其他 AI 编程智能体,它会按照上方的设置,把 Hibira 接入您的 HTML 项目。
Integrate Hibira realtime messaging into this HTML project. Hibira is a hosted WebSocket service that speaks the Pusher Channels protocol, so it works with the standard Pusher libraries (here: embed/v1.js, https://hibira.io/guides/html) pointed at Hibira instead of pusher.com.
Connection details:
- Host: ws.hibira.io
- Port: 443
- TLS: yes (https)
- App key: YOUR_APP_KEY
- No app secret: it belongs on the server, never in this app
What to do:
1. Look at the project first (framework version, package manager, config and env conventions, where similar integrations live) and follow what it already does.
2. Add the script tag once, in the shared layout or base template (just before </body>), not in every page or component.
3. If the site has a Content-Security-Policy, allow the script's origin in script-src and the WebSocket host (wss://) in connect-src.
4. For online counts in rooms bigger than a few hundred people, use a presence-large-* channel (it needs data-auth-endpoint); window.Hibira.largePresence(channel) gives the member sample and join/leave deltas.
5. Use the data-hibira-online, data-hibira-feed and data-hibira-toast widgets where they fit; style .hibira-feed-item with the site's own CSS. Event text is always inserted as plain text.
6. For custom behaviour, queue callbacks with (window.Hibira = window.Hibira || []).push((client) => ...) rather than polling for the script; the client is a standard pusher-js instance.
7. If the page uses private or presence channels, add data-auth-endpoint pointing at the backend route that signs subscriptions; that route uses the app secret and lives on the server only.
8. Events are published from the server with any Pusher-compatible server library (or the Debug console on the app page for a quick test).
9. Read the credentials and host from environment variables or the project's config, and add placeholder entries to .env.example (or its equivalent). Never commit real values.
10. Always pass the host, port and TLS setting above. The library defaults to pusher.com; where it requires a cluster, use "ap" (the host decides where it connects).
11. If YOUR_APP_KEY above is still a placeholder, keep it as an env placeholder and tell me where to fill it in rather than inventing a value.
12. When you are done, list the files you changed and tell me how to check it works, for example by publishing a test event and watching it arrive.
Reference setup from the Hibira HTML guide (adapt it to the project's structure):
Add the script tag:
```html
<!-- Before </body>, on every page that needs live updates -->
<script src="https://hibira.io/embed/v1.js" data-key="YOUR_APP_KEY" data-host="ws.hibira.io" async></script>
```
Drop in ready-made widgets:
```html
<!-- People on this page right now (turn on "Send subscriber counts" in the app settings) -->
<span data-hibira-online="lobby">0</span> online
<!-- The newest "update" events on the news channel, newest first -->
<ul data-hibira-feed="news" data-event="update" data-limit="10"></ul>
<!-- A toast for each "alert" event: { "title": "...", "body": "...", "url": "..." } -->
<div data-hibira-toast="alerts" data-event="alert" data-position="bottom-right"></div>
```
Use the client in your own code:
```js
// Runs as soon as the script has loaded, even if this code runs first.
(window.Hibira = window.Hibira || []).push((client) => {
client.subscribe('orders').bind('order-shipped', (data) => {
console.log('Order shipped', data);
});
});
```
请将 YOUR_APP_KEY 等占位符替换为控制台中的值,或让智能体保留为环境变量,之后再自行填写。
或连接 Hibira MCP 服务器,让代理自行创建应用并填入凭据。 连接您的 AI 编程代理 →
请使用控制台中的应用密钥(key 与 secret)。频道、事件与授权端点的用法与 Pusher 完全相同。 库参考文档 ↗