@@ -77,6 +77,8 @@ defmodule LiveExWebRTC.Player do
77
77
78
78
defstruct id: nil ,
79
79
publisher_id: nil ,
80
+ publisher_audio_track: nil ,
81
+ publisher_video_track: nil ,
80
82
pubsub: nil ,
81
83
pc: nil ,
82
84
audio_track_id: nil ,
@@ -92,6 +94,7 @@ defmodule LiveExWebRTC.Player do
92
94
munger: nil ,
93
95
layer: nil ,
94
96
target_layer: nil ,
97
+ video_layers: [ { "h" , "high" } ] ,
95
98
# codec that will be used for video sending
96
99
video_send_codec: nil
97
100
@@ -207,9 +210,7 @@ defmodule LiveExWebRTC.Player do
207
210
< div class = "" >
208
211
< video id = { @ player . id } phx-hook = "Player " class = { @ class } controls autoplay muted > </ video >
209
212
< select id = "lexp-video-quality " >
210
- < option value = "h " selected > High</ option >
211
- < option value = "m " > Medium</ option >
212
- < option value = "l " > Low</ option >
213
+ < option :for = { { id , layer } <- @ publisher . video_layers } value = { id } > { layer } </ option >
213
214
</ select >
214
215
</ div >
215
216
"""
@@ -227,6 +228,7 @@ defmodule LiveExWebRTC.Player do
227
228
receive do
228
229
{ ^ ref , % Player { publisher_id: ^ pub_id } = player } ->
229
230
player = % Player { player | layer: "h" , target_layer: "h" }
231
+ PubSub . subscribe ( player . pubsub , "streams:info:#{ player . publisher_id } " )
230
232
assign ( socket , player: player )
231
233
after
232
234
5000 -> exit ( :timeout )
@@ -271,6 +273,41 @@ defmodule LiveExWebRTC.Player do
271
273
{ :noreply , socket }
272
274
end
273
275
276
+ @ impl true
277
+ def handle_info ( { :live_ex_webrtc , :info , publisher_audio_track , publisher_video_track } , socket ) do
278
+ % { player: player } = socket . assigns
279
+
280
+ player =
281
+ case player do
282
+ % Player { publisher_audio_track: nil , publisher_video_track: nil } ->
283
+ video_layers = ( publisher_video_track && publisher_video_track . rids ) || [ "h" ]
284
+
285
+ video_layers =
286
+ Enum . map ( video_layers , fn
287
+ "h" -> { "h" , "high" }
288
+ "m" -> { "m" , "medium" }
289
+ "l" -> { "l" , "low" }
290
+ end )
291
+
292
+ % Player {
293
+ player
294
+ | publisher_audio_track: publisher_audio_track ,
295
+ publisher_video_track: publisher_video_track ,
296
+ video_layers: video_layers
297
+ }
298
+
299
+ % Player {
300
+ publisher_audio_track: ^ publisher_audio_track ,
301
+ publisher_video_track: ^ publisher_video_track
302
+ } ->
303
+ player
304
+ end
305
+
306
+ socket = assign ( socket , :player , player )
307
+
308
+ { :noreply , socket }
309
+ end
310
+
274
311
def handle_info ( { :live_ex_webrtc , :audio , packet } , socket ) do
275
312
% { player: player } = socket . assigns
276
313
0 commit comments