TelnyxCallReportCollector

public class TelnyxCallReportCollector

Collects WebRTC statistics during a call and posts them to voice-sdk-proxy at the end of the call for quality analysis and debugging.

Stats Collection Strategy (based on Twilio/Jitsi best practices):

  • Collects stats at regular intervals (default 5 seconds)
  • Stores cumulative values (packets, bytes) from WebRTC API
  • Calculates averages for variable metrics (audio level, jitter, RTT)
  • Uses in-memory buffer with size limits for long calls
  • Posts aggregated stats to voice-sdk-proxy on call end

Initialization

Public Methods

  • Start collecting stats from the peer connection

    Declaration

    Swift

    public func start(peerConnection: RTCPeerConnection)

    Parameters

    peerConnection

    The RTCPeerConnection to monitor

  • Stop collecting stats and prepare for final report

    Declaration

    Swift

    public func stop()
  • Post the final collected stats to voice-sdk-proxy

    Declaration

    Swift

    public func postReport(summary: CallReportSummary, callReportId: String, host: String, voiceSdkId: String? = nil)

    Parameters

    summary

    Call summary information

    callReportId

    Call report ID from REGED message

    host

    WebSocket host URL (will be converted to HTTP)

    voiceSdkId

    Optional voice SDK ID

  • Add a structured log entry to the call report.

    Declaration

    Swift

    public func addLogEntry(level: String, message: String, context: [String : Any]? = nil)

    Parameters

    level

    Log level (e.g. “info”, “warn”, “error”)

    message

    Human-readable event description

    context

    Optional dictionary with structured event data

  • Get the current stats buffer (for debugging)

    Declaration

    Swift

    public func getStatsBuffer() -> [CallReportInterval]

    Return Value

    Array of collected intervals

  • Get the collected logs (for debugging)

    Declaration

    Swift

    public func getLogs() -> [LogEntry]

    Return Value

    Array of log entries

  • Clean up resources (call after postReport)

    Declaration

    Swift

    public func cleanup()