Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into benjamin/agents
Browse files Browse the repository at this point in the history
  • Loading branch information
biglittlebigben committed Jun 24, 2024
2 parents edc26e4 + 6dec8d2 commit 2366dd8
Show file tree
Hide file tree
Showing 40 changed files with 6,635 additions and 3,299 deletions.
5 changes: 0 additions & 5 deletions .changeset/moody-boats-kick.md

This file was deleted.

5 changes: 5 additions & 0 deletions .changeset/purple-swans-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@livekit/protocol": patch
---

Add ErrorResponse
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# github.com/livekit/protocol

## 1.19.0

### Minor Changes

- Add SIP grants. - [#745](https://github.com/livekit/protocol/pull/745) ([@dennwc](https://github.com/dennwc))

### Patch Changes

- Fix typo in SIP Trunk conversion. - [#744](https://github.com/livekit/protocol/pull/744) ([@dennwc](https://github.com/dennwc))

## 1.18.0

### Minor Changes

- Split SIP Trunk configuration to inbound and outbound parts. - [#738](https://github.com/livekit/protocol/pull/738) ([@dennwc](https://github.com/dennwc))

- add Participant attributes key/val storage - [#733](https://github.com/livekit/protocol/pull/733) ([@davidzhao](https://github.com/davidzhao))

### Patch Changes

- Simplify number matching rules for SIP. - [#737](https://github.com/livekit/protocol/pull/737) ([@dennwc](https://github.com/dennwc))

- Added session token option for s3 uploads - [#734](https://github.com/livekit/protocol/pull/734) ([@frostbyte73](https://github.com/frostbyte73))

- Include analytics event ids - [#739](https://github.com/livekit/protocol/pull/739) ([@davidzhao](https://github.com/davidzhao))

## 1.17.0

### Minor Changes
Expand Down
18 changes: 18 additions & 0 deletions auth/accesstoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,29 @@ func (t *AccessToken) AddGrant(grant *VideoGrant) *AccessToken {
return t
}

func (t *AccessToken) AddSIPGrant(grant *SIPGrant) *AccessToken {
t.grant.SIP = grant
return t
}

func (t *AccessToken) SetMetadata(md string) *AccessToken {
t.grant.Metadata = md
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
3 changes: 3 additions & 0 deletions auth/accesstoken_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ func TestAccessToken(t *testing.T) {
t.Run("generates a decode-able key", func(t *testing.T) {
apiKey, secret := apiKeypair()
videoGrant := &VideoGrant{RoomJoin: true, Room: "myroom"}
sipGrant := &SIPGrant{Admin: true}
at := NewAccessToken(apiKey, secret).
AddGrant(videoGrant).
AddSIPGrant(sipGrant).
SetValidFor(time.Minute * 5).
SetKind(livekit.ParticipantInfo_AGENT).
SetIdentity("user")
Expand All @@ -60,6 +62,7 @@ func TestAccessToken(t *testing.T) {

require.EqualValues(t, livekit.ParticipantInfo_AGENT, decodedGrant.GetParticipantKind())
require.EqualValues(t, videoGrant, decodedGrant.Video)
require.EqualValues(t, sipGrant, decodedGrant.SIP)
})

t.Run("missing kind should be interpreted as standard", func(t *testing.T) {
Expand Down
24 changes: 24 additions & 0 deletions auth/grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package auth

import (
"maps"
"strings"

"golang.org/x/exp/slices"
Expand Down Expand Up @@ -56,14 +57,25 @@ type VideoGrant struct {
Agent bool `json:"agent,omitempty"`
}

type SIPGrant struct {
// Admin grants access to all SIP features.
Admin bool `json:"admin,omitempty"`

// Call allows making outbound SIP calls.
Call bool `json:"call,omitempty"`
}

type ClaimGrants struct {
Identity string `json:"-"`
Name string `json:"name,omitempty"`
Kind string `json:"kind,omitempty"`
Video *VideoGrant `json:"video,omitempty"`
SIP *SIPGrant `json:"sip,omitempty"`
// for verifying integrity of the message body
Sha256 string `json:"sha256,omitempty"`
Metadata string `json:"metadata,omitempty"`
// Key/value attributes to attach to the participant
Attributes map[string]string `json:"attributes,omitempty"`
}

func (c *ClaimGrants) SetParticipantKind(kind livekit.ParticipantInfo_Kind) {
Expand All @@ -81,6 +93,8 @@ func (c *ClaimGrants) Clone() *ClaimGrants {

clone := *c
clone.Video = c.Video.Clone()
clone.SIP = c.SIP.Clone()
clone.Attributes = maps.Clone(c.Attributes)

return &clone
}
Expand Down Expand Up @@ -262,6 +276,16 @@ func (v *VideoGrant) Clone() *VideoGrant {
return &clone
}

func (s *SIPGrant) Clone() *SIPGrant {
if s == nil {
return nil
}

clone := *s

return &clone
}

func sourceToString(source livekit.TrackSource) string {
return strings.ToLower(source.String())
}
Expand Down
5 changes: 4 additions & 1 deletion auth/verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ func TestVerifier(t *testing.T) {
"number": float64(3),
}
md, _ := json.Marshal(metadata)
attrs := map[string]string{"mykey": "myval", "secondkey": "secondval"}
at := auth.NewAccessToken(apiKey, secret).
AddGrant(&auth.VideoGrant{
RoomAdmin: true,
Room: "myroom",
}).
SetMetadata(string(md))
SetMetadata(string(md)).
SetAttributes(attrs)

authToken, err := at.ToJWT()
require.NoError(t, err)
Expand All @@ -90,6 +92,7 @@ func TestVerifier(t *testing.T) {
require.NoError(t, err)

require.EqualValues(t, string(md), decoded.Metadata)
require.EqualValues(t, attrs, decoded.Attributes)
})

t.Run("nil permissions are handled", func(t *testing.T) {
Expand Down
19 changes: 19 additions & 0 deletions livekit/attrs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package livekit

// Names of participant attributes for SIP.
const (
// AttrSIPPrefix is shared for all SIP attributes.
AttrSIPPrefix = "sip."
// AttrSIPCallID attribute contains LiveKit SIP call ID.
AttrSIPCallID = AttrSIPPrefix + "callID"
// AttrSIPTrunkID attribute contains LiveKit SIP Trunk ID used for the call.
AttrSIPTrunkID = AttrSIPPrefix + "trunkID"
// AttrSIPDispatchRuleID attribute contains LiveKit SIP DispatchRule ID used for the inbound call.
AttrSIPDispatchRuleID = AttrSIPPrefix + "ruleID"
// AttrSIPTrunkNumber attribute contains number associate with LiveKit SIP Trunk.
// This attribute will be omitted if HidePhoneNumber is set.
AttrSIPTrunkNumber = AttrSIPPrefix + "trunkPhoneNumber"
// AttrSIPPhoneNumber attribute contains number external to LiveKit SIP (caller for inbound and called number for outbound).
// This attribute will be omitted if HidePhoneNumber is set.
AttrSIPPhoneNumber = AttrSIPPrefix + "phoneNumber"
)
28 changes: 24 additions & 4 deletions livekit/livekit_analytics.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2366dd8

Please sign in to comment.