From d59b55b8570bec09f8e049e007b66ab55d26903a Mon Sep 17 00:00:00 2001 From: levs42 Date: Wed, 20 Mar 2024 11:04:46 -0700 Subject: [PATCH 1/2] Add optional releaseStream call --- Sources/RTMP/RTMPConnection.swift | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Sources/RTMP/RTMPConnection.swift b/Sources/RTMP/RTMPConnection.swift index 2bd10f14b..a8868f8f8 100644 --- a/Sources/RTMP/RTMPConnection.swift +++ b/Sources/RTMP/RTMPConnection.swift @@ -179,6 +179,8 @@ public class RTMPConnection: EventDispatcher { public var chunkSize: Int = RTMPConnection.defaultChunkSizeS /// Specifies the URI passed to the Self.connect() method. public private(set) var uri: URL? + /// Specifies a name to pass to `releaseStream` command. + public private(set) var resourceName: String? /// Specifies the instance connected to server(true) or not(false). public private(set) var connected = false /// Specifies the instance requires Network.framework if possible. @@ -282,11 +284,12 @@ public class RTMPConnection: EventDispatcher { } /// Creates a two-way connection to an application on RTMP Server. - public func connect(_ command: String, arguments: Any?...) { + public func connect(_ command: String, name: String? = nil, arguments: Any?...) { guard let uri = URL(string: command), let scheme = uri.scheme, !connected && Self.supportedProtocols.contains(scheme) else { return } self.uri = uri + self.resourceName = name self.arguments = arguments switch scheme { case "rtmpt", "rtmpts": @@ -338,6 +341,9 @@ public class RTMPConnection: EventDispatcher { } func createStream(_ stream: RTMPStream) { + if let resourceName { + call("releaseStream", responder: nil, arguments: resourceName) + } let responder = RTMPResponder(result: { data -> Void in guard let id = data[0] as? Double else { return @@ -386,7 +392,7 @@ public class RTMPConnection: EventDispatcher { break case description.contains("reason=needauth"): let command = Self.makeSanJoseAuthCommand(uri, description: description) - connect(command, arguments: arguments) + connect(command, name: resourceName, arguments: arguments) case description.contains("authmod=adobe"): if user.isEmpty || password.isEmpty { close(isDisconnected: true) @@ -394,7 +400,7 @@ public class RTMPConnection: EventDispatcher { } let query = uri.query ?? "" let command = uri.absoluteString + (query.isEmpty ? "?" : "&") + "authmod=adobe&user=\(user)" - connect(command, arguments: arguments) + connect(command, name: resourceName, arguments: arguments) default: break } From 633a05f4777b4ac571e5f3a52d2b05acdad12d5d Mon Sep 17 00:00:00 2001 From: levs42 Date: Wed, 20 Mar 2024 14:50:08 -0700 Subject: [PATCH 2/2] Move FCPublish call before createStream --- Sources/RTMP/RTMPConnection.swift | 1 + Sources/RTMP/RTMPStream.swift | 8 -------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/Sources/RTMP/RTMPConnection.swift b/Sources/RTMP/RTMPConnection.swift index a8868f8f8..71a978955 100644 --- a/Sources/RTMP/RTMPConnection.swift +++ b/Sources/RTMP/RTMPConnection.swift @@ -343,6 +343,7 @@ public class RTMPConnection: EventDispatcher { func createStream(_ stream: RTMPStream) { if let resourceName { call("releaseStream", responder: nil, arguments: resourceName) + call("FCPublish", responder: nil, arguments: resourceName) } let responder = RTMPResponder(result: { data -> Void in guard let id = data[0] as? Double else { diff --git a/Sources/RTMP/RTMPStream.swift b/Sources/RTMP/RTMPStream.swift index c5361e17a..1367fc88b 100644 --- a/Sources/RTMP/RTMPStream.swift +++ b/Sources/RTMP/RTMPStream.swift @@ -470,7 +470,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 +567,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