From 9d0e9a9343948f4fb1a2f7217427e0112aa652cd Mon Sep 17 00:00:00 2001 From: ThibaultBee <37510686+ThibaultBee@users.noreply.github.com> Date: Tue, 12 Dec 2023 11:20:30 +0100 Subject: [PATCH] fix(lib): intercept all connection and publishing errors --- Sources/ApiVideoLiveStream/ApiVideoLiveStream.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Sources/ApiVideoLiveStream/ApiVideoLiveStream.swift b/Sources/ApiVideoLiveStream/ApiVideoLiveStream.swift index 8d44441..d616e23 100644 --- a/Sources/ApiVideoLiveStream/ApiVideoLiveStream.swift +++ b/Sources/ApiVideoLiveStream/ApiVideoLiveStream.swift @@ -403,22 +403,26 @@ public class ApiVideoLiveStream { private func rtmpStatusHandler(_ notification: Notification) { let e = Event.from(notification) guard let data: ASObject = e.data as? ASObject, - let code: String = data["code"] as? String else + let code: String = data["code"] as? String, + let level: String = data["level"] as? String else { + print("rtmpStatusHandler: failed to parse event: \(e)") return } switch code { case RTMPConnection.Code.connectSuccess.rawValue: - self.delegate?.connectionSuccess() self.rtmpStream.publish(self.streamKey) - case RTMPConnection.Code.connectFailed.rawValue: - self.delegate?.connectionFailed(code) + case RTMPStream.Code.publishStart.rawValue: + self.delegate?.connectionSuccess() case RTMPConnection.Code.connectClosed.rawValue: self.delegate?.disconnection() default: + if level == "error" { + self.delegate?.connectionFailed(code) + } break } }