Skip to content

Commit 69cf309

Browse files
authored
Include room preset/config in SIP tokens (#932)
* Include room preset/config in SIP tokens * changeset
1 parent 9e8d1e3 commit 69cf309

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

.changeset/tall-fans-try.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"github.com/livekit/protocol": patch
3+
---
4+
5+
include room preset/config in SIP tokens

sip/token.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,35 @@ import (
2121
"github.com/livekit/protocol/livekit"
2222
)
2323

24-
func BuildSIPToken(
25-
apiKey, secret, roomName string,
26-
participantIdentity, participantName, participantMeta string,
27-
participantAttrs map[string]string,
28-
) (string, error) {
24+
type SIPTokenParams struct {
25+
APIKey string
26+
APISecret string
27+
RoomName string
28+
ParticipantIdentity string
29+
ParticipantName string
30+
ParticipantMetadata string
31+
ParticipantAttributes map[string]string
32+
RoomPreset string
33+
RoomConfig *livekit.RoomConfiguration
34+
}
35+
36+
func BuildSIPToken(params SIPTokenParams) (string, error) {
2937
t := true
30-
at := auth.NewAccessToken(apiKey, secret).
31-
AddGrant(&auth.VideoGrant{
38+
at := auth.NewAccessToken(params.APIKey, params.APISecret).
39+
SetVideoGrant(&auth.VideoGrant{
3240
RoomJoin: true,
33-
Room: roomName,
41+
Room: params.RoomName,
3442
CanSubscribe: &t,
3543
CanPublish: &t,
3644
CanPublishData: &t,
3745
CanUpdateOwnMetadata: &t,
3846
}).
39-
SetIdentity(participantIdentity).
40-
SetName(participantName).
41-
SetMetadata(participantMeta).
42-
SetAttributes(participantAttrs).
47+
SetIdentity(params.ParticipantIdentity).
48+
SetName(params.ParticipantName).
49+
SetMetadata(params.ParticipantMetadata).
50+
SetAttributes(params.ParticipantAttributes).
51+
SetRoomPreset(params.RoomPreset).
52+
SetRoomConfig(params.RoomConfig).
4353
SetKind(livekit.ParticipantInfo_SIP).
4454
SetValidFor(24 * time.Hour)
4555

0 commit comments

Comments
 (0)