Skip to content

Commit

Permalink
Improving compatibility with FMLE's FCPublish behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo4405 committed Apr 8, 2024
1 parent 4aff4aa commit 1687f03
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 23 deletions.
6 changes: 2 additions & 4 deletions Sources/RTMP/RTMPConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions Sources/RTMP/RTMPMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
}
Expand Down
22 changes: 3 additions & 19 deletions Sources/RTMP/RTMPStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1687f03

Please sign in to comment.