# Elysia

> Mount the pipedog WebRTC offer endpoint in an Elysia app on Bun.

Source: https://polvallverdu.github.io/pipedog/docs/frameworks/elysia/



Elysia runs on Bun. The offer is a route that passes Elysia's web `Request` to `offer`. This snippet
mounts only the offer.

## Install [#install]

```bash
bun add @pipedog/core @pipedog/asyncio @pipedog/transport-smallwebrtc @pipedog/transport-websocket @pipedog/serializer-protobuf @pipedog/openai @pipedog/audio-silero @pipedog/audio-smart-turn elysia
```

`@pipedog/audio-smart-turn` isn't imported anywhere: the default turn strategies load it. To run
the snippet from a checkout instead, see [Installation](https://polvallverdu.github.io/pipedog/docs/installation/#from-source).

## Files [#files]

The endpoints come from the shared module on the [overview](https://polvallverdu.github.io/pipedog/docs/frameworks/#the-two-endpoints).
`voice.ts` re-exports it:

```ts title="voice.ts"
export { offer, runSocketAgent, socket } from "../shared/voice.ts";

```

```ts title="server.ts"
import { Elysia } from "elysia";
import { offer } from "./voice.ts";

export const app = new Elysia().post("/api/offer", ({ request }) => offer(request));

// `bun server.ts` starts it on port 3000.
if (import.meta.main) {
  app.listen(3000);
}

```

## Run it [#run-it]

```bash
OPENAI_API_KEY=sk-... bun server.ts
```

It listens on port 3000, at `POST /api/offer`.

## Deploy [#deploy]

Run it as a long-lived Bun process on a host that allows UDP traffic, for the offer's media.

## WebSocket [#websocket]

Elysia has its own WebSocket route API (`.ws()`), which this snippet doesn't use. To serve WebSocket
sessions, wire `.ws()` to a `WebsocketConnection` the way the [Bun](https://polvallverdu.github.io/pipedog/docs/frameworks/bun.md) snippet
does, or run the Bun snippet next to this app.

## Authentication [#authentication]

The route has no auth. Wrap `offer` with a session check before it runs, or use an Elysia
`beforeHandle` hook, as in [Authentication](https://polvallverdu.github.io/pipedog/docs/frameworks/#authentication).
