# Realtime, waiting rooms and chat for Ktor

> A Ktor 3 plugin in Kotlin: channel auth and webhook routes for pusher-js and Laravel Echo, a waiting room route plugin, and coroutine access to events, the Chat API and Approvals.

Source: https://hibira.io/guides/ktor

A Ktor 3 plugin in Kotlin: channel auth and webhook routes for pusher-js and Laravel Echo, a waiting room route plugin, and coroutine access to events, the Chat API and Approvals.

Package: io.hibira:hibira-ktor

- hibiraChannelAuth, hibiraUserAuth and hibiraWebhooks add the routes pusher-js and Laravel Echo need.
- install(HibiraWaitingRoom) on a route sends visitors without a pass to the hosted waiting page.
- Suspend functions for events, the Chat API and Approvals, and Live Chat verified visitors.

## 1. Install

```kotlin
implementation("io.hibira:hibira-ktor:0.1.0")
```

## 2. Set it up

```shell
HIBIRA_APP_ID=YOUR_APP_ID
HIBIRA_KEY=YOUR_APP_KEY
HIBIRA_SECRET=YOUR_APP_SECRET
HIBIRA_HOST=ws.hibira.io
```

## 3. Use it

```kotlin
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()}") }
        }
    }
}
```

## Before you start

- The app secret is shown only once, when you create the app or rotate its secret. Keep it on your server, never in a browser or game build.
- On the Free plan, list every origin your pages load from in the app’s allowed origins (http://localhost:3000 while developing, then your domain). "*" needs a paid plan.

- [Maven Central](https://central.sonatype.com/artifact/io.hibira/hibira-ktor)
- [GitHub](https://github.com/hibira-io/kotlin)
