forked from livekit/server-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ingressclient.go
88 lines (75 loc) · 2.39 KB
/
ingressclient.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2023 LiveKit, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package lksdk
import (
"context"
"net/http"
"github.com/livekit/protocol/livekit"
"github.com/twitchtv/twirp"
)
type IngressClient struct {
ingressClient livekit.Ingress
authBase
}
func NewIngressClient(url string, apiKey string, secretKey string, opts ...twirp.ClientOption) *IngressClient {
url = ToHttpURL(url)
client := livekit.NewIngressProtobufClient(url, &http.Client{}, opts...)
return &IngressClient{
ingressClient: client,
authBase: authBase{
apiKey: apiKey,
apiSecret: secretKey,
},
}
}
func (c *IngressClient) CreateIngress(ctx context.Context, in *livekit.CreateIngressRequest) (*livekit.IngressInfo, error) {
if in == nil {
return nil, ErrInvalidParameter
}
ctx, err := c.withAuth(ctx, withVideoGrant{IngressAdmin: true})
if err != nil {
return nil, err
}
return c.ingressClient.CreateIngress(ctx, in)
}
func (c *IngressClient) UpdateIngress(ctx context.Context, in *livekit.UpdateIngressRequest) (*livekit.IngressInfo, error) {
if in == nil {
return nil, ErrInvalidParameter
}
ctx, err := c.withAuth(ctx, withVideoGrant{IngressAdmin: true})
if err != nil {
return nil, err
}
return c.ingressClient.UpdateIngress(ctx, in)
}
func (c *IngressClient) ListIngress(ctx context.Context, in *livekit.ListIngressRequest) (*livekit.ListIngressResponse, error) {
if in == nil {
return nil, ErrInvalidParameter
}
ctx, err := c.withAuth(ctx, withVideoGrant{IngressAdmin: true})
if err != nil {
return nil, err
}
return c.ingressClient.ListIngress(ctx, in)
}
func (c *IngressClient) DeleteIngress(ctx context.Context, in *livekit.DeleteIngressRequest) (*livekit.IngressInfo, error) {
if in == nil {
return nil, ErrInvalidParameter
}
ctx, err := c.withAuth(ctx, withVideoGrant{IngressAdmin: true})
if err != nil {
return nil, err
}
return c.ingressClient.DeleteIngress(ctx, in)
}