Skip to content

Commit

Permalink
add kv attrs to sip token
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc committed Jun 17, 2024
1 parent 05359df commit 031b1e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 13 additions & 0 deletions auth/accesstoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ func (t *AccessToken) SetMetadata(md string) *AccessToken {
return t
}

func (t *AccessToken) SetAttributes(attrs map[string]string) *AccessToken {
if len(attrs) == 0 {
return t
}
if t.grant.Attributes == nil {
t.grant.Attributes = make(map[string]string)
}
for k, v := range attrs {
t.grant.Attributes[k] = v
}
return t
}

func (t *AccessToken) SetSha256(sha string) *AccessToken {
t.grant.Sha256 = sha
return t
Expand Down
7 changes: 6 additions & 1 deletion sip/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import (
"github.com/livekit/protocol/livekit"
)

func BuildSIPToken(apiKey, secret, roomName, participantIdentity, participantName, participantMeta string) (string, error) {
func BuildSIPToken(
apiKey, secret, roomName string,
participantIdentity, participantName, participantMeta string,
participantAttrs map[string]string,
) (string, error) {
t := true
at := auth.NewAccessToken(apiKey, secret).
AddGrant(&auth.VideoGrant{
Expand All @@ -33,6 +37,7 @@ func BuildSIPToken(apiKey, secret, roomName, participantIdentity, participantNam
SetIdentity(participantIdentity).
SetName(participantName).
SetMetadata(participantMeta).
SetAttributes(participantAttrs).
SetKind(livekit.ParticipantInfo_SIP).
SetValidFor(24 * time.Hour)

Expand Down

0 comments on commit 031b1e9

Please sign in to comment.