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



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

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(roomRecord: true),
  )
end

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



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

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
)
  request = Proto::ParticipantEgressRequest.new(
    room_name: room_name,
    identity: identity,
    screen_share: screen_share,
    preset: preset,
    advanced: advanced,
  )
  self.set_output(request, output)
  self.rpc(
    :StartParticipantEgress,
    request,
    headers: auth_header(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) ⇒ 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
# 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
)
  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,
  )
  self.set_output(request, output)
  self.rpc(
    :StartRoomCompositeEgress,
    request,
    headers: auth_header(roomRecord: true),
  )
end

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



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

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
)
  request = Proto::TrackCompositeEgressRequest.new(
    room_name: room_name,
    preset: preset,
    advanced: advanced,
    audio_track_id: audio_track_id,
    video_track_id: video_track_id,
  )
  self.set_output(request, output)
  self.rpc(
    :StartTrackCompositeEgress,
    request,
    headers: auth_header(roomRecord: true),
  )
end

#start_track_egress(room_name, output, track_id) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/livekit/egress_service_client.rb', line 108

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

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



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

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
)
  request = Proto::WebEgressRequest.new(
    url: url,
    preset: preset,
    advanced: advanced,
    audio_only: audio_only,
    video_only: video_only,
    await_start_signal: await_start_signal,
  )
  self.set_output(request, output)
  self.rpc(
    :StartWebEgress,
    request,
    headers: auth_header(roomRecord: true),
  )
end

#stop_egress(egress_id) ⇒ Object



204
205
206
207
208
209
210
# File 'lib/livekit/egress_service_client.rb', line 204

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

#update_layout(egress_id, layout) ⇒ Object



161
162
163
164
165
166
167
168
169
170
# File 'lib/livekit/egress_service_client.rb', line 161

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

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



172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/livekit/egress_service_client.rb', line 172

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(roomRecord: true),
  )
end