Skip to content

Commit a269de7

Browse files
committed
add some more stats
1 parent dec5faa commit a269de7

3 files changed

Lines changed: 265 additions & 35 deletions

File tree

APIClient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ class APIClient {
296296
"jwks": true,
297297
"streamkeys": true,
298298
"clients": [
299-
"fields": ["host", "stream", "protocol", "conntime", "downbps", "upbps"]
299+
"fields": ["host", "stream", "protocol", "conntime", "downbps", "upbps", "down", "pktlost", "pktretransmit", "sessId"]
300300
],
301301
]
302302
makeAPICallWithRetry(apiCall, completion: completion)

AppState.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class AppState {
114114
let timestamp: Date
115115
let viewers: Int
116116
let bpsOut: Int
117+
let bpsIn: Int
117118
}
118119

119120
var totalsHistory: [TotalsSnapshot] = []
@@ -138,7 +139,8 @@ class AppState {
138139
let snapshot = StreamSnapshot(
139140
timestamp: Date(),
140141
viewers: streamViewerCount(name),
141-
bpsOut: streamBandwidth(name)
142+
bpsOut: streamBandwidth(name),
143+
bpsIn: streamBandwidthIn(name)
142144
)
143145
var history = streamHistory[name] ?? []
144146
history.append(snapshot)
@@ -201,6 +203,19 @@ class AppState {
201203
return counts
202204
}
203205

206+
var clientProtocolBandwidth: [String: Int] {
207+
var bandwidth: [String: Int] = [:]
208+
for (_, value) in connectedClients {
209+
guard let info = value as? [String: Any],
210+
let proto = info["protocol"] as? String
211+
else { continue }
212+
let down = info["downbps"] as? Int ?? 0
213+
let up = info["upbps"] as? Int ?? 0
214+
bandwidth[proto, default: 0] += down + up
215+
}
216+
return bandwidth
217+
}
218+
204219
// MARK: - Reset
205220

206221
func resetData() {

0 commit comments

Comments
 (0)