Class: LiveKit::EgressServiceClient

Inherits:
Twirp::Client
  • Object
show all
Includes:
AuthMixin
Defined in:
lib/livekit/egress_service_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AuthMixin

#auth_header

Constructor Details

#initialize(base_url, api_key: nil, api_secret: nil) ⇒ EgressServiceClient

Returns a new instance of EgressServiceClient.



13
14
15
16
17
# File 'lib/livekit/egress_service_client.rb', line 13

def initialize(base_url, api_key: nil, api_secret: nil)
  super(File.join(Utils.to_http_url(base_url), "/twirp"))
  @api_key = api_key
  @api_secret = api_secret
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



11
12
13
# File 'lib/livekit/egress_service_client.rb', line 11

def api_key
  @api_key
end

#api_secretObject

Returns the value of attribute api_secret.



11
12
13
# File 'lib/livekit/egress_service_client.rb', line 11

def api_secret
  @api_secret
end

Instance Method Details

#list_egress(room_name: nil, egress_id: nil, active: false) ⇒ Object

list all egress or only egress for a room



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/livekit/egress_service_client.rb', line 206

def list_egress(
  room_name: nil,
  egress_id: nil,
  active: false
)
  self.rpc(
    :ListEgress,
    Proto::ListEgressRequest.new(
      room_name: room_name,
      active: active,
      egress_id: egress_id,
    ),
    headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)),
  )
end

#start_participant_egress(room_name, identity, output, screen_share: false, preset: nil, advanced: nil, webhooks: nil) ⇒ Object



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
# File 'lib/livekit/egress_service_client.rb', line 59

def start_participant_egress(
  room_name,
  identity,
  # EncodedFileOutput, SegmentedFileOutput, StreamOutput, ImageOutput, or array containing up to one of each
  output,
  # true to record the participant's screenshare and screenshare_audio track
  screen_share: false,
  # EncodingOptionsPreset, only one of preset or advanced could be set
  preset: nil,
  # EncodingOptions, only one of preset or advanced could be set
  advanced: nil,
  # list of extra webhooks to call for this request
  webhooks: nil
)
  request = Proto::ParticipantEgressRequest.new(
    room_name: room_name,
    identity: identity,
    screen_share: screen_share,
    preset: preset,
    advanced: advanced,
    webhooks: webhooks,
  )
  self.set_output(request, output)
  self.rpc(
    :StartParticipantEgress,
    request,
    headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)),
  )
end

#start_room_composite_egress(room_name, output, preset: nil, advanced: nil, custom_base_url: nil, layout: nil, audio_only: false, video_only: false, audio_mixing: nil, webhooks: nil) ⇒ Object



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
# File 'lib/livekit/egress_service_client.rb', line 19

def start_room_composite_egress(
  room_name,
  # EncodedFileOutput, SegmentedFileOutput, StreamOutput, ImageOutput or array containing up to one of each
  output,
  # EncodingOptionsPreset, only one of preset or advanced could be set
  preset: nil,
  # EncodingOptions, only one of preset or advanced could be set
  advanced: nil,
  # egress template url, otherwise uses default templates
  custom_base_url: nil,
  # egress layout
  layout: nil,
  # true to record only audio
  audio_only: false,
  # true to record only video
  video_only: false,
  # DEFAULT_MIXING, DUAL_CHANNEL_AGENT, DUAL_CHANNEL_ALTERNATE
  audio_mixing: nil,
  # list of extra webhooks to call for this request
  webhooks: nil
)
  request = Proto::RoomCompositeEgressRequest.new(
    room_name: room_name,
    preset: preset,
    advanced: advanced,
    layout: layout,
    custom_base_url: custom_base_url,
    audio_only: audio_only,
    video_only: video_only,
    audio_mixing: audio_mixing,
    webhooks: webhooks,
  )
  self.set_output(request, output)
  self.rpc(
    :StartRoomCompositeEgress,
    request,
    headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)),
  )
end

#start_track_composite_egress(room_name, output, audio_track_id: nil, video_track_id: nil, preset: nil, advanced: nil, webhooks: nil) ⇒ Object



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
# File 'lib/livekit/egress_service_client.rb', line 89

def start_track_composite_egress(
  room_name,
  # EncodedFileOutput, SegmentedFileOutput, StreamOutput, ImageOutput, or array containing up to one of each
  output,
  # TrackID of an audio track
  audio_track_id: nil,
  # TrackID of a video track
  video_track_id: nil,
  # EncodingOptionsPreset, only one of preset or advanced could be set
  preset: nil,
  # EncodingOptions, only one of preset or advanced could be set
  advanced: nil,
  # list of extra webhooks to call for this request
  webhooks: nil
)
  request = Proto::TrackCompositeEgressRequest.new(
    room_name: room_name,
    preset: preset,
    advanced: advanced,
    audio_track_id: audio_track_id,
    video_track_id: video_track_id,
    webhooks: webhooks,
  )
  self.set_output(request, output)
  self.rpc(
    :StartTrackCompositeEgress,
    request,
    headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)),
  )
end

#start_track_egress(room_name, output, track_id, webhooks: nil) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/livekit/egress_service_client.rb', line 120

def start_track_egress(
  room_name,
  # either a DirectFileOutput - egress to storage or string - egress to WebSocket URL
  output,
  track_id,
  # list of extra webhooks to call for this request
  webhooks: nil
)
  request = Proto::TrackEgressRequest.new(
    room_name: room_name,
    track_id: track_id,
    webhooks: webhooks,
  )
  if output.filepath
    request.file = output
  else
    request.websocket_url = output
  end
  self.rpc(
    :StartTrackEgress,
    request,
    headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)),
  )
end

#start_web_egress(url, output, preset: nil, advanced: nil, audio_only: false, video_only: false, await_start_signal: false, webhooks: nil) ⇒ Object



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
# File 'lib/livekit/egress_service_client.rb', line 145

def start_web_egress(
  url,
  # EncodedFileOutput, SegmentedFileOutput, StreamOutput, ImageOutput, or array containing up to one of each
  output,
  # EncodingOptionsPreset, only one of preset or advanced could be set
  preset: nil,
  # EncodingOptions, only one of preset or advanced could be set
  advanced: nil,
  # true to record only audio
  audio_only: false,
  # true to record only video
  video_only: false,
  # true to await START_RECORDING chrome log
  await_start_signal: false,
  # list of extra webhooks to call for this request
  webhooks: nil
)
  request = Proto::WebEgressRequest.new(
    url: url,
    preset: preset,
    advanced: advanced,
    audio_only: audio_only,
    video_only: video_only,
    await_start_signal: await_start_signal,
    webhooks: webhooks,
  )
  self.set_output(request, output)
  self.rpc(
    :StartWebEgress,
    request,
    headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)),
  )
end

#stop_egress(egress_id) ⇒ Object



222
223
224
225
226
227
228
# File 'lib/livekit/egress_service_client.rb', line 222

def stop_egress(egress_id)
  self.rpc(
    :StopEgress,
    Proto::StopEgressRequest.new(egress_id: egress_id),
    headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)),
  )
end

#update_layout(egress_id, layout) ⇒ Object



179
180
181
182
183
184
185
186
187
188
# File 'lib/livekit/egress_service_client.rb', line 179

def update_layout(egress_id, layout)
  self.rpc(
    :UpdateLayout,
    Proto::UpdateLayoutRequest.new(
      egress_id: egress_id,
      layout: layout,
    ),
    headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)),
  )
end

#update_stream(egress_id, add_output_urls: [], remove_output_urls: []) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/livekit/egress_service_client.rb', line 190

def update_stream(egress_id,
  add_output_urls: [],
  remove_output_urls: []
)
  self.rpc(
    :UpdateStream,
    Proto::UpdateStreamRequest.new(
      egress_id: egress_id,
      add_output_urls: add_output_urls,
      remove_output_urls: remove_output_urls,
    ),
    headers:auth_header(video_grant: VideoGrant.new(roomRecord: true)),
  )
end