Skip to content

Commit

Permalink
Support get for SIP resources. (#575)
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc authored Dec 11, 2024
1 parent 59f3bc1 commit 7610e16
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/gorilla/websocket v1.5.3
github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1
github.com/livekit/mediatransportutil v0.0.0-20241128072814-c363618d4c98
github.com/livekit/protocol v1.29.3
github.com/livekit/protocol v1.29.5-0.20241209183753-f6b5078b2244
github.com/magefile/mage v1.15.0
github.com/pion/dtls/v3 v3.0.4
github.com/pion/interceptor v0.1.37
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 h1:jm09419p0lqTkD
github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ=
github.com/livekit/mediatransportutil v0.0.0-20241128072814-c363618d4c98 h1:QA7DqIC/ZSsMj8HC0+zNfMMwssHbA0alZALK68r30LQ=
github.com/livekit/mediatransportutil v0.0.0-20241128072814-c363618d4c98/go.mod h1:WIVFAGzVZ7VMjPC5+nbSfwdFjWcbuLgx97KeNSUDTEo=
github.com/livekit/protocol v1.29.3 h1:aAKhnc/E8H8uTB3sGmsp4OOtXV9vab2PqA57+SnDHEU=
github.com/livekit/protocol v1.29.3/go.mod h1:NDg1btMpKCzr/w6QR5kDuXw/e4Y7yOBE+RUAHsc+Y/M=
github.com/livekit/protocol v1.29.5-0.20241209183753-f6b5078b2244 h1:Eg9HK+5bMCDRKhh5g5g16oyNaMbCqMrJvxFBaBuP7Vo=
github.com/livekit/protocol v1.29.5-0.20241209183753-f6b5078b2244/go.mod h1:NDg1btMpKCzr/w6QR5kDuXw/e4Y7yOBE+RUAHsc+Y/M=
github.com/livekit/psrpc v0.6.1-0.20241018124827-1efff3d113a8 h1:Ibh0LoFl5NW5a1KFJEE0eLxxz7dqqKmYTj/BfCb0PbY=
github.com/livekit/psrpc v0.6.1-0.20241018124827-1efff3d113a8/go.mod h1:CQUBSPfYYAaevg1TNCc6/aYsa8DJH4jSRFdCeSZk5u0=
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
Expand Down
66 changes: 66 additions & 0 deletions sipclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,50 @@ func (s *SIPClient) CreateSIPOutboundTrunk(ctx context.Context, in *livekit.Crea
return s.sipClient.CreateSIPOutboundTrunk(ctx, in)
}

// GetSIPInboundTrunksByIDs gets SIP Inbound Trunks by ID.
// Returned slice is in the same order as the IDs. Missing IDs will have nil in the corresponding position.
func (s *SIPClient) GetSIPInboundTrunksByIDs(ctx context.Context, ids []string) ([]*livekit.SIPInboundTrunkInfo, error) {
if len(ids) == 0 {
return nil, ErrInvalidParameter
}

ctx, err := s.withAuth(ctx, withSIPGrant{Admin: true})
if err != nil {
return nil, err
}
req := &livekit.ListSIPInboundTrunkRequest{
TrunkIds: ids,
}
resp, err := s.ListSIPInboundTrunk(ctx, req)
if err != nil {
return nil, err
}
// Client-side filtering, in case SDK is newer than the server.
return req.FilterSlice(resp.Items), nil
}

// GetSIPOutboundTrunksByIDs gets SIP Outbound Trunks by ID.
// Returned slice is in the same order as the IDs. Missing IDs will have nil in the corresponding position.
func (s *SIPClient) GetSIPOutboundTrunksByIDs(ctx context.Context, ids []string) ([]*livekit.SIPOutboundTrunkInfo, error) {
if len(ids) == 0 {
return nil, ErrInvalidParameter
}

ctx, err := s.withAuth(ctx, withSIPGrant{Admin: true})
if err != nil {
return nil, err
}
req := &livekit.ListSIPOutboundTrunkRequest{
TrunkIds: ids,
}
resp, err := s.ListSIPOutboundTrunk(ctx, req)
if err != nil {
return nil, err
}
// Client-side filtering, in case SDK is newer than the server.
return req.FilterSlice(resp.Items), nil
}

// ListSIPTrunk lists SIP Trunks.
//
// Deprecated: Use ListSIPInboundTrunk or ListSIPOutboundTrunk
Expand Down Expand Up @@ -135,6 +179,28 @@ func (s *SIPClient) CreateSIPDispatchRule(ctx context.Context, in *livekit.Creat
return s.sipClient.CreateSIPDispatchRule(ctx, in)
}

// GetSIPDispatchRulesByIDs gets SIP Dispatch Rules by ID.
// Returned slice is in the same order as the IDs. Missing IDs will have nil in the corresponding position.
func (s *SIPClient) GetSIPDispatchRulesByIDs(ctx context.Context, ids []string) ([]*livekit.SIPDispatchRuleInfo, error) {
if len(ids) == 0 {
return nil, ErrInvalidParameter
}

ctx, err := s.withAuth(ctx, withSIPGrant{Admin: true})
if err != nil {
return nil, err
}
req := &livekit.ListSIPDispatchRuleRequest{
DispatchRuleIds: ids,
}
resp, err := s.ListSIPDispatchRule(ctx, req)
if err != nil {
return nil, err
}
// Client-side filtering, in case SDK is newer than the server.
return req.FilterSlice(resp.Items), nil
}

// ListSIPDispatchRule lists SIP Dispatch Rules.
func (s *SIPClient) ListSIPDispatchRule(ctx context.Context, in *livekit.ListSIPDispatchRuleRequest) (*livekit.ListSIPDispatchRuleResponse, error) {
if in == nil {
Expand Down

0 comments on commit 7610e16

Please sign in to comment.