Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support FMLE-compatible sequences(releaseStream/FCPublish) #1393

Merged
merged 1 commit into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Examples/iOS/NetStreamSwitcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ final class NetStreamSwitcher {
guard let connection = connection as? RTMPConnection else {
return
}
// Performing operations for FMLE compatibility purposes.
(stream as? RTMPStream)?.fcPublishName = Preference.defaultInstance.streamName
connection.addEventListener(.rtmpStatus, selector: #selector(rtmpStatusHandler), observer: self)
connection.addEventListener(.ioError, selector: #selector(rtmpErrorHandler), observer: self)
connection.connect(uri)
Expand Down
7 changes: 7 additions & 0 deletions Sources/RTMP/RTMPConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Copy link
Owner Author

@shogo4405 shogo4405 Mar 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ The 'stat' is the require reason api. Please check privacy manifest files.


/// A Handler represents RTMPResponder's callback function.
public typealias Handler = (_ data: [Any?]) -> Void

Expand Down Expand Up @@ -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
Expand Down
14 changes: 5 additions & 9 deletions Sources/RTMP/RTMPStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down