47 lines
945 B
Go
47 lines
945 B
Go
package livekit
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/flowy-live/llink/internal/utils"
|
|
"github.com/livekit/protocol/auth"
|
|
)
|
|
|
|
type Client interface {
|
|
// Name will show up in the participant data
|
|
GetJoinToken(roomId string, humanId string, name 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, humanId, name string) (string, error) {
|
|
at := auth.NewAccessToken(c.apiKey, c.apiSecret)
|
|
grant := &auth.VideoGrant{
|
|
RoomJoin: true,
|
|
Room: room,
|
|
}
|
|
at.SetVideoGrant(grant).
|
|
SetIdentity(humanId).
|
|
SetName(name).
|
|
SetValidFor(time.Hour)
|
|
|
|
return at.ToJWT()
|
|
}
|