Skip to main content

SendListener

Struct SendListener 

Source
pub struct SendListener { /* private fields */ }
Expand description

Lists the senders registered with a Discovery Server and reports their events.

§Connection

A listener connects in the background and keeps trying for as long as it lives. It is created whether or not its server can be reached; until the server answers, which can take several seconds after it appears, is_connected is false and snapshots are empty.

§Threading

A listener is Send but not Sync: it may be moved to another thread, and is used by one thread at a time. is_connected and server_url take a shared reference, and the SDK documents neither as safe to call on one listener from several threads at once; it forbids overlapping membership queries on one listener. Snapshots and events are plain owned data and can be shared freely.

Implementations§

Source§

impl SendListener

Source

pub fn new(ndi: &Ndi, options: &ListenerOptions) -> Result<Self>

Create a listener for the Discovery Server options name.

Success does not mean the server was reached; see Connection.

§Errors

Returns Error::UnsupportedCapability when the selected runtime cannot provide sender discovery, which needs NDI 6.4.0 or later, or the options carry an Advanced configuration that the runtime or this build cannot take; Error::InvalidCString when the endpoint contains a NUL byte; and Error::InvalidInput when the endpoint is empty, the options name multiple endpoints, or the SDK creates no listener. Without an explicit server the SDK uses its configuration; creation fails when it names no server or one the SDK cannot use. An explicit address the SDK cannot parse is also refused.

Source

pub fn is_connected(&self) -> bool

Whether the listener is connected to its Discovery Server right now. A listener that is not connected keeps trying. This reports registry connectivity, not progress of any receiver media.

Source

pub fn server_url(&self) -> Option<String>

The Discovery Server endpoint the listener uses, when the SDK reports one.

None when the SDK reports none, and also when what it reports is no string of less than 4 MiB, the most this crate reads from one SDK string. No endpoint is that long, and the value is for display only: the listener does not depend on it and the crate never passes it back to the SDK. So a value that cannot be read is reported as no value, rather than as an error that every caller of this getter would have to handle. Bytes that are not UTF-8 are replaced with U+FFFD, as in the other text a listener reports.

Source

pub fn wait_for_change(&mut self, timeout: Duration) -> Result<bool>

Wait for the advertised membership to change; a zero timeout polls.

§Errors

Returns Error::InvalidInput when timeout exceeds crate::MAX_TIMEOUT.

Source

pub fn subscribe(&mut self, id: &SenderId)

Ask to receive the events of the peer id names. The next snapshot reports whether the subscription is active.

The listener keeps its own copy of the identifier until unsubscribe returns or the listener is dropped.

Source

pub fn unsubscribe(&mut self, id: &SenderId)

Ask to stop receiving the events of the peer id names.

With the NDI 6.3.2 and 6.4.0.2 runtimes, unsubscribing from a receiver can permanently block that receiver’s connect, in this process or another, when it connects at the same moment: an SDK defect the crate cannot prevent. Dropping the listener ends its subscriptions without that risk. See the module documentation.

Source

pub fn next_events( &mut self, timeout: Duration, ) -> Result<Vec<ListenerEvent<SenderId>>>

Take the events that arrived since the last call, in arrival order, waiting up to timeout for the first one. An empty batch means none arrived in time; a zero timeout polls.

An event with a string of 4 MiB or longer is omitted; its scan still spends the shared budget. Other events remain in order.

§Errors

Returns Error::InvalidInput when timeout exceeds crate::MAX_TIMEOUT, Error::ResourceLimit when copying the batch would exceed its 16 MiB budget, and Error::UnexpectedSdkResult when the top-level batch array is malformed, or Error::AllocationFailed when storage cannot be reserved. The SDK has already handed a rejected batch over, so it is freed and its events are lost.

Source

pub fn current_senders(&mut self) -> Result<Vec<AdvertisedSender>>

Copy the senders currently advertised. The list is empty while the listener is not connected.

An entry with a string of 4 MiB or longer, or a malformed nested array, is omitted. Its scans still spend the shared budget. Text that is not valid UTF-8 is decoded lossily; see the module documentation.

§Errors

Returns Error::ResourceLimit when copying would exceed the 16 MiB budget, and Error::UnexpectedSdkResult when the top-level snapshot array is malformed. Error::AllocationFailed when storage cannot be reserved.

Trait Implementations§

Source§

impl Debug for SendListener

Source§

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

Formats the value using the given formatter. 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.