Files
MatchLiveTv/native/ios/MatchLiveTv/Core/MediaUrl.swift
Emiliano FrascaroandCursor 80813b390b Fix connessione RTMP in dev: riscrivi host Docker mediamtx per iOS.
Il simulatore non risolve «mediamtx»; l'app riscrive l'ingest verso 127.0.0.1 e docker-compose espone MEDIAMTX_RTMP_URL client-safe con messaggi d'errore RTMP più chiari.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-15 07:30:06 +02:00

48 lines
1.8 KiB
Swift

import Foundation
enum MediaUrl {
static func resolve(_ path: String?) -> String? {
guard let path, !path.isEmpty else { return nil }
if path.hasPrefix("http://") || path.hasPrefix("https://") { return path }
let base = AppConfig.apiBaseUrl
if path.hasPrefix("/") { return base + path }
return "\(base)/\(path)"
}
}
/// Normalizza l'URL RTMP restituito dall'API per il dispositivo corrente.
enum RtmpIngestUrl {
/// Host interni Docker non raggiungibili da simulatore / telefono → localhost o LAN.
private static let dockerInternalHosts: Set<String> = ["mediamtx", "host.docker.internal"]
static func resolveForDevice(_ urlString: String) -> String {
guard var components = URLComponents(string: urlString),
let host = components.host?.lowercased() else {
return urlString
}
guard dockerInternalHosts.contains(host) || shouldRewriteForLocalApi else {
return urlString
}
components.host = localIngestHost
if components.port == nil {
components.port = 1935
}
return components.url?.absoluteString ?? urlString
}
private static var shouldRewriteForLocalApi: Bool {
guard let host = URL(string: AppConfig.apiBaseUrl)?.host?.lowercased() else { return false }
return host == "localhost" || host == "127.0.0.1" || host.hasSuffix(".local")
}
/// Host RTMP per dev locale: simulatore iOS → 127.0.0.1; device fisico → stesso host dell'API.
private static var localIngestHost: String {
guard let apiHost = URL(string: AppConfig.apiBaseUrl)?.host else { return "127.0.0.1" }
let lower = apiHost.lowercased()
if lower == "localhost" || lower == "127.0.0.1" {
return "127.0.0.1"
}
return apiHost
}
}