@@ -32,6 +32,11 @@ defmodule ExICE.ICEAgent do
32
32
33
33
@ conn_check_handler % { controlling: ControllingHandler , controlled: ControlledHandler }
34
34
35
+ @ typedoc """
36
+ ICE agent role.
37
+
38
+ `:controlling` agent is responsible for nominating a pair.
39
+ """
35
40
@ type role ( ) :: :controlling | :controlled
36
41
37
42
@ typedoc """
@@ -72,52 +77,98 @@ defmodule ExICE.ICEAgent do
72
77
stun_servers: [ String . t ( ) ]
73
78
]
74
79
75
- defguard are_pairs_equal ( p1 , p2 )
76
- when p1 . local_cand . base_address == p2 . local_cand . base_address and
77
- p1 . local_cand . base_port == p2 . local_cand . base_port and
78
- p1 . local_cand . address == p2 . local_cand . address and
79
- p1 . local_cand . port == p2 . local_cand . port and
80
- p1 . remote_cand . address == p2 . remote_cand . address and
81
- p1 . remote_cand . port == p2 . remote_cand . port
80
+ defguardp are_pairs_equal ( p1 , p2 )
81
+ when p1 . local_cand . base_address == p2 . local_cand . base_address and
82
+ p1 . local_cand . base_port == p2 . local_cand . base_port and
83
+ p1 . local_cand . address == p2 . local_cand . address and
84
+ p1 . local_cand . port == p2 . local_cand . port and
85
+ p1 . remote_cand . address == p2 . remote_cand . address and
86
+ p1 . remote_cand . port == p2 . remote_cand . port
82
87
83
- defguard is_response ( class ) when class in [ :success_response , :error_response ]
88
+ defguardp is_response ( class ) when class in [ :success_response , :error_response ]
84
89
90
+ @ doc """
91
+ Starts and links a new ICE agent.
92
+
93
+ Process calling this function is called a `controlling process` and
94
+ has to be prepared for receiving ExICE messages described by `t:signal/0`.
95
+ """
85
96
@ spec start_link ( role ( ) , opts ( ) ) :: GenServer . on_start ( )
86
97
def start_link ( role , opts \\ [ ] ) do
87
98
GenServer . start_link ( __MODULE__ , opts ++ [ role: role , controlling_process: self ( ) ] )
88
99
end
89
100
101
+ @ doc """
102
+ Gets local credentials.
103
+
104
+ They remain unchanged until ICE restart.
105
+ """
90
106
@ spec get_local_credentials ( pid ( ) ) :: { :ok , ufrag :: binary ( ) , pwd :: binary ( ) }
91
107
def get_local_credentials ( ice_agent ) do
92
108
GenServer . call ( ice_agent , :get_local_credentials )
93
109
end
94
110
111
+ @ doc """
112
+ Sets remote credentials.
113
+
114
+ Call to this function is mandatory to start connectivity checks.
115
+ """
95
116
@ spec set_remote_credentials ( pid ( ) , binary ( ) , binary ( ) ) :: :ok
96
117
def set_remote_credentials ( ice_agent , ufrag , passwd )
97
118
when is_binary ( ufrag ) and is_binary ( passwd ) do
98
119
GenServer . cast ( ice_agent , { :set_remote_credentials , ufrag , passwd } )
99
120
end
100
121
122
+ @ doc """
123
+ Starts ICE gathering process.
124
+
125
+ Once a new candidate is discovered, it is sent as a message to the controlling process.
126
+ See `t:signal/0` for a message structure.
127
+ """
101
128
@ spec gather_candidates ( pid ( ) ) :: :ok
102
129
def gather_candidates ( ice_agent ) do
103
130
GenServer . cast ( ice_agent , :gather_candidates )
104
131
end
105
132
133
+ @ doc """
134
+ Adds a remote candidate.
135
+
136
+ If an ICE agent has already gathered any local candidates and
137
+ have remote credentials set, adding a remote candidate will start
138
+ connectivity checks.
139
+ """
106
140
@ spec add_remote_candidate ( pid ( ) , String . t ( ) ) :: :ok
107
141
def add_remote_candidate ( ice_agent , candidate ) when is_binary ( candidate ) do
108
142
GenServer . cast ( ice_agent , { :add_remote_candidate , candidate } )
109
143
end
110
144
145
+ @ doc """
146
+ Informs ICE agent that a remote side finished its gathering process.
147
+
148
+ Call to this function is mandatory to nominate a pair (when an agent is the `controlling` one)
149
+ and in turn move to the `completed` state.
150
+ """
111
151
@ spec end_of_candidates ( pid ( ) ) :: :ok
112
152
def end_of_candidates ( ice_agent ) do
113
153
GenServer . cast ( ice_agent , :end_of_candidates )
114
154
end
115
155
156
+ @ doc """
157
+ Sends data.
158
+
159
+ Can only be called after moving to the `connected` state.
160
+ """
116
161
@ spec send_data ( pid ( ) , binary ( ) ) :: :ok
117
162
def send_data ( ice_agent , data ) when is_binary ( data ) do
118
163
GenServer . cast ( ice_agent , { :send_data , data } )
119
164
end
120
165
166
+ @ doc """
167
+ Restarts ICE.
168
+
169
+ If there were any valid pairs in the previous ICE session,
170
+ data can still be sent.
171
+ """
121
172
@ spec restart ( pid ( ) ) :: :ok
122
173
def restart ( ice_agent ) do
123
174
GenServer . cast ( ice_agent , :restart )
@@ -998,7 +1049,7 @@ defmodule ExICE.ICEAgent do
998
1049
Checklist pair: #{ checklist_pair . id } .
999
1050
""" )
1000
1051
1001
- # if we get here, don't update discovered_pair_id and succeeded_pair_id of
1052
+ # if we get here, don't update discovered_pair_id and succeeded_pair_id of
1002
1053
# the checklist pair as they are already set
1003
1054
conn_check_pair = % CandidatePair {
1004
1055
conn_check_pair
0 commit comments