Gói chính thức · Framework
Cập nhật trực tiếp trong SolidJS bằng signal
Đăng ký kênh Hibira từ SolidJS bằng pusher-js và một primitive nhỏ biến sự kiện thành signal, được dọn dẹp cùng chủ sở hữu của nó. SolidStart ký kênh riêng tư trên máy chủ.
Cách nhanh nhất: plugin Hibira và một prompt
Cài plugin vào agent lập trình AI của bạn rồi dán prompt. Agent sẽ đăng nhập, tạo ứng dụng miễn phí nếu cần, viết mã và gửi một sự kiện thử. GitHub ↗
Cài plugin
claude plugin marketplace add hibira-io/agent-plugin claude plugin install hibira@hibiraDán prompt này
Add Hibira SolidJS (pusher-js) to this project. Follow https://hibira.io/guides/solidjs, 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.
- createEvent trả về một signal giữ sự kiện mới nhất và hủy đăng ký khi component bị unmount.
- Một route API của SolidStart ký kênh riêng tư và presence bằng gói pusher trên npm.
Đă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
Cài đặt
npm install pusher-js pusherSử dụng
import Pusher from 'pusher-js'; import { createSignal, onCleanup } from 'solid-js'; const pusher = new Pusher(import.meta.env.VITE_HIBIRA_APP_KEY, { cluster: 'hkg', wsHost: 'ws.hibira.io', channelAuthorization: { endpoint: '/api/hibira/auth', transport: 'ajax' }, }); export function createEvent<T>(channelName: string, event: string) { const [value, setValue] = createSignal<T>(); const channel = pusher.subscribe(channelName); const handler = (data: T) => setValue(() => data); channel.bind(event, handler); onCleanup(() => channel.unbind(event, handler)); return value; } // const order = createEvent<{ id: number }>('orders', 'order.shipped');Ký đăng ký kênh
// src/routes/api/hibira/auth.ts (SolidStart) import Pusher from 'pusher'; const pusher = new Pusher({ appId: process.env.HIBIRA_APP_ID!, key: process.env.HIBIRA_APP_KEY!, secret: process.env.HIBIRA_APP_SECRET!, host: 'ws.hibira.io', port: '443', useTLS: true, }); export async function POST({ request }: { request: Request }) { const form = await request.formData(); // check the signed-in user may join this channel first return Response.json(pusher.authorizeChannel(String(form.get('socket_id')), String(form.get('channel_name')))); }
Trước khi bắt đầu
- Với gói Free, hãy thêm mọi origin mà trang của bạn tải từ đó vào Origin được phép của ứng dụng (http://localhost:3000 khi phát triển, sau đó là tên miền của bạn). "*" cần gói trả phí.
- Secret của ứng dụng chỉ hiện một lần, khi bạn tạo ứng dụng hoặc xoay vòng secret. Hãy giữ nó trên máy chủ, không bao giờ đưa vào trình duyệt hay bản build game.
Dùng app key từ bảng điều khiển; secret chỉ để trên máy chủ của bạn. Kênh, sự kiện và endpoint xác thực hoạt động y như với Pusher. Tạo tài khoản miễn phí →