@@ -309,49 +309,56 @@ defmodule LiveExWebRTC.Publisher do
309
309
id = "lex-video-settings "
310
310
class = "hidden transition-all duration-700 text-[#606060] flex flex-col gap-6 px-4 pb-3 "
311
311
>
312
- < div id = "lex-resolution " class = "flex gap-2.5 items-center " >
313
- < label for = "lex-width " > Width</ label >
314
- < input
315
- type = "text "
316
- id = "lex-width "
317
- value = "1280 "
318
- class = "rounded-lg disabled:text-gray-400 disabled:border-gray-400 focus:border-brand focus:outline-none focus:ring-0 "
319
- />
320
- < label for = "lex-height " > Height</ label >
321
- < input
322
- type = "text "
323
- id = "lex-height "
324
- value = "720 "
325
- class = "rounded-lg disabled:text-gray-400 disabled:border-gray-400 focus:border-brand focus:outline-none focus:ring-0 "
326
- />
327
- </ div >
328
- < div class = "flex gap-2.5 items-center " >
329
- < label for = "lex-fps " > FPS</ label >
330
- < input
331
- type = "text "
332
- id = "lex-fps "
333
- value = "24 "
334
- class = "rounded-lg disabled:text-gray-400 disabled:border-gray-400 focus:border-brand focus:outline-none focus:ring-0 "
335
- />
336
- </ div >
337
- < button
338
- id = "lex-video-apply-button "
339
- class = "rounded-lg px-10 py-2.5 bg-brand disabled:bg-brand/50 hover:bg-brand/90 text-white font-bold "
340
- disabled
341
- >
342
- Apply
343
- </ button >
344
- < div class = "flex gap-2.5 items-center " >
345
- < label for = "lex-bitrate " > Max Bitrate (kbps)</ label >
346
- < input
347
- type = "text "
348
- id = "lex-bitrate "
349
- value = "1500 "
350
- class = "rounded-lg disabled:text-gray-400 disabled:border-gray-400 focus:border-brand focus:outline-none focus:ring-0 "
351
- />
312
+ < div id = "lex-video-static " phx-update = "ignore " class = "flex flex-col gap-6 " >
313
+ < div id = "lex-resolution " class = "flex gap-2.5 items-center " >
314
+ < label for = "lex-width " > Width</ label >
315
+ < input
316
+ type = "text "
317
+ id = "lex-width "
318
+ value = "1280 "
319
+ class = "rounded-lg disabled:text-gray-400 disabled:border-gray-400 focus:border-brand focus:outline-none focus:ring-0 "
320
+ />
321
+ < label for = "lex-height " > Height</ label >
322
+ < input
323
+ type = "text "
324
+ id = "lex-height "
325
+ value = "720 "
326
+ class = "rounded-lg disabled:text-gray-400 disabled:border-gray-400 focus:border-brand focus:outline-none focus:ring-0 "
327
+ />
328
+ </ div >
329
+ < div class = "flex gap-2.5 items-center " >
330
+ < label for = "lex-fps " > FPS</ label >
331
+ < input
332
+ type = "text "
333
+ id = "lex-fps "
334
+ value = "24 "
335
+ class = "rounded-lg disabled:text-gray-400 disabled:border-gray-400 focus:border-brand focus:outline-none focus:ring-0 "
336
+ />
337
+ </ div >
338
+ < button
339
+ id = "lex-video-apply-button "
340
+ class = "rounded-lg px-10 py-2.5 bg-brand disabled:bg-brand/50 hover:bg-brand/90 text-white font-bold "
341
+ disabled
342
+ >
343
+ Apply
344
+ </ button >
345
+ < div class = "flex gap-2.5 items-center " >
346
+ < label for = "lex-bitrate " > Max Bitrate (kbps)</ label >
347
+ < input
348
+ type = "text "
349
+ id = "lex-bitrate "
350
+ value = "1500 "
351
+ class = "rounded-lg disabled:text-gray-400 disabled:border-gray-400 focus:border-brand focus:outline-none focus:ring-0 "
352
+ />
353
+ </ div >
352
354
</ div >
353
355
< . form for = { @ publisher . form } phx-change = "change_simulcast " phx-update = "replace " >
354
- < . input type = "checkbox " field = { @ publisher . form [ :simulcast ] } label = "Simulcast " />
356
+ < . input
357
+ type = "checkbox "
358
+ field = { @ publisher . form [ :simulcast ] }
359
+ label = "Simulcast "
360
+ { if @ publisher . streaming? , do: % { "disabled" => true } , else: % { "disabled" => false } }
361
+ />
355
362
</ . form >
356
363
</ div >
357
364
</ div >
@@ -583,18 +590,34 @@ defmodule LiveExWebRTC.Publisher do
583
590
end
584
591
585
592
@ impl true
586
- def handle_event ( "change_simulcast" , params , socket ) do
587
- publisher = % Publisher {
588
- socket . assigns . publisher
589
- | form:
590
- to_form ( params ,
593
+ def handle_event ( "change_simulcast" , % { "simulcast" => "true" } = params , socket ) do
594
+ codecs =
595
+ socket . assigns . publisher . video_codecs || PeerConnection.Configuration . default_video_codecs ( )
596
+
597
+ publisher =
598
+ if simulcast_supported? ( codecs ) == true do
599
+ % Publisher { socket . assigns . publisher | form: to_form ( params , id: "lex-form" ) }
600
+ else
601
+ # FIXME this doesn't work when simulcast is not supported and user re-check the checkbox
602
+ form =
603
+ to_form ( socket . assigns . publisher . form ,
591
604
id: "lex-form" ,
592
605
errors: [
593
606
simulcast: { "Server must be configured with H264 codec to support simulcast" , [ ] }
594
607
]
595
608
)
596
- }
597
609
610
+ % Publisher { socket . assigns . publisher | form: form }
611
+ end
612
+
613
+ socket = assign ( socket , publisher: publisher )
614
+ { :noreply , socket }
615
+ end
616
+
617
+ @ impl true
618
+ def handle_event ( "change_simulcast" , % { "simulcast" => "false" } = params , socket ) do
619
+ form = to_form ( params , id: "lex-form" )
620
+ publisher = % Publisher { socket . assigns . publisher | form: form }
598
621
socket = assign ( socket , publisher: publisher )
599
622
{ :noreply , socket }
600
623
end
@@ -624,4 +647,20 @@ defmodule LiveExWebRTC.Publisher do
624
647
1000 -> :ok
625
648
end
626
649
end
650
+
651
+ defp simulcast_supported? ( codecs ) do
652
+ Enum . any? ( codecs , fn codec ->
653
+ fmtp = codec . sdp_fmtp_line
654
+
655
+ fmtp_correct =
656
+ if fmtp == nil do
657
+ false
658
+ else
659
+ fmtp . level_asymmetry_allowed == true and fmtp . packetization_mode == 0 and
660
+ fmtp . profile_level_id == 0x42E01F
661
+ end
662
+
663
+ codec . mime_type == "video/H264" and fmtp_correct == true
664
+ end )
665
+ end
627
666
end
0 commit comments