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 13, 2024
1 parent 31cd4f8 commit 1d72595
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, willChangeReadyState state: IOStream.ReadyState) {
}

/// Tells the receiver that the ready state did change.
func stream(_ stream: IOStream, didChangeReadyState state: 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, willChangeReadyState state: IOStream.ReadyState)
/// Tells the receiver that the ready state did change.
func stream(_ stream: IOStream, didChangeReadyState state: IOStream.ReadyState)
}

@available(*, deprecated, renamed: "IOStream")
Expand Down Expand Up @@ -301,13 +305,15 @@ open class IOStream: NSObject {
guard readyState != newValue else {
return
}
delegate?.stream(self, willChangeReadyState: readyState)
readyStateWillChange(to: newValue)
}
didSet {
guard readyState != oldValue else {
return
}
readyStateDidChange(to: readyState)
delegate?.stream(self, didChangeReadyState: readyState)
}
}

Expand Down

0 comments on commit 1d72595

Please sign in to comment.