diff --git a/Sources/RTMP/RTMPConnection.swift b/Sources/RTMP/RTMPConnection.swift index 41df21bcc..1f90e5262 100644 --- a/Sources/RTMP/RTMPConnection.swift +++ b/Sources/RTMP/RTMPConnection.swift @@ -3,8 +3,6 @@ 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 @@ -336,8 +334,8 @@ 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) + call("releaseStream", responder: nil, arguments: fcPublishName) + call("FCPublish", responder: nil, arguments: fcPublishName) } let responder = RTMPResponder(result: { data -> Void in guard let id = data[0] as? Double else { diff --git a/Sources/RTMP/RTMPMessage.swift b/Sources/RTMP/RTMPMessage.swift index 99876d06e..3d564ec52 100644 --- a/Sources/RTMP/RTMPMessage.swift +++ b/Sources/RTMP/RTMPMessage.swift @@ -336,6 +336,9 @@ final class RTMPCommandMessage: RTMPMessage { switch commandName { case "close": connection.close(isDisconnected: true) + case "onFCPublish", "onFCUnpublish": + // The specification is undefined, ignores it because it cannot handle it properly. + logger.info(commandName, arguments) default: connection.dispatch(.rtmpStatus, bubbles: false, data: arguments.first as Any?) } diff --git a/Sources/RTMP/RTMPStream.swift b/Sources/RTMP/RTMPStream.swift index 1808f6d27..b8ff8e678 100644 --- a/Sources/RTMP/RTMPStream.swift +++ b/Sources/RTMP/RTMPStream.swift @@ -426,16 +426,6 @@ open class RTMPStream: IOStream { return metadata } - override public func readyStateWillChange(to readyState: IOStream.ReadyState) { - switch self.readyState { - case .publishing: - FCUnpublish() - default: - break - } - super.readyStateWillChange(to: readyState) - } - override public func readyStateDidChange(to readyState: IOStream.ReadyState) { guard let connection else { return @@ -494,6 +484,9 @@ open class RTMPStream: IOStream { return } readyState = .open + if let fcPublishName { + connection.call("FCUnpublish", responder: nil, arguments: fcPublishName) + } connection.socket?.doOutput(chunk: RTMPChunk( type: .zero, streamId: RTMPChunk.StreamID.command.rawValue, @@ -569,15 +562,6 @@ open class RTMPStream: IOStream { } } -extension RTMPStream { - func FCUnpublish() { - guard let connection, let name = info.resourceName, connection.flashVer.contains("FMLE/") else { - return - } - connection.call("FCUnpublish", responder: nil, arguments: name) - } -} - extension RTMPStream: EventDispatcherConvertible { // MARK: IEventDispatcher public func addEventListener(_ type: Event.Name, selector: Selector, observer: AnyObject? = nil, useCapture: Bool = false) {