forked from notedit/janus-go
-
Notifications
You must be signed in to change notification settings - Fork 3
/
videoroom.go
193 lines (168 loc) · 5.33 KB
/
videoroom.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package plugins
import (
"github.com/edoshor/janus-go"
)
type VideoroomResponse struct {
Videoroom string `json:"videoroom"`
}
type VideoroomErrorResponse struct {
VideoroomResponse
PluginError
}
func (err *VideoroomErrorResponse) Error() string {
return err.PluginError.Error()
}
type VideoroomRequestFactory struct {
PluginRequestFactory
}
func MakeVideoroomRequestFactory(adminKey string) *VideoroomRequestFactory {
return &VideoroomRequestFactory{
PluginRequestFactory: *NewPluginRequestFactory("janus.plugin.videoroom", adminKey),
}
}
func (f *VideoroomRequestFactory) ListRequest() *BasePluginRequest {
request := f.make("list")
return &request
}
func (f *VideoroomRequestFactory) CreateRequest(room *VideoroomRoom, permanent bool, allowed []string) *VideoroomCreateRequest {
return &VideoroomCreateRequest{
BasePluginRequest: f.make("create"),
Room: room,
Permanent: permanent,
Allowed: allowed,
}
}
func (f *VideoroomRequestFactory) EditRequest(room *VideoroomRoomForEdit, permanent bool, secret string) *VideoroomEditRequest {
return &VideoroomEditRequest{
BasePluginRequest: f.make("edit"),
Room: room,
Permanent: permanent,
Secret: secret,
}
}
func (f *VideoroomRequestFactory) DestroyRequest(roomID int, permanent bool, secret string) *VideoroomDestroyRequest {
return &VideoroomDestroyRequest{
BasePluginRequest: f.make("destroy"),
RoomID: roomID,
Permanent: permanent,
Secret: secret,
}
}
type VideoroomListResponse struct {
VideoroomResponse
Rooms []*VideoroomRoomFromListResponse `json:"list"`
}
type VideoroomCreateRequest struct {
BasePluginRequest
Room *VideoroomRoom
Permanent bool
Allowed []string
}
func (r *VideoroomCreateRequest) Payload() map[string]interface{} {
payload := r.BasePluginRequest.Payload()
payload["permanent"] = r.Permanent
if len(r.Allowed) > 0 {
payload["allowed"] = r.Allowed
}
mergeMap(payload, r.Room.AsMap())
return payload
}
type VideoroomCreateResponse struct {
VideoroomResponse
RoomID int `json:"room"`
Permanent bool `json:"permanent"`
}
type VideoroomEditRequest struct {
BasePluginRequest
Room *VideoroomRoomForEdit
Secret string
Permanent bool
}
func (r *VideoroomEditRequest) Payload() map[string]interface{} {
payload := r.BasePluginRequest.Payload()
payload["permanent"] = r.Permanent
if r.Secret != "" {
payload["secret"] = r.Secret
}
mergeMap(payload, r.Room.AsMap())
return payload
}
type VideoroomEditResponse struct {
VideoroomResponse
RoomID int `json:"room"`
}
type VideoroomDestroyRequest struct {
BasePluginRequest
RoomID int
Secret string
Permanent bool
}
func (r *VideoroomDestroyRequest) Payload() map[string]interface{} {
payload := r.BasePluginRequest.Payload()
payload["room"] = r.RoomID
payload["permanent"] = r.Permanent
if r.Secret != "" {
payload["secret"] = r.Secret
}
return payload
}
type VideoroomDestroyResponse struct {
VideoroomResponse
RoomID int `json:"room"`
}
type VideoroomRoom struct {
Room int `json:"room"`
Description string `json:"description,omitempty"`
IsPrivate bool `json:"is_private"`
Secret string `json:"secret,omitempty"`
Pin string `json:"pin,omitempty"`
RequirePvtID bool `json:"require_pvtid"`
RequireE2ee bool `json:"require_e2ee"`
Publishers int `json:"publishers"`
Bitrate int `json:"bitrate"`
FirFreq int `json:"fir_freq"`
AudioCodec string `json:"audiocodec,omitempty"`
VideoCodec string `json:"videocodec,omitempty"`
Vp9Profile string `json:"vp9_profile,omitempty"`
H264Profile string `json:"h264_profile,omitempty"`
OpusFec bool `json:"opus_fec"`
VideoSvc bool `json:"video_svc"`
AudioLevelExt bool `json:"audiolevel_ext"`
AudioLevelEvent bool `json:"audiolevel_event"`
AudioActivePackets int `json:"audio_active_packets,omitempty"`
AudioLevelAverage int `json:"audio_level_average,omitempty"`
VideoOrientExt bool `json:"videoorient_ext"`
PlayoutDelayExt bool `json:"playoutdelay_ext"`
TransportWideCCExt bool `json:"transport_wide_cc_ext"`
Record bool `json:"record"`
RecDir string `json:"rec_dir,omitempty"`
LockRecord bool `json:"lock_record"`
NotifyJoining bool `json:"notify_joining"`
}
func (r *VideoroomRoom) AsMap() map[string]interface{} {
m, _ := janus.StructToMap(r)
return m
}
type VideoroomRoomFromListResponse struct {
VideoroomRoom
PinRequired bool `json:"pin_required"`
MaxPublishers int `json:"max_publishers"`
BitrateCap bool `json:"bitrate_cap"`
NumParticipants int `json:"num_participants"`
}
type VideoroomRoomForEdit struct {
Room int `json:"room"`
Description string `json:"new_description,omitempty"`
IsPrivate bool `json:"new_is_private"`
Secret string `json:"new_secret,omitempty"`
Pin string `json:"new_pin,omitempty"`
RequirePvtID bool `json:"new_require_pvtid"`
Publishers int `json:"new_publishers"`
Bitrate int `json:"new_bitrate"`
FirFreq int `json:"new_fir_freq"`
LockRecord bool `json:"new_lock_record"`
}
func (r *VideoroomRoomForEdit) AsMap() map[string]interface{} {
m, _ := janus.StructToMap(r)
return m
}