diff --git a/SRTHaishinKit/SRTStream.swift b/SRTHaishinKit/SRTStream.swift index 01bfb5807..286dbbe15 100644 --- a/SRTHaishinKit/SRTStream.swift +++ b/SRTHaishinKit/SRTStream.swift @@ -9,14 +9,12 @@ public final class SRTStream: NetStream { private var action: (() -> Void)? private var keyValueObservations: [NSKeyValueObservation] = [] private weak var connection: SRTConnection? - - private lazy var writer: TSWriter = { + private lazy var writer = { var writer = TSWriter() writer.delegate = self return writer }() - - private lazy var reader: TSReader = { + private lazy var reader = { var reader = TSReader() reader.delegate = self return reader @@ -97,9 +95,11 @@ public final class SRTStream: NetStream { } override public func readyStateDidChange(to readyState: NetStream.ReadyState) { + super.readyStateDidChange(to: readyState) switch readyState { case .play: connection?.socket?.doInput() + self.readyState = .playing case .publish: writer.expectedMedias.removeAll() if videoInputFormat != nil { diff --git a/Sources/Net/NetStream.swift b/Sources/Net/NetStream.swift index 40d8e3c0c..f46dbf83e 100644 --- a/Sources/Net/NetStream.swift +++ b/Sources/Net/NetStream.swift @@ -284,7 +284,7 @@ open class NetStream: NSObject { guard readyState != newValue else { return } - readyStateWillChange(to: readyState) + readyStateWillChange(to: newValue) } didSet { guard readyState != oldValue else { @@ -427,11 +427,11 @@ open class NetStream: NSObject { /// A handler that receives stream readyState will update. /// - Warning: Please do not call this method yourself. open func readyStateWillChange(to readyState: ReadyState) { - switch readyState { - case .publishing: - mixer.stopRunning() + switch self.readyState { case .playing: mixer.stopRunning() + case .publishing: + mixer.stopRunning() default: break } diff --git a/Sources/RTMP/RTMPStream.swift b/Sources/RTMP/RTMPStream.swift index 26e5089c8..04f0dc10f 100644 --- a/Sources/RTMP/RTMPStream.swift +++ b/Sources/RTMP/RTMPStream.swift @@ -417,7 +417,7 @@ open class RTMPStream: NetStream { } override public func readyStateWillChange(to readyState: NetStream.ReadyState) { - switch readyState { + switch self.readyState { case .publishing: FCUnpublish() default: