where is the code of token server in LiveKit JS SD...
# ask-ai
h
where is the code of token server in LiveKit JS SDK?
t
Thanks for reaching out, YUNYI. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Just a heads-up: the token server code isn’t included in the LiveKit JavaScript SDK (
livekit-client
) because that SDK is mainly for using tokens to connect to LiveKit. Instead, token generation happens on the backend with the LiveKit Server SDK (
livekit-server-sdk
). For example, here’s a simple way to create a token server using Node.js and Express:
Copy code
app.post('/api/get-token', async (req, res) => {
  const { identity, roomName } = req.body;
  const token = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET, { identity });
  token.addGrant({ room: roomName, roomJoin: true, canPublish: true, canSubscribe: true });
  res.json({ token: await token.toJwt(), url: LIVEKIT_URL });
});
Also, LiveKit offers a handy Node.js token server template that you can check out for guidance. If you want a hand setting up your token server or have any questions, just give me a shout—I’m here to help! Sources: TEMPLATE.md | JavaScript quickstart (web) | LiveKit Docs | examples/rpc/api.ts | client/web/src/app/api/token/route.ts
h
Can I specify the agent I want to use in JS SDK, I change the access token so it can include agent name
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!