Skip to content

Commit

Permalink
Support FMLE-compatible sequences.
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo4405 committed Mar 22, 2024
1 parent 27998ab commit 3052fce
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
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 })

/// 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

0 comments on commit 3052fce

Please sign in to comment.