Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ipavlidakis committed Dec 3, 2024
1 parent 414fb3d commit 053f35c
Showing 1 changed file with 39 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,10 @@ extension WebRTCCoordinator.StateMachine.Stage {

try Task.checkCancellation()

await reportTelemetry()
reportTelemetry(
sessionId: await coordinator.stateAdapter.sessionID,
sfuAdapter: sfuAdapter
)
}

/// Reports telemetry data to the SFU (Selective Forwarding Unit) to monitor and analyze the
Expand All @@ -355,51 +358,46 @@ extension WebRTCCoordinator.StateMachine.Stage {
/// The telemetry data provides insights into the connection's performance and the strategies used
/// during rejoining, fast reconnecting, or migration.
///
/// - Important: The method relies on the `sessionID` and `sfuAdapter` being
/// available in the context. If either is missing, no telemetry is sent.
///
/// The reported data includes:
/// - Connection time in seconds for a regular flow.
/// - Reconnection strategies (e.g., fast reconnect, rejoin, or migration) and their duration.
private func reportTelemetry() async {
guard
let sessionId = await context.coordinator?.stateAdapter.sessionID,
let sfuAdapter = await context.coordinator?.stateAdapter.sfuAdapter
else {
return
}
private func reportTelemetry(
sessionId: String,
sfuAdapter: SFUAdapter
) {
Task {
var telemetry = Stream_Video_Sfu_Signal_Telemetry()
let duration = Float(Date().timeIntervalSince(startTime))
var reconnection = Stream_Video_Sfu_Signal_Reconnection()
reconnection.timeSeconds = duration

telemetry.data = {
switch flowType {
case .regular:
return .connectionTimeSeconds(duration)
case .fast:
var reconnection = Stream_Video_Sfu_Signal_Reconnection()
reconnection.strategy = .fast
return .reconnection(reconnection)
case .rejoin:
reconnection.strategy = .rejoin
return .reconnection(reconnection)
case .migrate:
reconnection.strategy = .migrate
return .reconnection(reconnection)
}
}()

var telemetry = Stream_Video_Sfu_Signal_Telemetry()
let duration = Float(Date().timeIntervalSince(startTime))
var reconnection = Stream_Video_Sfu_Signal_Reconnection()
reconnection.timeSeconds = duration

telemetry.data = {
switch flowType {
case .regular:
return .connectionTimeSeconds(duration)
case .fast:
var reconnection = Stream_Video_Sfu_Signal_Reconnection()
reconnection.strategy = .fast
return .reconnection(reconnection)
case .rejoin:
reconnection.strategy = .rejoin
return .reconnection(reconnection)
case .migrate:
reconnection.strategy = .migrate
return .reconnection(reconnection)
do {
try await sfuAdapter.sendStats(
nil,
for: sessionId,
telemetry: telemetry
)
log.debug("Join call completed in \(duration) seconds.")
} catch {
log.error(error)
}
}()

do {
try await sfuAdapter.sendStats(
nil,
for: sessionId,
telemetry: telemetry
)
log.debug("Join call completed in \(duration) seconds.")
} catch {
log.error(error)
}
}
}
Expand Down

0 comments on commit 053f35c

Please sign in to comment.