Files
MatchLiveTv/native/ios/MatchLiveTv/Data/Repository/SessionRepository.swift
T
Emiliano FrascaroandCursor 585332e32e Aggiunge app iOS nativa con parità multi-sport e test unitari.
Porting SwiftUI da Android (auth, hub, wizard, broadcast RTMP, overlay, scoring board-aware), reload hub al ritorno da diretta, decodifica score tollerante e documentazione allineata.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-14 21:37:32 +02:00

96 lines
2.7 KiB
Swift

import Foundation
@MainActor
final class SessionRepository {
private let api: MatchLiveAPI
init(api: MatchLiveAPI) {
self.api = api
}
func createSession(
matchId: String,
platform: String = "matchlivetv",
privacyStatus: String = "public",
qualityPreset: String = "720p_30_2.5mbps",
targetBitrate: Int = 2_500_000,
targetFps: Int = 30,
youtubeChannel: String? = nil
) async throws -> StreamSession {
try await api.createSession(
matchId: matchId,
body: CreateSessionRequest(
platform: platform,
privacyStatus: privacyStatus,
qualityPreset: qualityPreset,
targetBitrate: targetBitrate,
targetFps: targetFps,
youtubeChannel: youtubeChannel
)
).toDomain()
}
func fetchSession(id: String) async throws -> StreamSession {
try await api.session(id: id).toDomain()
}
func startSession(id: String) async throws -> StreamSession {
try await api.startSession(id: id).toDomain()
}
func stopSession(id: String) async throws -> StreamSession {
try await api.stopSession(id: id).toDomain()
}
func pauseSession(id: String) async throws -> StreamSession {
try await api.pauseSession(id: id).toDomain()
}
func resumeSession(id: String) async throws -> StreamSession {
try await api.resumeSession(id: id).toDomain()
}
func submitNetworkTest(
sessionId: String,
downloadMbps: Double,
uploadMbps: Double,
latencyMs: Int,
networkType: String
) async throws -> NetworkTestResponse {
try await api.networkTest(
sessionId: sessionId,
body: NetworkTestRequest(
downloadMbps: downloadMbps,
uploadMbps: uploadMbps,
latencyMs: latencyMs,
networkType: networkType
)
)
}
func createRegiaLink(sessionId: String) async throws -> String {
try await api.regiaLink(sessionId: sessionId).regiaUrl
}
func postTelemetry(
sessionId: String,
health: DeviceHealth,
currentBitrate: Int?,
targetBitrate: Int?,
fps: Int?
) async throws {
try await api.postTelemetry(
sessionId: sessionId,
body: TelemetryRequest(
deviceRole: "camera",
batteryLevel: health.batteryPercent,
networkType: health.networkType,
signalStrength: nil,
currentBitrate: currentBitrate,
targetBitrate: targetBitrate,
fps: fps
)
)
}
}