Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions examples/webhooks-nextjs/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"extends": [
"../../.eslintrc",
"plugin:@next/next/recommended"
"../../.eslintrc"
],
"parserOptions": {
"project": ["./tsconfig.json"]
},
"settings": {
"react": {
"version": "18"
"version": "19"
}
}
}
}
}
20 changes: 12 additions & 8 deletions examples/webhooks-nextjs/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Using Webhooks with a Next.JS app
# Using Webhooks with a Next.js app

This example was generated using [create-next-app](https://nextjs.org/docs/api-reference/create-next-app).
This example shows how to receive [LiveKit webhooks](https://docs.livekit.io/home/server/webhooks/)
in a Next.js (App Router) application using `livekit-server-sdk`.

We've made the following modifications to the generated project:

- `pnpm add livekit-server-sdk`
- [webhook.ts](pages/api/webhook.ts)
- added API key and secret to [next.config.js](next.config.js)
The webhook handler lives in [app/api/webhook/route.ts](app/api/webhook/route.ts) and reads your
API key and secret from environment variables.

Follow these steps to see this demo in action:

Expand All @@ -20,7 +18,13 @@ Follow these steps to see this demo in action:
```

- Start livekit-server locally
- Open next.config.js and fill in your API key and secret pair
- Provide your API key and secret, e.g. in a `.env.local` file:

```
LIVEKIT_API_KEY=your-api-key
LIVEKIT_API_SECRET=your-api-secret
```

- Run this example with `pnpm dev`
- Connect a client to livekit-server
- Observe the following in your Next.js app logs:
Expand Down
13 changes: 13 additions & 0 deletions examples/webhooks-nextjs/app/api/webhook/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { WebhookReceiver } from 'livekit-server-sdk';

const receiver = new WebhookReceiver(
process.env.LIVEKIT_API_KEY!,
process.env.LIVEKIT_API_SECRET!,
);

export async function POST(req: Request) {
const body = await req.text();
const event = await receiver.receive(body, req.headers.get('Authorization') ?? undefined);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚩 SDK exports misleading authorizeHeader = 'Authorize' constant

The SDK at packages/livekit-server-sdk/src/WebhookReceiver.ts:9 exports authorizeHeader = 'Authorize', but the actual header used by LiveKit server is Authorization (per the SDK README examples at lines 140, 173 which use req.get('Authorization')). The new example correctly uses req.headers.get('Authorization'). The exported constant is unused within the SDK and appears to be a pre-existing inconsistency — it's not consumed anywhere in the codebase.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

console.log('received webhook event', event);
return new Response(null, { status: 200 });
}
16 changes: 16 additions & 0 deletions examples/webhooks-nextjs/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Metadata } from 'next';
import type { ReactNode } from 'react';
import './globals.css';

export const metadata: Metadata = {
title: 'LiveKit Webhooks Example',
description: 'Example using livekit-server-sdk to handle webhooks with Next.js',
};

export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
11 changes: 11 additions & 0 deletions examples/webhooks-nextjs/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function Home() {
return (
<main style={{ padding: '2rem', maxWidth: 640 }}>
<h1>LiveKit Webhooks Example</h1>
<p>
Webhook events sent by livekit-server are received at <code>/api/webhook</code> and logged
to the server console.
</p>
</main>
);
}
5 changes: 0 additions & 5 deletions examples/webhooks-nextjs/next.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
serverRuntimeConfig: {
livekitApiKey: 'your-api-key',
livekitApiSecret: 'your-api-secret',
},
};

module.exports = nextConfig;
15 changes: 7 additions & 8 deletions examples/webhooks-nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"lint": "eslint -f unix \"**/*.{ts,tsx}\""
},
"dependencies": {
"livekit-server-sdk": "workspace:*",
"next": "12.3.0",
"react": "18.2.0",
"react-dom": "18.2.0"
"next": "^16.0.0",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@next/eslint-plugin-next": "^14.2.4",
"@types/node": "18.7.18",
"@types/react": "18.0.20",
"@types/react-dom": "18.0.6"
"@types/node": "^22.0.0",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0"
}
}
9 changes: 0 additions & 9 deletions examples/webhooks-nextjs/pages/_app.tsx

This file was deleted.

17 changes: 0 additions & 17 deletions examples/webhooks-nextjs/pages/api/webhook.ts

This file was deleted.

73 changes: 0 additions & 73 deletions examples/webhooks-nextjs/pages/index.tsx

This file was deleted.

4 changes: 0 additions & 4 deletions examples/webhooks-nextjs/public/vercel.svg

This file was deleted.

129 changes: 0 additions & 129 deletions examples/webhooks-nextjs/styles/Home.module.css

This file was deleted.

Loading
Loading