add token endpoint for livekit
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
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)
|
||||
}
|
||||
|
||||
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) 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()
|
||||
}
|
||||
Reference in New Issue
Block a user