Verifies LiveKit room JWTs and signs admin tokens for gateway.
// Source: https://github.com/YunaiV/yudao-cloud | License: MIT | Copyright 2021 yudao-cloud
// Provided via justclaw.it.com; keep this notice with the code.
// LiveKit 房间 Token 校验与网关管理 Token 签发:仅支持 HS256,与后端 LiveKitClient.signJoinToken 保持一致
import { createHmac, timingSafeEqual } from 'node:crypto'
const MAX_TOKEN_LENGTH = 4096 // 拒绝超长 Token,避免无意义的解析开销
const USER_IDENTITY_PATTERN = /^[1-9]\d{0,18}$/ // 业务 identity:数字 userId,与后端 buildIdentity 一致
const MAX_ROOM_LENGTH = 128 // 房间名长度上限
/** 房间 Token 校验失败;status 为返回给客户端的 HTTP 状态码 */
export class TokenError extends Error {
/**
* @param {string} code 错误码
* @param {string} message 错误说明(不包含 Token 内容)
* @param {number} status HTTP 状态码
*/
constructor(code, message, status = 401) {
super(message)
this.code = code
this.sta
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key