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
impl NodeContext
Sourcepub fn take_input(
&mut self,
pin_name: &str,
) -> Result<Receiver<Packet>, StreamKitError>
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.
Sourcepub async fn recv_with_cancellation(
&self,
rx: &mut Receiver<Packet>,
) -> Option<Packet>
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.