公式パッケージ · フレームワーク

Ktor のためのリアルタイム・待合室・チャット

Kotlin で書かれた Ktor 3 プラグイン:pusher-js と Laravel Echo に必要なチャンネル認可と Webhook のルート、待合室のルートプラグイン、そしてコルーチンでのイベント・Chat API・Approvals の利用を提供します。

Maven Central のバージョンライセンス

最速の方法:Hibira プラグインとプロンプト 1 つ

AI コーディングエージェントにプラグインを入れて、プロンプトを貼り付けるだけ。エージェントがサインインし、必要なら無料アプリを作成し、コードを書いてテストイベントを送ります。 GitHub ↗

  1. プラグインをインストール

    claude plugin marketplace add hibira-io/agent-plugin
    claude plugin install hibira@hibira
  2. このプロンプトを貼り付け

    Add Hibira Ktor (io.hibira:hibira-ktor) to this project.
    Follow https://hibira.io/guides/ktor, 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.
  • hibiraChannelAuth・hibiraUserAuth・hibiraWebhooks で、pusher-js と Laravel Echo に必要なルートを追加します。
  • ルートで install(HibiraWaitingRoom) すると、パスのない訪問者はホスト型の待合ページに送られます。
  • イベント・Chat API・Approvals の suspend 関数と、Live Chat の認証済み訪問者。

サインインすると、コード例にご自身のクラスターホストが入ります。 サインイン

  1. インストール

    implementation("io.hibira:hibira-ktor:0.1.0")
  2. 設定する

    HIBIRA_APP_ID=YOUR_APP_ID
    HIBIRA_KEY=YOUR_APP_KEY
    HIBIRA_SECRET=YOUR_APP_SECRET
    HIBIRA_HOST=ws.hibira.io
  3. 使う

    fun Application.module() {
        install(HibiraPlugin)
        routing {
            hibiraChannelAuth { channel ->
                val user = principal<UserIdPrincipal>() ?: return@hibiraChannelAuth deny()
                if (channel.startsWith("presence-")) presence(user.name) else allow()
            }
            route("/drop") {
                install(HibiraWaitingRoom) { room = "presale" }
                get { call.respondText("You are number ${call.waitingRoomPass!!.number()}") }
            }
        }
    }

始める前に

  • アプリのシークレットは、アプリの作成時とシークレットのローテーション時に一度だけ表示されます。サーバーにだけ置き、ブラウザやゲームのビルドには入れないでください。
  • Free プランでは、ページを読み込むすべてのオリジンをアプリの許可オリジンに登録してください(開発中は http://localhost:3000、その後は自分のドメイン)。"*" は有料プランで使えます。

ダッシュボードのアプリキーを使ってください。シークレットはサーバー側だけに置きます。チャンネル、イベント、認可エンドポイントは Pusher とまったく同じように動作します。 無料でアカウントを作成 →