-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from livekit-examples:small-fixes
Small changes and clean ups
- Loading branch information
Showing
4 changed files
with
71 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { | ||
AccessToken, | ||
AccessTokenOptions, | ||
VideoGrant, | ||
} from "livekit-server-sdk"; | ||
import { NextResponse } from "next/server"; | ||
|
||
const API_KEY = process.env.LIVEKIT_API_KEY; | ||
const API_SECRET = process.env.LIVEKIT_API_SECRET; | ||
const LIVEKIT_URL = process.env.LIVEKIT_URL; | ||
|
||
export type ConnectionDetails = { | ||
serverUrl: string; | ||
roomName: string; | ||
participantName: string; | ||
participantToken: string; | ||
}; | ||
|
||
export async function GET() { | ||
try { | ||
// Generate participant token | ||
const participantIdentity = `voice_assistant_user_${Math.round( | ||
Math.random() * 10_000 | ||
)}`; | ||
const participantToken = await createParticipantToken( | ||
{ | ||
identity: participantIdentity, | ||
}, | ||
"roomName" | ||
); | ||
|
||
if (LIVEKIT_URL === undefined) { | ||
throw new Error("LIVEKIT_URL is not defined"); | ||
} | ||
|
||
// Return connection details | ||
const data: ConnectionDetails = { | ||
serverUrl: LIVEKIT_URL, | ||
roomName: "voice_assistant_room", | ||
participantToken: participantToken, | ||
participantName: participantIdentity, | ||
}; | ||
return NextResponse.json(data); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
console.error(error); | ||
|
||
return new NextResponse(error.message, { status: 500 }); | ||
} | ||
} | ||
} | ||
|
||
function createParticipantToken( | ||
userInfo: AccessTokenOptions, | ||
roomName: string | ||
) { | ||
const at = new AccessToken(API_KEY, API_SECRET, userInfo); | ||
at.ttl = "5m"; | ||
const grant: VideoGrant = { | ||
room: roomName, | ||
roomJoin: true, | ||
canPublish: true, | ||
canPublishData: true, | ||
canSubscribe: true, | ||
}; | ||
at.addGrant(grant); | ||
return at.toJwt(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,3 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
|
||
:root { | ||
--background: #ffffff; | ||
--foreground: #171717; | ||
} | ||
|
||
@media (prefers-color-scheme: dark) { | ||
:root { | ||
--background: #0a0a0a; | ||
--foreground: #ededed; | ||
} | ||
} | ||
|
||
body { | ||
color: var(--foreground); | ||
background: var(--background); | ||
font-family: Arial, Helvetica, sans-serif; | ||
} | ||
|
||
@layer utilities { | ||
.text-balance { | ||
text-wrap: balance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters