zello_client/
lib.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2// SPDX-FileCopyrightText: 2024 John C. Murray
3
4#![warn(clippy::all, clippy::pedantic, rust_2018_idioms)]
5#![warn(missing_debug_implementations, clippy::unwrap_used)]
6#![allow(
7    clippy::module_name_repetitions,
8    clippy::missing_errors_doc,
9    clippy::missing_panics_doc
10)]
11#![doc = include_str!("../README.md")]
12
13pub mod client;
14pub mod error;
15pub mod handlers;
16pub mod message;
17pub mod protocol;
18pub mod utilities;
19
20// Re-exports for convenience
21use audiopus::{Channels, SampleRate};
22pub use client::*;
23pub use error::{Result, ZelloError};
24pub use handlers::{handle_message, process_audio_output};
25pub use message::{CodecHeader, Error, Event, IncomingMessage, Message, Response};
26pub use protocol::Protocol;
27pub use utilities::{
28    connect_to_zello, create_decoder, initialize_logging, load_credentials, load_dotenv,
29    setup_audio_output,
30};
31
32/// Library version
33pub const VERSION: &str = env!("CARGO_PKG_VERSION");
34
35/// GIT version
36pub const GIT_VERSION: &str = env!("GIT_VERSION");
37
38/// Zello uses a mono audio stream.
39pub const OPUS_CHANNELS: Channels = Channels::Mono;
40
41/// Zello uses a 16kHz sample rate.
42pub const OPUS_SAMPLE_RATE: SampleRate = SampleRate::Hz16000;
43
44/// PCM buffer capacity for Zello audio stream.
45pub const PCM_CHANNEL_CAPACITY: usize = 20;
46
47/// PCM buffer size for Zello audio stream.
48pub const PCM_BUFFER_SIZE: usize = 1920;
49
50///Cpal sample rate to match Zello audio stream.
51pub const CPAL_SAMPLE_RATE: cpal::SampleRate = cpal::SampleRate(16000);
52
53///Cpal channels to match Zello audio stream.
54pub const CPAL_CHANNELS: u16 = 1;
55
56///Cpal vector queue capacity to match Zello audio stream.
57pub const CPAL_VECTOR_QUEUE_CAPACITY: usize = 8192;
58
59/// PCM to cpal conversion factor for PCM to cpal audio stream.
60pub const PCM_I16_TO_F32: f32 = 1.0 / 32768.0;
61
62/// Cpal buffer size to match Zello audio stream.
63#[allow(clippy::cast_possible_truncation)]
64pub const CPAL_BUFFER_SIZE: cpal::BufferSize =
65    cpal::BufferSize::Fixed(PCM_BUFFER_SIZE as cpal::FrameCount);
66
67/// Default Zello WebSocket URL
68pub const ZELLO_DEFAULT_URL: &str = "wss://zello.io/ws";
69
70#[cfg(test)]
71mod tests {
72    use super::*;
73
74    #[test]
75    fn test_version() {
76        assert!(!VERSION.is_empty());
77    }
78
79    #[test]
80    fn test_git_version() {
81        assert!(!GIT_VERSION.is_empty());
82    }
83}