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
impl SendListener
Sourcepub fn new(ndi: &Ndi, options: &ListenerOptions) -> Result<Self>
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.
Sourcepub fn is_connected(&self) -> bool
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.
Sourcepub fn server_url(&self) -> Option<String>
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.
Sourcepub fn wait_for_change(&mut self, timeout: Duration) -> Result<bool>
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.
Sourcepub fn subscribe(&mut self, id: &SenderId)
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.
Sourcepub fn unsubscribe(&mut self, id: &SenderId)
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.
Sourcepub fn next_events(
&mut self,
timeout: Duration,
) -> Result<Vec<ListenerEvent<SenderId>>>
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.
Sourcepub fn current_senders(&mut self) -> Result<Vec<AdvertisedSender>>
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.