import { Status } from "../../../../constants/Project" ; import { FastifySchema , Response , ResponseError } from "../../../../types/Server" ; import { getRTCToken } from "../../../utils/AgoraToken" ; import { ErrorCode } from "../../../../ErrorCode" ; import { RoomUserDAO } from "../../../../dao" ; import { AbstractController } from "../../../../abstract/controller" ; import { Controller } from "../../../../decorator/Controller" ; @ Controller < RequestType , ResponseType > ( { method : "post" , path : "agora/token/generate/rtc" , auth : true , } ) export class GenerateRTC extends AbstractController < RequestType , ResponseType > { public static readonly schema : FastifySchema < RequestType > = { body : { type : "object" , required : [ "roomUUID" ] , properties : { roomUUID : { type : "string" , } , } , } , } ; public async execute ( ) { const { roomUUID } = this . body ; const roomUserInfo = await RoomUserDAO ( ) . findOne ( [ "rtc_uid" ] , { room_uuid : roomUUID , user_uuid : this . userUUID , } ) ; if ( roomUserInfo === undefined ) { return { status : Status . Failed , code : ErrorCode . RoomNotFound , } ; } const token = await getRTCToken ( roomUUID , Number ( roomUserInfo . rtc_uid ) ) ; return { status : Status . Success , data : { token , } , } ; } public errorHandler ( error ) { return this . autoHandlerError ( error ) ; } } interface RequestType { body : { roomUUID : string ; } ; } interface ResponseType { token : string ; }