startStats method

Future<bool> startStats(
  1. String callId,
  2. String peerId,
  3. RTCPeerConnection pc, {
  4. CallQualityCallback? onCallQualityChange,
  5. String? direction,
  6. String? destinationNumber,
  7. String? callerNumber,
})

Implementation

Future<bool> startStats(
  String callId,
  String peerId,
  RTCPeerConnection pc, {
  CallQualityCallback? onCallQualityChange,
  String? direction,
  String? destinationNumber,
  String? callerNumber,
}) async {
  // Create log collector
  _callReportLogCollector = CallReportLogCollector(
    maxEntries: _callReportMaxLogEntries,
    logLevel: _callReportLogLevel,
  );

  // Log call started event
  _callReportLogCollector?.logCallStarted(
    callId: callId,
    direction: direction ?? 'unknown',
    destinationNumber: destinationNumber,
    callerNumber: callerNumber,
  );

  // Always start call report collector (for post-call reporting)
  _callReportCollector = CallReportCollector(
    options: CallReportOptions(
      intervalMs: _callReportInterval,
    ),
    logCollector: _callReportLogCollector,
  );
  _callReportCollector?.start(pc);
  GlobalLogger().d('Peer :: CallReportCollector started for $callId');

  // Only start WebRTC stats reporter if debug mode is enabled
  if (!_debug) {
    GlobalLogger().d(
      'Peer :: Stats manager will NOT start; debug mode not enabled.',
    );
    return true; // Return true because call report collector started
  }
  _statsManager = WebRTCStatsReporter(
    _socket,
    pc,
    callId,
    peerId,
    _txClient.isDebug(),
    onCallQualityChange: onCallQualityChange,
  );
  await _statsManager?.startStatsReporting();
  GlobalLogger().d('Peer :: Stats Manager started for callId=$callId');
  return true;
}