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

Improving compatibility with FMLE's FCPublish behavior. #1414

Merged
merged 1 commit into from
Apr 9, 2024
Merged
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
6 changes: 2 additions & 4 deletions Sources/RTMP/RTMPConnection.swift
Original file line number Diff line number Diff line change
@@ -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 {
3 changes: 3 additions & 0 deletions Sources/RTMP/RTMPMessage.swift
Original file line number Diff line number Diff line change
@@ -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?)
}
22 changes: 3 additions & 19 deletions Sources/RTMP/RTMPStream.swift
Original file line number Diff line number Diff line change
@@ -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) {