pub struct StreamCallbacks { /* private fields */ }Expand description
Builder for closure-based stream delegate
Provides a convenient way to create a stream delegate using closures
instead of implementing the SCStreamDelegateTrait trait.
§Examples
use screencapturekit::prelude::*;
use screencapturekit::stream::delegate_trait::StreamCallbacks;
// Create delegate with multiple callbacks
let delegate = StreamCallbacks::new()
.on_stop(|error| {
if let Some(e) = error {
eprintln!("Stream stopped with error: {}", e);
} else {
println!("Stream stopped normally");
}
})
.on_error(|error| eprintln!("Stream error: {}", error))
.on_active(|| println!("Stream became active"))
.on_inactive(|| println!("Stream became inactive"));
let stream = SCStream::new_with_delegate(&filter, &config, delegate);Implementations§
Source§impl StreamCallbacks
impl StreamCallbacks
Sourcepub fn on_stop<F>(self, f: F) -> Self
pub fn on_stop<F>(self, f: F) -> Self
Set the callback for when the stream stops.
The closure receives Some(message) describing the error that stopped
the stream. Because ScreenCaptureKit only reports error stops to the
delegate, this fires alongside on_error on an error
stop; a clean stop you requested via
SCStream::stop_capture is not
delivered here. Prefer on_error when you want the
typed SCError.
Sourcepub fn on_error<F>(self, f: F) -> Self
pub fn on_error<F>(self, f: F) -> Self
Set the callback for when the stream encounters an error
Sourcepub fn on_active<F>(self, f: F) -> Self
pub fn on_active<F>(self, f: F) -> Self
Set the callback for when the stream becomes active (macOS 15.2+)
Sourcepub fn on_inactive<F>(self, f: F) -> Self
pub fn on_inactive<F>(self, f: F) -> Self
Set the callback for when the stream becomes inactive (macOS 15.2+)
Sourcepub fn on_video_effect_start<F>(self, f: F) -> Self
pub fn on_video_effect_start<F>(self, f: F) -> Self
Set the callback for when video effects start (macOS 14.0+)
Sourcepub fn on_video_effect_stop<F>(self, f: F) -> Self
pub fn on_video_effect_stop<F>(self, f: F) -> Self
Set the callback for when video effects stop (macOS 14.0+)
Trait Implementations§
Source§impl Debug for StreamCallbacks
impl Debug for StreamCallbacks
Source§impl Default for StreamCallbacks
impl Default for StreamCallbacks
Source§impl SCStreamDelegateTrait for StreamCallbacks
impl SCStreamDelegateTrait for StreamCallbacks
Source§fn stream_did_stop(&self, error: Option<String>)
fn stream_did_stop(&self, error: Option<String>)
ScreenCaptureKit reports stops only via did_stop_with_error; the stream engine no longer invokes this method. Implement did_stop_with_error instead.