Skip to content

Commit

Permalink
make stat properties optional
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroshihorie committed Aug 21, 2023
1 parent e3f4327 commit 2f18def
Show file tree
Hide file tree
Showing 3 changed files with 416 additions and 404 deletions.
12 changes: 8 additions & 4 deletions Sources/LiveKit/Track/Track.swift
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,11 @@ public extension OutboundRtpStreamStatistics {
}

var bps: UInt64 {
guard let previous = previous else { return 0 }
guard let previous = previous,
let currentBytesSent = bytesSent,
let previousBytesSent = previous.bytesSent else { return 0 }
let secondsDiff = (timestamp - previous.timestamp) / (1000 * 1000)
return UInt64(Double(((bytesSent - previous.bytesSent) * 8)) / abs(secondsDiff))
return UInt64(Double(((currentBytesSent - previousBytesSent) * 8)) / abs(secondsDiff))
}
}

Expand All @@ -473,9 +475,11 @@ public extension InboundRtpStreamStatistics {
}

var bps: UInt64 {
guard let previous = previous else { return 0 }
guard let previous = previous,
let currentBytesReceived = bytesReceived,
let previousBytesReceived = previous.bytesReceived else { return 0 }
let secondsDiff = (timestamp - previous.timestamp) / (1000 * 1000)
return UInt64(Double(((bytesReceived - previous.bytesReceived) * 8)) / abs(secondsDiff))
return UInt64(Double(((currentBytesReceived - previousBytesReceived) * 8)) / abs(secondsDiff))
}
}

Expand Down
Loading

0 comments on commit 2f18def

Please sign in to comment.