11defmodule ExWebRTC.PeerConnection do
22 @ moduledoc """
3- PeerConnection
3+ Implementation of the [RTCPeerConnection](https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection).
44 """
55
66 use GenServer
@@ -14,7 +14,7 @@ defmodule ExWebRTC.PeerConnection do
1414 alias ExWebRTC . {
1515 DefaultICETransport ,
1616 DTLSTransport ,
17- IceCandidate ,
17+ ICECandidate ,
1818 MediaStreamTrack ,
1919 RTPTransceiver ,
2020 RTPSender ,
@@ -36,7 +36,7 @@ defmodule ExWebRTC.PeerConnection do
3636 @ type signal ( ) ::
3737 { :ex_webrtc , pid ( ) ,
3838 :negotiation_needed
39- | { :ice_candidate , IceCandidate . t ( ) }
39+ | { :ice_candidate , ICECandidate . t ( ) }
4040 | { :signaling_state_change , signaling_state ( ) }
4141 | { :connection_state_change , connection_state ( ) }
4242 | { :track , MediaStreamTrack . t ( ) }
@@ -72,19 +72,19 @@ defmodule ExWebRTC.PeerConnection do
7272 end
7373
7474 @ spec create_offer ( peer_connection ( ) , offer_options ( ) ) ::
75- { :ok , SessionDescription . t ( ) } | { :error , :TODO }
75+ { :ok , SessionDescription . t ( ) } | { :error , :invalid_state }
7676 def create_offer ( peer_connection , options \\ [ ] ) do
7777 GenServer . call ( peer_connection , { :create_offer , options } )
7878 end
7979
8080 @ spec create_answer ( peer_connection ( ) , answer_options ( ) ) ::
81- { :ok , SessionDescription . t ( ) } | { :error , :TODO }
81+ { :ok , SessionDescription . t ( ) } | { :error , :invalid_state }
8282 def create_answer ( peer_connection , options \\ [ ] ) do
8383 GenServer . call ( peer_connection , { :create_answer , options } )
8484 end
8585
8686 @ spec set_local_description ( peer_connection ( ) , SessionDescription . t ( ) ) ::
87- :ok | { :error , :TODO }
87+ :ok | { :error , atom ( ) }
8888 def set_local_description ( peer_connection , description ) do
8989 GenServer . call ( peer_connection , { :set_local_description , description } )
9090 end
@@ -95,7 +95,7 @@ defmodule ExWebRTC.PeerConnection do
9595 end
9696
9797 @ spec set_remote_description ( peer_connection ( ) , SessionDescription . t ( ) ) ::
98- :ok | { :error , :TODO }
98+ :ok | { :error , atom ( ) }
9999 def set_remote_description ( peer_connection , description ) do
100100 GenServer . call ( peer_connection , { :set_remote_description , description } )
101101 end
@@ -105,8 +105,8 @@ defmodule ExWebRTC.PeerConnection do
105105 GenServer . call ( peer_connection , :get_current_remote_description )
106106 end
107107
108- @ spec add_ice_candidate ( peer_connection ( ) , IceCandidate . t ( ) ) ::
109- :ok | { :error , :TODO }
108+ @ spec add_ice_candidate ( peer_connection ( ) , ICECandidate . t ( ) ) ::
109+ :ok | { :error , :no_remote_description }
110110 def add_ice_candidate ( peer_connection , candidate ) do
111111 GenServer . call ( peer_connection , { :add_ice_candidate , candidate } )
112112 end
@@ -157,16 +157,16 @@ defmodule ExWebRTC.PeerConnection do
157157 GenServer . call ( peer_connection , { :remove_track , sender_id } )
158158 end
159159
160- @ spec close ( peer_connection ( ) ) :: :ok
161- def close ( peer_connection ) do
162- GenServer . stop ( peer_connection )
163- end
164-
165160 @ spec send_rtp ( peer_connection ( ) , String . t ( ) , ExRTP.Packet . t ( ) ) :: :ok
166161 def send_rtp ( peer_connection , track_id , packet ) do
167162 GenServer . cast ( peer_connection , { :send_rtp , track_id , packet } )
168163 end
169164
165+ @ spec close ( peer_connection ( ) ) :: :ok
166+ def close ( peer_connection ) do
167+ GenServer . stop ( peer_connection )
168+ end
169+
170170 #### CALLBACKS ####
171171
172172 @ impl true
@@ -617,7 +617,7 @@ defmodule ExWebRTC.PeerConnection do
617617
618618 @ impl true
619619 def handle_info ( { :ex_ice , _from , { :new_candidate , candidate } } , state ) do
620- candidate = % IceCandidate {
620+ candidate = % ICECandidate {
621621 candidate: "candidate:" <> candidate ,
622622 sdp_mid: 0 ,
623623 sdp_m_line_index: 0
@@ -795,7 +795,7 @@ defmodule ExWebRTC.PeerConnection do
795795
796796 defp apply_local_description ( % SessionDescription { type: type } , _state )
797797 when type in [ :rollback , :pranswer ] ,
798- do: { :error , :not_implemented }
798+ do: { :error , :" #{ type } _not_implemented" }
799799
800800 defp apply_local_description ( % SessionDescription { type: type , sdp: raw_sdp } , state ) do
801801 with { :ok , next_sig_state } <- next_signaling_state ( state . signaling_state , :local , type ) ,
@@ -829,7 +829,7 @@ defmodule ExWebRTC.PeerConnection do
829829
830830 defp apply_remote_description ( % SessionDescription { type: type } , _state )
831831 when type in [ :rollback , :pranswer ] ,
832- do: { :error , :not_implemented }
832+ do: { :error , :" #{ type } _not_implemented" }
833833
834834 defp apply_remote_description ( % SessionDescription { type: type , sdp: raw_sdp } , state ) do
835835 with { :ok , next_sig_state } <- next_signaling_state ( state . signaling_state , :remote , type ) ,
0 commit comments