用戶端函式庫
用 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 程式開發代理 →
請使用儀表板中的應用程式金鑰與密鑰。頻道、事件與授權端點的用法和 Pusher 完全相同。 函式庫說明文件 ↗