diff --git a/Sources/RTMP/RTMPConnection.swift b/Sources/RTMP/RTMPConnection.swift index 2bd10f14b..c7f37e8d0 100644 --- a/Sources/RTMP/RTMPConnection.swift +++ b/Sources/RTMP/RTMPConnection.swift @@ -3,6 +3,8 @@ import Foundation /// The RTMPResponder class provides to use handle RTMPConnection's callback. open class RTMPResponder { + static let empty = RTMPResponder(result: { _ in }) + /// A Handler represents RTMPResponder's callback function. public typealias Handler = (_ data: [Any?]) -> Void @@ -338,6 +340,11 @@ public class RTMPConnection: EventDispatcher { } func createStream(_ stream: RTMPStream) { + if let fcPublishName = stream.fcPublishName { + // FMLE-compatible sequences + call("releaseStream", responder: RTMPResponder.empty, arguments: fcPublishName) + call("FCPublish", responder: RTMPResponder.empty, arguments: fcPublishName) + } let responder = RTMPResponder(result: { data -> Void in guard let id = data[0] as? Double else { return diff --git a/Sources/RTMP/RTMPStream.swift b/Sources/RTMP/RTMPStream.swift index c5361e17a..eb14c8736 100644 --- a/Sources/RTMP/RTMPStream.swift +++ b/Sources/RTMP/RTMPStream.swift @@ -230,6 +230,9 @@ open class RTMPStream: IOStream { } } } + /// Specifies the stream name used for FMLE-compatible sequences. + public var fcPublishName: String? + var id: UInt32 = RTMPStream.defaultID var audioTimestamp: Double = 0.0 var videoTimestamp: Double = 0.0 @@ -248,9 +251,10 @@ open class RTMPStream: IOStream { private weak var connection: RTMPConnection? /// Creates a new stream. - public init(connection: RTMPConnection) { + public init(connection: RTMPConnection, fcPublishName: String? = nil) { self.connection = connection super.init() + self.fcPublishName = fcPublishName dispatcher = EventDispatcher(target: self) connection.streams.append(self) addEventListener(.rtmpStatus, selector: #selector(on(status:)), observer: self) @@ -470,7 +474,6 @@ open class RTMPStream: IOStream { videoWasSent = false audioWasSent = false dataTimestamps.removeAll() - FCPublish() case .publishing: let metadata = makeMetaData() send(handlerName: "@setDataFrame", arguments: "onMetaData", metadata) @@ -568,13 +571,6 @@ open class RTMPStream: IOStream { } extension RTMPStream { - func FCPublish() { - guard let connection, let name = info.resourceName, connection.flashVer.contains("FMLE/") else { - return - } - connection.call("FCPublish", responder: nil, arguments: name) - } - func FCUnpublish() { guard let connection, let name = info.resourceName, connection.flashVer.contains("FMLE/") else { return