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>
This commit is contained in:
Emiliano Frascaro
2026-06-15 07:30:06 +02:00
parent 5de3a1a1cf
commit 80813b390b
6 changed files with 101 additions and 2 deletions

View File

@@ -13,6 +13,20 @@ final class ApiInstantTests: XCTestCase {
XCTAssertEqual(target?.connectURL, "rtmp://stream.example.com/live")
XCTAssertEqual(target?.streamName, "match_abc-123")
}
func testRtmpIngestUrlRewritesDockerHostForLocalApi() {
let resolved = RtmpIngestUrlLogic.resolve(
"rtmp://mediamtx:1935/live/match_abc",
apiBaseUrl: "http://localhost:3000"
)
XCTAssertEqual(resolved, "rtmp://127.0.0.1:1935/live/match_abc")
}
func testRtmpIngestUrlKeepsProductionHost() {
let url = "rtmp://www.matchlivetv.it:1935/live/match_abc"
let resolved = RtmpIngestUrlLogic.resolve(url, apiBaseUrl: "https://www.matchlivetv.it")
XCTAssertEqual(resolved, url)
}
}
enum OverlayKindMapping {
@@ -45,3 +59,29 @@ enum RTMPUrlParserLogic {
return Target(connectURL: connect, streamName: streamName)
}
}
/// Copia della logica `RtmpIngestUrl` per test senza bundle Info.plist.
enum RtmpIngestUrlLogic {
private static let dockerInternalHosts: Set<String> = ["mediamtx", "host.docker.internal"]
static func resolve(_ urlString: String, apiBaseUrl: String) -> String {
guard var components = URLComponents(string: urlString),
let host = components.host?.lowercased() else {
return urlString
}
let apiHost = URL(string: apiBaseUrl)?.host?.lowercased()
let isLocalApi = apiHost.map { $0 == "localhost" || $0 == "127.0.0.1" || $0.hasSuffix(".local") } ?? false
guard dockerInternalHosts.contains(host) || isLocalApi else {
return urlString
}
let ingestHost: String
if let apiHost, apiHost != "localhost", apiHost != "127.0.0.1" {
ingestHost = apiHost
} else {
ingestHost = "127.0.0.1"
}
components.host = ingestHost
if components.port == nil { components.port = 1935 }
return components.url?.absoluteString ?? urlString
}
}