From 3929f502ecd9887afa661c72a98e5f89dd37deac Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 27 Apr 2024 22:20:48 +0800 Subject: [PATCH] :sparkles: Provide userinfo for livekit --- pkg/services/calls.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/services/calls.go b/pkg/services/calls.go index dc217ea..44ea606 100644 --- a/pkg/services/calls.go +++ b/pkg/services/calls.go @@ -7,6 +7,7 @@ import ( "git.solsynth.dev/hydrogen/messaging/pkg/database" "git.solsynth.dev/hydrogen/messaging/pkg/external" "git.solsynth.dev/hydrogen/messaging/pkg/models" + jsoniter "github.com/json-iterator/go" "github.com/livekit/protocol/auth" "github.com/livekit/protocol/livekit" "github.com/rs/zerolog/log" @@ -158,9 +159,15 @@ func EncodeCallToken(user models.Account, call models.Call) (string, error) { RoomAdmin: isAdmin, } + metadata, _ := jsoniter.Marshal(user) + duration := time.Second * time.Duration(viper.GetInt("calling.token_duration")) tk := auth.NewAccessToken(viper.GetString("calling.api_key"), viper.GetString("calling.api_secret")) - tk.AddGrant(grant).SetIdentity(user.Name).SetValidFor(duration) + tk.AddGrant(grant). + SetIdentity(user.Name). + SetName(user.Nick). + SetMetadata(string(metadata)). + SetValidFor(duration) return tk.ToJWT() }