Skip to content

Setting for call statistics logs #549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/src/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class Settings {
/// ICE Gathering Timeout (in millisecond).
int ice_gathering_timeout = 500;

/// Call statistics in the log
bool log_call_statistics = false;

bool terminateOnAudioMediaPortZero = false;

/// Sip Message Delay (in millisecond) ( default 0 ).
Expand Down Expand Up @@ -255,6 +258,9 @@ class Checks {
},
'ice_gathering_timeout': (Settings src, Settings? dst) {
dst!.ice_gathering_timeout = src.ice_gathering_timeout;
},
'log_call_statistics': (Settings src, Settings? dst) {
dst!.log_call_statistics = src.log_call_statistics;
}
};
}
Expand Down
66 changes: 65 additions & 1 deletion lib/src/rtc_session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ class RTCSession extends EventManager implements Owner {
/**
* Terminate the call.
*/
void terminate([Map<String, dynamic>? options]) {
void terminate([Map<String, dynamic>? options]) async {
logger.d('terminate()');

options = options ?? <String, dynamic>{};
Expand Down Expand Up @@ -844,6 +844,9 @@ class RTCSession extends EventManager implements Owner {
}
});

//write call statistics to the log
await _logCallStat();

_ended(
Originator.local,
null,
Expand All @@ -863,6 +866,10 @@ class RTCSession extends EventManager implements Owner {
<String, dynamic>{'extraHeaders': extraHeaders, 'body': body});
reason_phrase = reason_phrase ?? 'Terminated by local';
status_code = status_code ?? 200;

//write call statistics to the log
await _logCallStat();

_ended(
Originator.local,
null,
Expand Down Expand Up @@ -1359,6 +1366,10 @@ class RTCSession extends EventManager implements Owner {
case SipMethod.BYE:
if (_state == RtcSessionState.confirmed) {
request.reply(200);

//write call statistics to the log
await _logCallStat();

_ended(
Originator.remote,
request,
Expand All @@ -1369,6 +1380,10 @@ class RTCSession extends EventManager implements Owner {
} else if (_state == RtcSessionState.inviteReceived) {
request.reply(200);
_request.reply(487, 'BYE Received');

//write call statistics to the log
await _logCallStat();

_ended(
Originator.remote,
request,
Expand Down Expand Up @@ -3441,4 +3456,53 @@ class RTCSession extends EventManager implements Owner {
logger.d('emit "unmuted"');
emit(EventCallUnmuted(session: this, audio: audio, video: video));
}

Future<void> _logCallStat() async {
if (!ua.configuration.log_call_statistics) return;

try {
List<RTCRtpSender>? senders = await connection?.senders;
List<RTCRtpReceiver>? receivers = await connection?.receivers;

RTCRtpReceiver? receiver = receivers?.firstOrNull;
RTCRtpSender? sender = senders?.firstOrNull;

List<StatsReport> senderStats = <StatsReport>[];
List<StatsReport> receiverStats = <StatsReport>[];

if (sender != null) {
senderStats = await sender.getStats();
}

if (receiver != null) {
receiverStats = await receiver.getStats();
}

String senderStat = 'Sender stats: \n';

for (StatsReport s in senderStats) {
senderStat += ' ${s.timestamp} ${s.id} ${s.type}:\n';
s.values.forEach((key, value) {
senderStat += ' $key: $value\n';
});
senderStat += '\r';
}

logger.d(senderStat);

String receiverStat = 'Receiver stats: \n';

for (StatsReport s in receiverStats) {
receiverStat += ' ${s.timestamp} ${s.id} ${s.type}\n';
s.values.forEach((key, value) {
receiverStat += ' $key: $value\n';
});
receiverStat += '\r';
}

logger.d(receiverStat);
} catch (e) {
return;
}
}
}
4 changes: 4 additions & 0 deletions lib/src/sip_ua_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ class SIPUAHelper extends EventManager {
uaSettings.connectionRecoveryMinInterval;
_settings.terminateOnAudioMediaPortZero =
uaSettings.terminateOnMediaPortZero;
_settings.log_call_statistics = uaSettings.logCallStatistics;

try {
_ua = UA(_settings);
Expand Down Expand Up @@ -899,6 +900,9 @@ class UaSettings {
/// Min interval between recovery connection, default 2 sec
int connectionRecoveryMinInterval = 2;

/// Allows to write advanced call statistics in the log after the call ends
bool logCallStatistics = false;

bool terminateOnMediaPortZero = false;

/// Sip Message Delay (in millisecond) (default 0).
Expand Down