Skip to content

Commit aae6179

Browse files
author
Volodymyr B
committed
writing call stats to log
1 parent 38dbab7 commit aae6179

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

lib/src/config.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class Settings {
6464
/// ICE Gathering Timeout (in millisecond).
6565
int ice_gathering_timeout = 500;
6666

67+
/// Call statistics in the log
68+
bool log_call_statistics = false;
69+
6770
bool terminateOnAudioMediaPortZero = false;
6871

6972
/// Sip Message Delay (in millisecond) ( default 0 ).
@@ -255,6 +258,9 @@ class Checks {
255258
},
256259
'ice_gathering_timeout': (Settings src, Settings? dst) {
257260
dst!.ice_gathering_timeout = src.ice_gathering_timeout;
261+
},
262+
'log_call_statistics': (Settings src, Settings? dst) {
263+
dst!.log_call_statistics = src.log_call_statistics;
258264
}
259265
};
260266
}

lib/src/rtc_session.dart

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ class RTCSession extends EventManager implements Owner {
726726
/**
727727
* Terminate the call.
728728
*/
729-
void terminate([Map<String, dynamic>? options]) {
729+
void terminate([Map<String, dynamic>? options]) async {
730730
logger.d('terminate()');
731731

732732
options = options ?? <String, dynamic>{};
@@ -844,6 +844,9 @@ class RTCSession extends EventManager implements Owner {
844844
}
845845
});
846846

847+
//write call statistics to the log
848+
await _logCallStat();
849+
847850
_ended(
848851
Originator.local,
849852
null,
@@ -863,6 +866,10 @@ class RTCSession extends EventManager implements Owner {
863866
<String, dynamic>{'extraHeaders': extraHeaders, 'body': body});
864867
reason_phrase = reason_phrase ?? 'Terminated by local';
865868
status_code = status_code ?? 200;
869+
870+
//write call statistics to the log
871+
await _logCallStat();
872+
866873
_ended(
867874
Originator.local,
868875
null,
@@ -1359,6 +1366,10 @@ class RTCSession extends EventManager implements Owner {
13591366
case SipMethod.BYE:
13601367
if (_state == RtcSessionState.confirmed) {
13611368
request.reply(200);
1369+
1370+
//write call statistics to the log
1371+
await _logCallStat();
1372+
13621373
_ended(
13631374
Originator.remote,
13641375
request,
@@ -1369,6 +1380,10 @@ class RTCSession extends EventManager implements Owner {
13691380
} else if (_state == RtcSessionState.inviteReceived) {
13701381
request.reply(200);
13711382
_request.reply(487, 'BYE Received');
1383+
1384+
//write call statistics to the log
1385+
await _logCallStat();
1386+
13721387
_ended(
13731388
Originator.remote,
13741389
request,
@@ -3441,4 +3456,57 @@ class RTCSession extends EventManager implements Owner {
34413456
logger.d('emit "unmuted"');
34423457
emit(EventCallUnmuted(session: this, audio: audio, video: video));
34433458
}
3459+
3460+
Future<void> _logCallStat() async {
3461+
3462+
if(!ua.configuration.log_call_statistics) return;
3463+
3464+
try {
3465+
List<RTCRtpSender>? senders = await connection?.senders;
3466+
List<RTCRtpReceiver>? receivers = await connection?.receivers;
3467+
3468+
RTCRtpReceiver? receiver = receivers?.firstOrNull;
3469+
RTCRtpSender? sender = senders?.firstOrNull;
3470+
3471+
List<StatsReport> senderStats = <StatsReport>[];
3472+
List<StatsReport> receiverStats = <StatsReport>[];
3473+
3474+
if(sender!=null) {
3475+
senderStats = await sender.getStats();
3476+
}
3477+
3478+
if(receiver != null) {
3479+
receiverStats = await receiver.getStats();
3480+
}
3481+
3482+
String senderStat = 'Sender stats: \n';
3483+
3484+
for(StatsReport s in senderStats) {
3485+
senderStat += '${s.timestamp} ${s.id} ${s.type}\n';
3486+
senderStat += '----------------------------------------------------\n';
3487+
s.values.forEach((key, value) {
3488+
senderStat += '$key: $value\n';
3489+
});
3490+
senderStat += '----------------------------------------------------\n';
3491+
}
3492+
3493+
logger.d(senderStat);
3494+
3495+
String receiverStat = 'Receiver stats: \n';
3496+
3497+
for(StatsReport s in receiverStats) {
3498+
receiverStat += '${s.timestamp} ${s.id} ${s.type}\n';
3499+
receiverStat += '----------------------------------------------------\n';
3500+
s.values.forEach((key, value) {
3501+
receiverStat += '$key: $value\n';
3502+
});
3503+
receiverStat += '----------------------------------------------------\n';
3504+
}
3505+
3506+
logger.d(receiverStat);
3507+
3508+
} catch (e) {
3509+
return;
3510+
}
3511+
}
34443512
}

lib/src/sip_ua_helper.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ class SIPUAHelper extends EventManager {
194194
uaSettings.connectionRecoveryMinInterval;
195195
_settings.terminateOnAudioMediaPortZero =
196196
uaSettings.terminateOnMediaPortZero;
197+
_settings.log_call_statistics = uaSettings.logCallStatistics;
197198

198199
try {
199200
_ua = UA(_settings);
@@ -899,6 +900,9 @@ class UaSettings {
899900
/// Min interval between recovery connection, default 2 sec
900901
int connectionRecoveryMinInterval = 2;
901902

903+
/// Allows to write advanced call statistics in the log after the call ends
904+
bool logCallStatistics = false;
905+
902906
bool terminateOnMediaPortZero = false;
903907

904908
/// Sip Message Delay (in millisecond) (default 0).

0 commit comments

Comments
 (0)