ZelloClient

Struct ZelloClient 

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

Zello client for interacting with the Zello API

Implementations§

Source§

impl ZelloClient

Zello client for interacting with the Zello API

Source

pub async fn new(config: ZelloConfig) -> Result<Self>

Create a new Zello client and connect

#Errors

Returns an error if fail to create a new Zello client

Source

pub async fn run_message_loop( &mut self, decoder: Arc<Mutex<Decoder>>, pcm_tx: &Sender<Vec<i16>>, ) -> Result<()>

Run the main message processing loop

§Errors

Returns an error if message receiving fails

Examples found in repository?
examples/complete.rs (line 84)
59async fn main() -> Result<()> {
60    let args = Args::parse();
61
62    load_dotenv_from_file("examples/.env.example")?;
63    initialize_logging()?;
64
65    let credentials = load_credentials()?;
66    let decoder = create_decoder()?;
67
68    let (pcm_tx, pcm_rx) = bounded::<Vec<i16>>(PCM_CHANNEL_CAPACITY);
69    let pcm_rx = Arc::new(Mutex::new(pcm_rx));
70    let _stream = setup_audio_output(pcm_rx)?;
71
72    let mut client = connect_to_zello(&credentials).await?;
73
74    match (args.message, args.callsign) {
75        (Some(msg), Some(callsign)) => {
76            client
77                .send_text_message_to_callsign(&msg, &callsign)
78                .await?;
79        }
80        (Some(msg), None) => {
81            client.send_text_message(&msg).await?;
82        }
83        (None, _) => {
84            client.run_message_loop(decoder, &pcm_tx).await?;
85        }
86    }
87
88    client.close().await?;
89
90    Ok(())
91}
Source

pub async fn send_text_message(&mut self, text: &str) -> Result<()>

Send a text message to the channel

§Errors

Returns an error if fail to send a text message to the channel

Examples found in repository?
examples/simple.rs (line 17)
12async fn main() -> Result<()> {
13    load_dotenv_from_file("examples/.env.example")?;
14    initialize_logging()?;
15    let credentials = load_credentials()?;
16    let mut client = connect_to_zello(&credentials).await?;
17    client.send_text_message("Hello from Zello!").await?;
18    client.close().await?;
19    Ok(())
20}
More examples
Hide additional examples
examples/complete.rs (line 81)
59async fn main() -> Result<()> {
60    let args = Args::parse();
61
62    load_dotenv_from_file("examples/.env.example")?;
63    initialize_logging()?;
64
65    let credentials = load_credentials()?;
66    let decoder = create_decoder()?;
67
68    let (pcm_tx, pcm_rx) = bounded::<Vec<i16>>(PCM_CHANNEL_CAPACITY);
69    let pcm_rx = Arc::new(Mutex::new(pcm_rx));
70    let _stream = setup_audio_output(pcm_rx)?;
71
72    let mut client = connect_to_zello(&credentials).await?;
73
74    match (args.message, args.callsign) {
75        (Some(msg), Some(callsign)) => {
76            client
77                .send_text_message_to_callsign(&msg, &callsign)
78                .await?;
79        }
80        (Some(msg), None) => {
81            client.send_text_message(&msg).await?;
82        }
83        (None, _) => {
84            client.run_message_loop(decoder, &pcm_tx).await?;
85        }
86    }
87
88    client.close().await?;
89
90    Ok(())
91}
Source

pub async fn send_text_message_to_callsign( &mut self, text: &str, callsign: &str, ) -> Result<()>

Send a text message to the channel

§Errors

Returns an error if fail to send a text message to the channel

Examples found in repository?
examples/complete.rs (line 77)
59async fn main() -> Result<()> {
60    let args = Args::parse();
61
62    load_dotenv_from_file("examples/.env.example")?;
63    initialize_logging()?;
64
65    let credentials = load_credentials()?;
66    let decoder = create_decoder()?;
67
68    let (pcm_tx, pcm_rx) = bounded::<Vec<i16>>(PCM_CHANNEL_CAPACITY);
69    let pcm_rx = Arc::new(Mutex::new(pcm_rx));
70    let _stream = setup_audio_output(pcm_rx)?;
71
72    let mut client = connect_to_zello(&credentials).await?;
73
74    match (args.message, args.callsign) {
75        (Some(msg), Some(callsign)) => {
76            client
77                .send_text_message_to_callsign(&msg, &callsign)
78                .await?;
79        }
80        (Some(msg), None) => {
81            client.send_text_message(&msg).await?;
82        }
83        (None, _) => {
84            client.run_message_loop(decoder, &pcm_tx).await?;
85        }
86    }
87
88    client.close().await?;
89
90    Ok(())
91}
Source

pub async fn start_audio_stream( &mut self, codec: &str, packet_duration: u32, ) -> Result<u32>

Start an audio stream

§Errors

Returns an error if fail to start an audio stream

Source

pub async fn send_audio_packet( &mut self, stream_id: u32, data: Vec<u8>, ) -> Result<()>

Send audio data packet

§Errors

Returns an error if fail to send audio data packet

Source

pub async fn stop_audio_stream(&mut self, stream_id: u32) -> Result<()>

Stop an audio stream

§Errors

Returns an error if fail to stop an audio stream

Source

pub async fn receive_message(&mut self) -> Result<Option<IncomingMessage>>

Receive the next message

§Errors

Returns an error if fail to receive the next message

Source

pub fn is_authenticated(&self) -> bool

Check if client is authenticated

Source

pub fn channel(&self) -> &str

Get the current channel

Source

pub async fn close(self) -> Result<()>

Close the connection

§Errors

Returns an error if fail to close the connection

Examples found in repository?
examples/simple.rs (line 18)
12async fn main() -> Result<()> {
13    load_dotenv_from_file("examples/.env.example")?;
14    initialize_logging()?;
15    let credentials = load_credentials()?;
16    let mut client = connect_to_zello(&credentials).await?;
17    client.send_text_message("Hello from Zello!").await?;
18    client.close().await?;
19    Ok(())
20}
More examples
Hide additional examples
examples/complete.rs (line 88)
59async fn main() -> Result<()> {
60    let args = Args::parse();
61
62    load_dotenv_from_file("examples/.env.example")?;
63    initialize_logging()?;
64
65    let credentials = load_credentials()?;
66    let decoder = create_decoder()?;
67
68    let (pcm_tx, pcm_rx) = bounded::<Vec<i16>>(PCM_CHANNEL_CAPACITY);
69    let pcm_rx = Arc::new(Mutex::new(pcm_rx));
70    let _stream = setup_audio_output(pcm_rx)?;
71
72    let mut client = connect_to_zello(&credentials).await?;
73
74    match (args.message, args.callsign) {
75        (Some(msg), Some(callsign)) => {
76            client
77                .send_text_message_to_callsign(&msg, &callsign)
78                .await?;
79        }
80        (Some(msg), None) => {
81            client.send_text_message(&msg).await?;
82        }
83        (None, _) => {
84            client.run_message_loop(decoder, &pcm_tx).await?;
85        }
86    }
87
88    client.close().await?;
89
90    Ok(())
91}
Source

pub fn add_inbound_stream( &mut self, stream_id: u32, channel: String, codec: String, callsign: Option<String>, ) -> Result<()>

Add a new inbound stream to the client

§Errors

Returns an error if fail to add a new inbound stream

Source

pub fn get_inbound_stream(&self, stream_id: u32) -> Option<&StreamInfo>

Get an inbound stream from the client

Source

pub fn remove_inbound_stream(&mut self, stream_id: u32) -> Result<()>

Remove an inbound stream from the client

§Errors

Returns an error if fail to remove an inbound stream

Trait Implementations§

Source§

impl Debug for ZelloClient

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<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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

Source§

type Output = T

Should always be Self
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,