Thư viện client
HTML thời gian thực với WebSocket Thêm một thẻ script vào bất kỳ trang web nào: một client đã kết nối cùng bộ đếm trực tuyến, feed và thông báo toast trực tiếp, không cần bước build.
Đăng nhập để xem các đoạn mã này với host cụm của riêng bạn. Đăng nhập
Đang dùng một AI agent lập trình? Sao chép prompt cho agent ↓
Thêm thẻ script
<script src ="https://hibira.io/embed/v1.js" data-key ="YOUR_APP_KEY" data-host ="ws.hibira.io" async > </script > Thêm widget dựng sẵn
<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 > Dùng client trong mã của bạn
(window .Hibira = window .Hibira || []).push ((client ) => {
client.subscribe ('orders' ).bind ('order-shipped' , (data ) => {
console .log ('Order shipped' , data);
});
});Prompt cho agent Dán nội dung này vào Claude Code, Cursor, GitHub Copilot hoặc một AI agent lập trình khác, và nó sẽ tích hợp Hibira vào dự án HTML của bạn với các cài đặt ở trên.
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);
});
});
```
Thay YOUR_APP_KEY và các giá trị giữ chỗ khác bằng giá trị từ bảng điều khiển, hoặc để agent giữ chúng dưới dạng biến môi trường để bạn tự điền.
Hoặc kết nối máy chủ MCP của Hibira, và agent của bạn có thể tự tạo ứng dụng và điền thông tin xác thực. Kết nối AI agent lập trình của bạn →
Dùng app key và secret từ bảng điều khiển. Kênh, sự kiện và endpoint xác thực hoạt động y như với Pusher. Tài liệu thư viện ↗