postCallReport method

Future<void> postCallReport({
  1. required String callId,
  2. required String direction,
  3. String? destinationNumber,
  4. String? callerNumber,
  5. String? state,
  6. String? telnyxSessionId,
  7. String? telnyxLegId,
})

Posts the collected call report to voice-sdk-proxy. Should be called after stopStats() when the call ends.

Implementation

Future<void> postCallReport({
  required String callId,
  required String direction,
  String? destinationNumber,
  String? callerNumber,
  String? state,
  String? telnyxSessionId,
  String? telnyxLegId,
}) async {
  if (_callReportCollector == null) {
    GlobalLogger().d('Peer :: No call report collector to post');
    return;
  }

  final callReportId = _txClient.callReportId;
  final host = _txClient.socketHost;

  if (callReportId == null) {
    GlobalLogger().d('Peer :: Cannot post call report: callReportId not available');
    return;
  }

  if (host == null) {
    GlobalLogger().e('Peer :: Cannot post call report: socket host not available');
    return;
  }

  // Log call ended event
  _callReportLogCollector?.logCallEnded(
    callId: callId,
    reason: state,
  );

  final summary = CallSummary(
    callId: callId,
    destinationNumber: destinationNumber,
    callerNumber: callerNumber,
    direction: direction,
    state: state,
    telnyxSessionId: telnyxSessionId,
    telnyxLegId: telnyxLegId,
    sdkVersion: VersionUtils.getSDKVersion(),
  );

  // Store upload config for intermediate segment flushing
  _callReportCollector!.storeUploadConfig(
    callReportId: callReportId,
    host: host,
    voiceSdkId: _txClient.voiceSdkId,
  );

  await _callReportCollector!.postReport(
    summary: summary,
    callReportId: callReportId,
    host: host,
    voiceSdkId: _txClient.voiceSdkId,
  );
}