stop method
void
stop()
Gracefully close.
Implementation
void stop() {
logger.debug('stop()');
// Remove dynamic settings.
_dynConfiguration = null;
if (_status == C.STATUS_USER_CLOSED) {
logger.debug('UA already closed');
return;
}
// Close registrator.
_registrator.close();
// If there are session wait a bit so CANCEL/BYE can be sent and their responses received.
int num_sessions = _sessions.length;
// Run _terminate_ on every Session.
_sessions.forEach((String? key, _) {
if (_sessions.containsKey(key)) {
logger.debug('closing session $key');
try {
RTCSession rtcSession = _sessions[key]!;
if (!rtcSession.isEnded()) {
rtcSession.terminate();
}
} catch (error, s) {
Log.e(error.toString(), null, s);
}
}
});
// Run _close_ on every applicant.
for (Message message in _applicants) {
try {
message.close();
} catch (error) {}
}
_status = C.STATUS_USER_CLOSED;
int num_transactions = _transactions.countTransactions();
if (num_transactions == 0 && num_sessions == 0) {
_transport!.disconnect();
} else {
_closeTimer = setTimeout(() {
logger.info('Closing connection');
_closeTimer = null;
_transport!.disconnect();
}, 2000);
}
}