Skip to content

Commit

Permalink
Add IOStream readyState delegate observer
Browse files Browse the repository at this point in the history
  • Loading branch information
levs42 committed Feb 12, 2024
1 parent 31cd4f8 commit 88fbe4b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Examples/iOS/NetStreamSwitcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,12 @@ extension NetStreamSwitcher: IOStreamDelegate {
/// Tells the receiver to the stream opened.
func streamDidOpen(_ stream: IOStream) {
}

/// Tells the receiver that the ready state will change.
func stream(_ stream: IOStream, willChange readyState: IOStream.ReadyState) {
}

/// Tells the receiver that the ready state did change.
func stream(_ stream: IOStream, didChange readyState: IOStream.ReadyState) {
}
}
6 changes: 6 additions & 0 deletions Sources/IO/IOStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public protocol IOStreamDelegate: AnyObject {
func stream(_ stream: IOStream, audioErrorOccurred error: IOAudioUnitError)
/// Tells the receiver to the stream opened.
func streamDidOpen(_ stream: IOStream)
/// Tells the receiver that the ready state will change.
func stream(_ stream: IOStream, willChange readyState: IOStream.ReadyState)
/// Tells the receiver that the ready state did change.
func stream(_ stream: IOStream, didChange readyState: IOStream.ReadyState)
}

@available(*, deprecated, renamed: "IOStream")
Expand Down Expand Up @@ -458,6 +462,7 @@ open class IOStream: NSObject {
/// A handler that receives stream readyState will update.
/// - Warning: Please do not call this method yourself.
open func readyStateWillChange(to readyState: ReadyState) {
delegate?.stream(self, willChange: readyState)
switch self.readyState {
case .playing:
mixer.stopRunning()
Expand Down Expand Up @@ -487,6 +492,7 @@ open class IOStream: NSObject {
default:
break
}
delegate?.stream(self, didChange: readyState)
}

#if os(iOS) || os(tvOS)
Expand Down

0 comments on commit 88fbe4b

Please sign in to comment.