package livekit import ( "time" "github.com/flowy-live/llink/internal/utils" "github.com/livekit/protocol/auth" ) type Client interface { GetJoinToken(roomId string, identity string) (string, error) ServerUrl() string } type clientImpl struct { apiSecret string apiKey string hostUrl string } func NewClient() Client { return &clientImpl{ apiSecret: utils.MustGetEnv("LIVEKIT_API_SECRET"), apiKey: utils.MustGetEnv("LIVEKIT_API_KEY"), hostUrl: utils.MustGetEnv("LIVEKIT_URL"), } } func (c *clientImpl) ServerUrl() string { return c.hostUrl } func (c *clientImpl) GetJoinToken(room, identity string) (string, error) { at := auth.NewAccessToken(c.apiKey, c.apiSecret) grant := &auth.VideoGrant{ RoomJoin: true, Room: room, } at.SetVideoGrant(grant). SetIdentity(identity). SetValidFor(time.Hour) return at.ToJWT() }