Skip to main content

StreamCallbacks

Struct StreamCallbacks 

Source
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

Source

pub fn new() -> Self

Create a new empty callbacks builder

Source

pub fn on_stop<F>(self, f: F) -> Self
where F: Fn(Option<String>) + Send + Sync + 'static,

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.

Source

pub fn on_error<F>(self, f: F) -> Self
where F: Fn(SCError) + Send + Sync + 'static,

Set the callback for when the stream encounters an error

Source

pub fn on_active<F>(self, f: F) -> Self
where F: Fn() + Send + Sync + 'static,

Set the callback for when the stream becomes active (macOS 15.2+)

Source

pub fn on_inactive<F>(self, f: F) -> Self
where F: Fn() + Send + Sync + 'static,

Set the callback for when the stream becomes inactive (macOS 15.2+)

Source

pub fn on_video_effect_start<F>(self, f: F) -> Self
where F: Fn() + Send + Sync + 'static,

Set the callback for when video effects start (macOS 14.0+)

Source

pub fn on_video_effect_stop<F>(self, f: F) -> Self
where F: Fn() + Send + Sync + 'static,

Set the callback for when video effects stop (macOS 14.0+)

Trait Implementations§

Source§

impl Debug for StreamCallbacks

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for StreamCallbacks

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl SCStreamDelegateTrait for StreamCallbacks

Source§

fn stream_did_stop(&self, error: Option<String>)

👎Deprecated:

ScreenCaptureKit reports stops only via did_stop_with_error; the stream engine no longer invokes this method. Implement did_stop_with_error instead.

Called when stream stops. Read more
Source§

fn did_stop_with_error(&self, error: SCError)

Called when the stream stops with an error. Read more
Source§

fn stream_did_become_active(&self)

Called when the stream becomes active (macOS 15.2+) Read more
Source§

fn stream_did_become_inactive(&self)

Called when the stream becomes inactive (macOS 15.2+) Read more
Source§

fn output_video_effect_did_start_for_stream(&self)

Called when video effects start (macOS 14.0+) Read more
Source§

fn output_video_effect_did_stop_for_stream(&self)

Called when video effects stop (macOS 14.0+) Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.