NodeContext

Struct NodeContext 

Source
pub struct NodeContext {
    pub inputs: HashMap<String, Receiver<Packet>>,
    pub control_rx: Receiver<NodeControlMessage>,
    pub output_sender: OutputSender,
    pub batch_size: usize,
    pub state_tx: Sender<NodeStateUpdate>,
    pub stats_tx: Option<Sender<NodeStatsUpdate>>,
    pub telemetry_tx: Option<Sender<TelemetryEvent>>,
    pub session_id: Option<String>,
    pub cancellation_token: Option<CancellationToken>,
    pub pin_management_rx: Option<Receiver<PinManagementMessage>>,
    pub audio_pool: Option<Arc<AudioFramePool>>,
}
Expand description

The context provided by the engine to a node when it is run.

Fields§

§inputs: HashMap<String, Receiver<Packet>>§control_rx: Receiver<NodeControlMessage>§output_sender: OutputSender§batch_size: usize§state_tx: Sender<NodeStateUpdate>

Channel for the node to report state changes. Nodes should send updates when transitioning between states to enable monitoring and debugging. It’s acceptable if sends fail (e.g., in stateless pipelines where state tracking may not be enabled).

§stats_tx: Option<Sender<NodeStatsUpdate>>

Channel for the node to report statistics updates. Nodes should throttle these updates (e.g., every 10s or 1000 packets) to prevent overloading the monitoring system. Like state_tx, it’s acceptable if sends fail.

§telemetry_tx: Option<Sender<TelemetryEvent>>

Channel for the node to emit telemetry events. Telemetry is best-effort and should never block audio processing. Nodes should use try_send() or the TelemetryEmitter helper which handles rate limiting and drop accounting automatically.

§session_id: Option<String>

Session ID for gateway registration and routing (if applicable)

§cancellation_token: Option<CancellationToken>

Cancellation token for coordinated shutdown of pipeline tasks. When this token is cancelled, nodes should stop processing and exit gracefully. This is primarily used in stateless pipelines to abort processing when the client disconnects or the request is interrupted.

§pin_management_rx: Option<Receiver<PinManagementMessage>>

Channel for runtime pin management messages (Tier 2). Only provided for nodes that support dynamic pins.

§audio_pool: Option<Arc<AudioFramePool>>

Optional per-pipeline audio buffer pool for hot-path allocations.

Nodes that produce audio frames (decoders, resamplers, mixers) may use this to amortize Vec<f32> allocations. If None, nodes should fall back to allocating.

Implementations§

Source§

impl NodeContext

Source

pub fn take_input( &mut self, pin_name: &str, ) -> Result<Receiver<Packet>, StreamKitError>

Retrieves an input pin receiver by name, returning an error if not found. This is a convenience method to avoid repeated error handling boilerplate.

§Errors

Returns StreamKitError::Runtime if the requested input pin doesn’t exist.

Source

pub async fn recv_with_cancellation( &self, rx: &mut Receiver<Packet>, ) -> Option<Packet>

Receives a packet from the given receiver, respecting the cancellation token if present. Returns None if cancelled or if the channel is closed.

This is a convenience method that should be used in node loops instead of calling recv() directly, as it automatically handles cancellation for stateless pipelines.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more