set human name in livekit room context
This commit is contained in:
@@ -1064,6 +1064,11 @@ func (h *Handler) GetLivekitToken(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Error(w, "unauthorized", http.StatusUnauthorized)
|
http.Error(w, "unauthorized", http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
humanEmail, ok := middleware.EmailFromContext(r.Context())
|
||||||
|
if !ok {
|
||||||
|
http.Error(w, "unauthorized", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var req GetLivekitTokenRequest
|
var req GetLivekitTokenRequest
|
||||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||||
@@ -1076,7 +1081,7 @@ func (h *Handler) GetLivekitToken(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
token, err := h.livekitClient.GetJoinToken(req.RoomId, humanId)
|
token, err := h.livekitClient.GetJoinToken(req.RoomId, humanId, humanEmail)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("failed to generate livekit token", "error", err, "humanId", humanId, "roomId", req.RoomId)
|
slog.Error("failed to generate livekit token", "error", err, "humanId", humanId, "roomId", req.RoomId)
|
||||||
http.Error(w, "failed to generate token", http.StatusInternalServerError)
|
http.Error(w, "failed to generate token", http.StatusInternalServerError)
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Client interface {
|
type Client interface {
|
||||||
GetJoinToken(roomId string, identity string) (string, error)
|
// Name will show up in the participant data
|
||||||
|
GetJoinToken(roomId string, humanId string, name string) (string, error)
|
||||||
ServerUrl() string
|
ServerUrl() string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,14 +31,15 @@ func (c *clientImpl) ServerUrl() string {
|
|||||||
return c.hostUrl
|
return c.hostUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *clientImpl) GetJoinToken(room, identity string) (string, error) {
|
func (c *clientImpl) GetJoinToken(room, humanId, name string) (string, error) {
|
||||||
at := auth.NewAccessToken(c.apiKey, c.apiSecret)
|
at := auth.NewAccessToken(c.apiKey, c.apiSecret)
|
||||||
grant := &auth.VideoGrant{
|
grant := &auth.VideoGrant{
|
||||||
RoomJoin: true,
|
RoomJoin: true,
|
||||||
Room: room,
|
Room: room,
|
||||||
}
|
}
|
||||||
at.SetVideoGrant(grant).
|
at.SetVideoGrant(grant).
|
||||||
SetIdentity(identity).
|
SetIdentity(humanId).
|
||||||
|
SetName(name).
|
||||||
SetValidFor(time.Hour)
|
SetValidFor(time.Hour)
|
||||||
|
|
||||||
return at.ToJWT()
|
return at.ToJWT()
|
||||||
|
|||||||
Reference in New Issue
Block a user