livekit
This commit is contained in:
38
apps/dispatch-server/routes/livekit.ts
Normal file
38
apps/dispatch-server/routes/livekit.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { Router } from "express";
|
||||
import { AccessToken } from "livekit-server-sdk";
|
||||
|
||||
if (!process.env.LIVEKIT_API_KEY) throw new Error("LIVEKIT_API_KEY not set");
|
||||
if (!process.env.LIVEKIT_API_SECRET)
|
||||
throw new Error("LIVEKIT_API_SECRET not set");
|
||||
|
||||
const createToken = async () => {
|
||||
// If this room doesn't exist, it'll be automatically created when the first
|
||||
// participant joins
|
||||
const roomName = "quickstart-room";
|
||||
// Identifier to be used for participant.
|
||||
// It's available as LocalParticipant.identity with livekit-client SDK
|
||||
const participantName = "quickstart-username";
|
||||
|
||||
const at = new AccessToken(
|
||||
process.env.LIVEKIT_API_KEY,
|
||||
process.env.LIVEKIT_API_SECRET,
|
||||
{
|
||||
identity: participantName,
|
||||
// Token to expire after 10 minutes
|
||||
ttl: "10m",
|
||||
},
|
||||
);
|
||||
at.addGrant({ roomJoin: true, room: roomName });
|
||||
|
||||
return await at.toJwt();
|
||||
};
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get("/token", async (req, res) => {
|
||||
res.send({
|
||||
token: await createToken(),
|
||||
});
|
||||
});
|
||||
|
||||
export default router;
|
||||
8
apps/dispatch-server/routes/router.ts
Normal file
8
apps/dispatch-server/routes/router.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Router } from "express";
|
||||
import livekitRouter from "./livekit";
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.use("/livekit", livekitRouter);
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user