公式パッケージ · フレームワーク
SolidJS でシグナルを使ってライブ更新
SolidJS から pusher-js で Hibira のチャンネルを購読し、イベントをシグナルに変える小さなプリミティブを使います。オーナーとともに後片付けされます。プライベートチャンネルは SolidStart がサーバー側で署名します。
最速の方法:Hibira プラグインとプロンプト 1 つ
AI コーディングエージェントにプラグインを入れて、プロンプトを貼り付けるだけ。エージェントがサインインし、必要なら無料アプリを作成し、コードを書いてテストイベントを送ります。 GitHub ↗
プラグインをインストール
claude plugin marketplace add hibira-io/agent-plugin claude plugin install hibira@hibiraこのプロンプトを貼り付け
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 は最新のイベントを保持するシグナルを返し、コンポーネントのアンマウント時に購読を解除します。
- SolidStart の API ルートが pusher npm パッケージでプライベート・プレゼンスチャンネルに署名します。
サインインすると、コード例にご自身のクラスターホストが入ります。 サインイン
インストール
npm install pusher-js pusher使う
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');チャンネル購読に署名する
// 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')))); }
始める前に
- Free プランでは、ページを読み込むすべてのオリジンをアプリの許可オリジンに登録してください(開発中は http://localhost:3000、その後は自分のドメイン)。"*" は有料プランで使えます。
- アプリのシークレットは、アプリの作成時とシークレットのローテーション時に一度だけ表示されます。サーバーにだけ置き、ブラウザやゲームのビルドには入れないでください。
ダッシュボードのアプリキーを使ってください。シークレットはサーバー側だけに置きます。チャンネル、イベント、認可エンドポイントは Pusher とまったく同じように動作します。 無料でアカウントを作成 →