# Axum과 Actix Web을 위한 실시간, 대기실, 채팅

> Hibira crate는 이벤트를 보내고, 채널 구독과 웹훅에 서명·검증하고, Axum 또는 Actix Web 라우트 앞에 대기실을 두고, Chat API와 Approvals를 호출합니다.

Source: https://hibira.io/ko/guides/rust

Hibira crate는 이벤트를 보내고, 채널 구독과 웹훅에 서명·검증하고, Axum 또는 Actix Web 라우트 앞에 대기실을 두고, Chat API와 Approvals를 호출합니다.

Package: hibira

- Axum과 Actix Web용 대기실 미들웨어. 핸들러가 방문자의 패스를 받습니다.
- 비공개·presence 채널 인증, pusher-js 로그인, 웹훅 검증을 지원하며, client feature를 끄면 네트워크 코드가 포함되지 않습니다.
- 같은 crate에서 Chat API, Approvals, Live Chat 인증 방문자도 사용할 수 있습니다.

## 1. 설치

```shell
cargo add hibira --features axum   # or --features actix
```

## 2. 설정하기

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

## 3. 사용하기

```rust
use std::sync::Arc;
use axum::{middleware, routing::get, Extension, Router};
use hibira::{waiting_room::axum_guard, Client, Config, Pass};

let config = Config::from_env()?;
let hibira = Client::new(config.clone());
hibira.trigger(&["orders"], "order.shipped", &serde_json::json!({ "id": 1042 })).await?;

let app = Router::new()
    .route("/drop", get(|Extension(pass): Extension<Pass>| async move { format!("You are number {}", pass.number) }))
    .layer(middleware::from_fn_with_state(Arc::new(config.waiting_room("presale")), axum_guard));
```

## 시작하기 전에

- 앱 시크릿은 앱을 만들거나 시크릿을 교체할 때 한 번만 표시됩니다. 서버에만 두고, 브라우저나 게임 빌드에는 절대 넣지 마세요.
- 프라이빗 채널과 프레즌스 채널에는 pusher-js와 마찬가지로, 앱 시크릿으로 구독에 서명하는 인증 엔드포인트가 백엔드에 필요합니다.

- [crates.io](https://crates.io/crates/hibira)
- [GitHub](https://github.com/hibira-io/rust)
