package server import ( "time" "forge.redroom.link/yves/meowlib" "github.com/livekit/protocol/auth" ) type VideoServer struct { Url string `json:"url,omitempty"` ApiKey string `json:"api_key,omitempty"` ApiSecret string `json:"secret,omitempty"` } func (s *VideoServer) GetJoinToken(room, username string, validity time.Duration) (string, error) { at := auth.NewAccessToken(s.ApiKey, s.ApiSecret) grant := &auth.VideoGrant{ RoomJoin: true, Room: room, } at.AddGrant(grant). SetIdentity(username). SetValidFor(validity) return at.ToJWT() } func (s *VideoServer) UpdateVideoData(vd *meowlib.VideoData) (*meowlib.VideoData, error) { vd.Url = s.Url vd.Credentials = []*meowlib.VideoCredential{} for idx := range len(vd.Credentials) { token, err := s.GetJoinToken(vd.Room, vd.Credentials[idx].Username, time.Duration(vd.Duration*uint64(time.Second))) if err != nil { return nil, err } vd.Credentials[idx].Token = token vd.Credentials[idx].SharedKey = s.ApiKey } return vd, nil }