แพ็กเกจอย่างเป็นทางการ · เฟรมเวิร์ก
อัปเดตสดใน Qwik
เชื่อมต่อกับ Hibira จากคอมโพเนนต์ Qwik เมื่อมองเห็นแล้วเท่านั้น เพื่อไม่ให้ pusher-js อยู่ในการโหลดครั้งแรก และลงนามช่องส่วนตัวใน endpoint ของ Qwik City
วิธีที่เร็วที่สุด: ปลั๊กอิน Hibira กับพรอมต์เดียว
ติดตั้งปลั๊กอินในเอเจนต์เขียนโค้ด AI ของคุณแล้ววางพรอมต์ เอเจนต์จะลงชื่อเข้าใช้ สร้างแอปฟรีหากจำเป็น เขียนโค้ด และส่งอีเวนต์ทดสอบให้ GitHub ↗
ติดตั้งปลั๊กอิน
claude plugin marketplace add hibira-io/agent-plugin claude plugin install hibira@hibiraวางพรอมต์นี้
Add Hibira Qwik (pusher-js) to this project. Follow https://hibira.io/guides/qwik, 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.
อยากทำเองใช่ไหม ขั้นตอนด้านล่างมีดังนี้:
- useVisibleTask$ โหลด pusher-js เมื่อต้องการ และตัดการเชื่อมต่อตอน cleanup
- endpoint onPost ของ Qwik City ลงนามช่องส่วนตัวและ presence ด้วยแพ็กเกจ pusher จาก npm
ลงชื่อเข้าใช้เพื่อดูโค้ดตัวอย่างเหล่านี้พร้อมโฮสต์คลัสเตอร์ของคุณเอง ลงชื่อเข้าใช้
ติดตั้ง
npm install pusher-js pusherใช้งาน
import { component$, useSignal, useVisibleTask$ } from '@builder.io/qwik'; export default component$(() => { const status = useSignal('Waiting for updates'); useVisibleTask$(async ({ cleanup }) => { const { default: Pusher } = await import('pusher-js'); const pusher = new Pusher(import.meta.env.PUBLIC_HIBIRA_APP_KEY, { cluster: 'hkg', wsHost: 'ws.hibira.io', channelAuthorization: { endpoint: '/api/hibira/auth', transport: 'ajax' }, }); pusher.subscribe('orders').bind('order.shipped', (o: { id: number }) => (status.value = `Order #${o.id} shipped`)); cleanup(() => pusher.disconnect()); }); return <p>{status.value}</p>; });ลงนามการสมัครช่อง
// src/routes/api/hibira/auth/index.ts import type { RequestHandler } from '@builder.io/qwik-city'; import Pusher from 'pusher'; export const onPost: RequestHandler = async ({ parseBody, env, json }) => { const pusher = new Pusher({ appId: env.get('HIBIRA_APP_ID')!, key: env.get('HIBIRA_APP_KEY')!, secret: env.get('HIBIRA_APP_SECRET')!, host: 'ws.hibira.io', port: '443', useTLS: true, }); const form = (await parseBody()) as Record<string, string>; // check the signed-in user may join this channel first json(200, pusher.authorizeChannel(form.socket_id, form.channel_name)); };
ก่อนเริ่ม
- ในแพ็กเกจ Free ให้ใส่ทุก origin ที่หน้าเว็บโหลดมาใน Origin ที่อนุญาตของแอป (http://localhost:3000 ระหว่างพัฒนา แล้วตามด้วยโดเมนของคุณ) ส่วน "*" ต้องใช้แพ็กเกจแบบชำระเงิน
- ซีเคร็ตของแอปจะแสดงเพียงครั้งเดียว ตอนสร้างแอปหรือตอนหมุนเวียนซีเคร็ต เก็บไว้บนเซิร์ฟเวอร์เท่านั้น ห้ามใส่ในเบราว์เซอร์หรือไฟล์บิลด์ของเกม
ใช้ app key จากแดชบอร์ดของคุณ ส่วน secret ให้เก็บไว้บนเซิร์ฟเวอร์เท่านั้น ช่อง อีเวนต์ และ endpoint การยืนยันสิทธิ์ทำงานเหมือนกับที่ใช้กับ Pusher ทุกประการ สร้างบัญชีฟรีของคุณ →