@@ -465,6 +465,26 @@ defmodule ExWebRTC.PeerConnection do
465
465
{ :reply , :ok , state }
466
466
end
467
467
468
+ @ impl true
469
+ def handle_call ( :get_connection_state , _from , state ) do
470
+ { :reply , state . conn_state , state }
471
+ end
472
+
473
+ @ impl true
474
+ def handle_call ( :get_ice_connection_state , _from , state ) do
475
+ { :reply , state . ice_state , state }
476
+ end
477
+
478
+ @ impl true
479
+ def handle_call ( :get_ice_gathering_state , _from , state ) do
480
+ { :reply , state . ice_gathering_state , state }
481
+ end
482
+
483
+ @ impl true
484
+ def handle_call ( :get_signaling_state , _from , state ) do
485
+ { :reply , state . signaling_state , state }
486
+ end
487
+
468
488
@ impl true
469
489
def handle_call ( { :create_offer , _options } , _from , % { signaling_state: ss } = state )
470
490
when ss not in [ :stable , :have_local_offer ] do
@@ -658,7 +678,8 @@ defmodule ExWebRTC.PeerConnection do
658
678
659
679
@ impl true
660
680
def handle_call ( :get_transceivers , _from , state ) do
661
- { :reply , state . transceivers , state }
681
+ transceivers = Enum . map ( state . transceivers , & RTPTransceiver . to_struct / 1 )
682
+ { :reply , transceivers , state }
662
683
end
663
684
664
685
@ impl true
@@ -667,25 +688,25 @@ defmodule ExWebRTC.PeerConnection do
667
688
{ ssrc , rtx_ssrc } = generate_ssrcs ( state )
668
689
options = [ { :ssrc , ssrc } , { :rtx_ssrc , rtx_ssrc } | options ]
669
690
670
- transceiver = RTPTransceiver . new ( kind , nil , state . config , options )
671
- state = % { state | transceivers: state . transceivers ++ [ transceiver ] }
691
+ tr = RTPTransceiver . new ( kind , nil , state . config , options )
692
+ state = % { state | transceivers: state . transceivers ++ [ tr ] }
672
693
673
694
state = update_negotiation_needed ( state )
674
695
675
- { :reply , { :ok , transceiver } , state }
696
+ { :reply , { :ok , RTPTransceiver . to_struct ( tr ) } , state }
676
697
end
677
698
678
699
@ impl true
679
700
def handle_call ( { :add_transceiver , % MediaStreamTrack { } = track , options } , _from , state ) do
680
701
{ ssrc , rtx_ssrc } = generate_ssrcs ( state )
681
702
options = [ { :ssrc , ssrc } , { :rtx_ssrc , rtx_ssrc } | options ]
682
703
683
- transceiver = RTPTransceiver . new ( track . kind , track , state . config , options )
684
- state = % { state | transceivers: state . transceivers ++ [ transceiver ] }
704
+ tr = RTPTransceiver . new ( track . kind , track , state . config , options )
705
+ state = % { state | transceivers: state . transceivers ++ [ tr ] }
685
706
686
707
state = update_negotiation_needed ( state )
687
708
688
- { :reply , { :ok , transceiver } , state }
709
+ { :reply , { :ok , RTPTransceiver . to_struct ( tr ) } , state }
689
710
end
690
711
691
712
@ impl true
@@ -698,7 +719,7 @@ defmodule ExWebRTC.PeerConnection do
698
719
699
720
idx ->
700
721
tr = Enum . at ( state . transceivers , idx )
701
- tr = % RTPTransceiver { tr | direction: direction }
722
+ tr = % { tr | direction: direction }
702
723
transceivers = List . replace_at ( state . transceivers , idx , tr )
703
724
state = % { state | transceivers: transceivers }
704
725
state = update_negotiation_needed ( state )
@@ -735,9 +756,9 @@ defmodule ExWebRTC.PeerConnection do
735
756
# we ignore the condition that sender has never been used to send
736
757
free_transceiver_idx =
737
758
Enum . find_index ( state . transceivers , fn
738
- % RTPTransceiver {
759
+ % {
739
760
kind: ^ kind ,
740
- sender: % RTPSender { track: nil } ,
761
+ sender: % { track: nil } ,
741
762
current_direction: direction
742
763
}
743
764
when direction not in [ :sendrecv , :sendonly ] ->
@@ -972,7 +993,12 @@ defmodule ExWebRTC.PeerConnection do
972
993
end )
973
994
974
995
case transceiver do
975
- % RTPTransceiver { } ->
996
+ nil ->
997
+ Logger . warning (
998
+ "Attempted to send packet to track with unrecognized id: #{ inspect ( track_id ) } "
999
+ )
1000
+
1001
+ _other ->
976
1002
{ packet , state } =
977
1003
case Map . fetch ( state . config . video_rtp_hdr_exts , @ twcc_uri ) do
978
1004
{ :ok , % { id: id } } ->
@@ -1000,11 +1026,6 @@ defmodule ExWebRTC.PeerConnection do
1000
1026
1001
1027
{ :noreply , state }
1002
1028
1003
- nil ->
1004
- Logger . warning (
1005
- "Attempted to send packet to track with unrecognized id: #{ inspect ( track_id ) } "
1006
- )
1007
-
1008
1029
{ :noreply , state }
1009
1030
end
1010
1031
end
@@ -1083,7 +1104,7 @@ defmodule ExWebRTC.PeerConnection do
1083
1104
@ impl true
1084
1105
def handle_info ( { :dtls_transport , _pid , { :rtp , data } } , state ) do
1085
1106
with { :ok , demuxer , mid , packet } <- Demuxer . demux ( state . demuxer , data ) ,
1086
- { idx , % RTPTransceiver { } = t } <- find_transceiver ( state . transceivers , mid ) do
1107
+ { idx , t } <- find_transceiver ( state . transceivers , mid ) do
1087
1108
# we always update the ssrc's for the one's from the latest packet
1088
1109
# although this is not a necessity, the feedbacks are transport-wide
1089
1110
twcc_recorder = % TWCCRecorder {
@@ -1248,13 +1269,13 @@ defmodule ExWebRTC.PeerConnection do
1248
1269
Enum . map_reduce ( state . transceivers , next_mid , fn
1249
1270
# In the initial offer, we can't have stopped transceivers, only stopping ones.
1250
1271
# Also, stopped transceivers are immediately removed.
1251
- % RTPTransceiver { stopping: true , mid: nil } = tr , nm ->
1272
+ % { stopping: true , mid: nil } = tr , nm ->
1252
1273
{ tr , nm }
1253
1274
1254
- % RTPTransceiver { stopping: false , mid: nil } = tr , nm ->
1275
+ % { stopping: false , mid: nil } = tr , nm ->
1255
1276
tr = RTPTransceiver . assign_mid ( tr , to_string ( nm ) )
1256
1277
# in the initial offer, mline_idx is the same as mid
1257
- tr = % RTPTransceiver { tr | mline_idx: nm }
1278
+ tr = % { tr | mline_idx: nm }
1258
1279
{ tr , nm + 1 }
1259
1280
end )
1260
1281
@@ -1326,7 +1347,7 @@ defmodule ExWebRTC.PeerConnection do
1326
1347
defp assign_mlines ( [ ] , _ , _ , _ , _ , result ) , do: Enum . reverse ( result )
1327
1348
1328
1349
defp assign_mlines (
1329
- [ % RTPTransceiver { mid: nil , mline_idx: nil , stopped: false } = tr | trs ] ,
1350
+ [ % { mid: nil , mline_idx: nil , stopped: false } = tr | trs ] ,
1330
1351
last_answer ,
1331
1352
next_mid ,
1332
1353
next_mline_idx ,
@@ -1337,12 +1358,12 @@ defmodule ExWebRTC.PeerConnection do
1337
1358
1338
1359
case SDPUtils . find_free_mline_idx ( last_answer , recycled_mlines ) do
1339
1360
nil ->
1340
- tr = % RTPTransceiver { tr | mline_idx: next_mline_idx }
1361
+ tr = % { tr | mline_idx: next_mline_idx }
1341
1362
result = [ tr | result ]
1342
1363
assign_mlines ( trs , last_answer , next_mid + 1 , next_mline_idx + 1 , recycled_mlines , result )
1343
1364
1344
1365
idx ->
1345
- tr = % RTPTransceiver { tr | mline_idx: idx }
1366
+ tr = % { tr | mline_idx: idx }
1346
1367
result = [ tr | result ]
1347
1368
recycled_mlines = [ idx | recycled_mlines ]
1348
1369
assign_mlines ( trs , last_answer , next_mid + 1 , next_mline_idx , recycled_mlines , result )
@@ -1448,7 +1469,7 @@ defmodule ExWebRTC.PeerConnection do
1448
1469
# This might result in unremovable transceiver when
1449
1470
# we add and stop it before the first offer.
1450
1471
# See https://github.com/w3c/webrtc-pc/issues/2923
1451
- % RTPTransceiver { mid: nil } ->
1472
+ % { mid: nil } ->
1452
1473
false
1453
1474
1454
1475
tr ->
@@ -1566,7 +1587,7 @@ defmodule ExWebRTC.PeerConnection do
1566
1587
notify ( owner , { :track_muted , tr . receiver . track . id } )
1567
1588
end
1568
1589
1569
- tr = % RTPTransceiver { tr | current_direction: direction , fired_direction: direction }
1590
+ tr = % { tr | current_direction: direction , fired_direction: direction }
1570
1591
1571
1592
# This is not defined in the W3C but see https://github.com/w3c/webrtc-pc/issues/2927
1572
1593
tr =
@@ -1596,12 +1617,12 @@ defmodule ExWebRTC.PeerConnection do
1596
1617
# after processing remote track but this shouldn't have any impact
1597
1618
{ idx , tr } =
1598
1619
case find_transceiver_from_remote ( transceivers , mline ) do
1599
- { idx , % RTPTransceiver { } = tr } -> { idx , RTPTransceiver . update ( tr , mline , config ) }
1620
+ { idx , tr } -> { idx , RTPTransceiver . update ( tr , mline , config ) }
1600
1621
nil -> { nil , RTPTransceiver . from_mline ( mline , idx , config ) }
1601
1622
end
1602
1623
1603
1624
tr = process_remote_track ( tr , direction , owner )
1604
- tr = if sdp_type == :answer , do: % RTPTransceiver { tr | current_direction: direction } , else: tr
1625
+ tr = if sdp_type == :answer , do: % { tr | current_direction: direction } , else: tr
1605
1626
1606
1627
tr =
1607
1628
if SDPUtils . rejected? ( mline ) ,
@@ -1623,7 +1644,7 @@ defmodule ExWebRTC.PeerConnection do
1623
1644
{ :mid , mid } = ExSDP . get_attribute ( mline , :mid )
1624
1645
1625
1646
case find_transceiver ( transceivers , mid ) do
1626
- { idx , % RTPTransceiver { } = tr } -> { idx , tr }
1647
+ { idx , tr } -> { idx , tr }
1627
1648
nil -> find_associable_transceiver ( transceivers , mline )
1628
1649
end
1629
1650
end
@@ -1649,7 +1670,7 @@ defmodule ExWebRTC.PeerConnection do
1649
1670
:ok
1650
1671
end
1651
1672
1652
- % RTPTransceiver { transceiver | fired_direction: direction }
1673
+ % { transceiver | fired_direction: direction }
1653
1674
end
1654
1675
1655
1676
defp reverse_direction ( :recvonly ) , do: :sendonly
@@ -1819,7 +1840,7 @@ defmodule ExWebRTC.PeerConnection do
1819
1840
1820
1841
# in case NACK was received, but RTX was not negotiated
1821
1842
# as NACK and RTX are negotited independently
1822
- { % RTPTransceiver { sender: % RTPSender { rtx_pt: nil } } , _idx } ->
1843
+ { % { sender: % { rtx_pt: nil } } , _idx } ->
1823
1844
state
1824
1845
1825
1846
{ tr , idx } ->
0 commit comments