@@ -211,11 +211,20 @@ defmodule ExICE.ICEAgent do
211
211
212
212
* `bytes_sent` - data bytes sent. This does not include connectivity checks and UDP/IP header sizes.
213
213
* `bytes_received` - data bytes received. This does not include connectivity checks and UDP/IP header sizes.
214
- * `candidate_pairs` - list of current candidate pairs. It will change after doing an ICE restart.
214
+ * `packets_sent` - data packets sent. This does not include connectivity checks.
215
+ * `packets_received` - data packets received. This does not include connectivity checks.
216
+ * `candidate_pairs` - list of current candidate pairs. Changes after doing an ICE restart.
215
217
"""
216
218
@ spec get_stats ( pid ( ) ) :: % {
217
219
bytes_sent: non_neg_integer ( ) ,
218
- bytes_received: non_neg_integer ,
220
+ bytes_received: non_neg_integer ( ) ,
221
+ packets_sent: non_neg_integer ( ) ,
222
+ packets_received: non_neg_integer ( ) ,
223
+ state: atom ( ) ,
224
+ role: atom ( ) ,
225
+ local_ufrag: binary ( ) ,
226
+ local_candidates: [ Candidate . t ( ) ] ,
227
+ remote_candidates: [ Candidate . t ( ) ] ,
219
228
candidate_pairs: [ CandidatePair . t ( ) ]
220
229
}
221
230
def get_stats ( ice_agent ) do
@@ -299,7 +308,9 @@ defmodule ExICE.ICEAgent do
299
308
turn_servers: [ ] ,
300
309
# stats
301
310
bytes_sent: 0 ,
302
- bytes_received: 0
311
+ bytes_received: 0 ,
312
+ packets_sent: 0 ,
313
+ packets_received: 0
303
314
}
304
315
305
316
{ :ok , state }
@@ -335,6 +346,13 @@ defmodule ExICE.ICEAgent do
335
346
stats = % {
336
347
bytes_sent: state . bytes_sent ,
337
348
bytes_received: state . bytes_received ,
349
+ packets_sent: state . packets_sent ,
350
+ packets_received: state . packets_received ,
351
+ state: state . state ,
352
+ role: state . role ,
353
+ local_ufrag: state . local_ufrag ,
354
+ local_candidates: state . local_cands ,
355
+ remote_candidates: state . remote_cands ,
338
356
candidate_pairs: Map . values ( state . checklist )
339
357
}
340
358
@@ -470,7 +488,15 @@ defmodule ExICE.ICEAgent do
470
488
471
489
dst = { pair . remote_cand . address , pair . remote_cand . port }
472
490
bytes_sent = do_send ( pair . local_cand . socket , dst , data )
473
- { :noreply , % { state | bytes_sent: state . bytes_sent + bytes_sent } }
491
+ # if we didn't manage to send any bytes, don't increment packets_sent
492
+ packets_sent = if bytes_sent == 0 , do: 0 , else: 1
493
+
494
+ { :noreply ,
495
+ % {
496
+ state
497
+ | bytes_sent: state . bytes_sent + bytes_sent ,
498
+ packets_sent: state . packets_sent + packets_sent
499
+ } }
474
500
end
475
501
476
502
@ impl true
@@ -617,7 +643,13 @@ defmodule ExICE.ICEAgent do
617
643
end
618
644
else
619
645
notify ( state . on_data , { :data , packet } )
620
- { :noreply , % { state | bytes_received: state . bytes_received + byte_size ( packet ) } }
646
+
647
+ { :noreply ,
648
+ % {
649
+ state
650
+ | bytes_received: state . bytes_received + byte_size ( packet ) ,
651
+ packets_received: state . packets_received + 1
652
+ } }
621
653
end
622
654
end
623
655
0 commit comments