Constructor

pub fn new(endpoint_url: &str, lib_path: &str) -> std::io::Result<Self>
ArgumentNotes
endpoint_urlquic://host:port
lib_pathAbsolute path to telequick_core_ffi.so / .dylib / .dll.
new loads the FFI lib via libloading::Library::new. Safety: the caller is responsible for pointing at a trusted path; symbols are invoked through typed wrappers that match the C ABI defined by apirpc_compiler.

Connection

pub async fn connect(&mut self) -> Result<(), Box<dyn Error>>
Connects to the gateway, spawns the receive loop, and subscribes events. Called automatically on first RPC; explicit call reduces first-RPC latency.

Callbacks

pub on_audio_frame: Option<Arc<dyn Fn(Vec<u8>) + Send + Sync>>
pub on_call_event:  Option<Arc<dyn Fn(Vec<u8>) + Send + Sync>>
Both deliver the raw serde envelope of AudioFrame / CallEvent. Decode using whatever serde reader you’ve integrated.

RPC methods

All methods are async and return Result<(), Box<dyn Error>>.
async fn dial(&mut self,
    to: &str,
    trunk_id: &str,
    auto_barge_in: bool,
    barge_in_patience_ms: i32,
    client_id: Option<&str>,
) -> Result<(), Box<dyn Error>>;

async fn originate_bulk(&mut self,
    csv_url: &str,
    trunk_id: &str,
    cps: i32,
    cmp_id: &str,
    auto_barge_in: bool,
    barge_in_patience_ms: i32,
) -> Result<(), Box<dyn Error>>;

async fn terminate(&mut self, call_sid: &str)              -> Result<(), Box<dyn Error>>;
async fn abort_bulk(&mut self, campaign_id: &str)          -> Result<(), Box<dyn Error>>;
async fn stream_events(&mut self, client_id: &str)         -> Result<(), Box<dyn Error>>;
async fn barge(&mut self, call_sid: &str)                  -> Result<(), Box<dyn Error>>;

async fn set_inbound_routing(&mut self,
    trunk_id: &str, rule: i32,
    audio_url: &str, webhook_url: &str, ai_ws: &str, ai_quic: &str,
) -> Result<(), Box<dyn Error>>;

async fn get_incoming_calls(&mut self, trunk_id: &str)     -> Result<(), Box<dyn Error>>;

async fn answer_incoming_call(&mut self,
    call_sid: &str, ai_ws: &str, ai_quic: &str,
) -> Result<(), Box<dyn Error>>;

async fn get_active_buckets(&mut self)                     -> Result<(), Box<dyn Error>>;
async fn get_bucket_calls(&mut self, bucket_id: &str)      -> Result<(), Box<dyn Error>>;

async fn execute_bucket_action(&mut self,
    bucket_id: &str, action: i32,
) -> Result<(), Box<dyn Error>>;

async fn push_audio(&mut self,
    call_sid: &str, payload: &[u8], codec: &str,
    seq_num: u64, eos: bool,
) -> Result<(), Box<dyn Error>>;
dial deliberately exposes a smaller arg set than other SDKs — additional fields default to gateway defaults. Reach for the FFI directly via the telequick::ffi module if you need full control.

Method ID constants

use telequick::method_id::*;

METHOD_ID_ORIGINATE
METHOD_ID_AUDIO_FRAME
METHOD_ID_STREAM_EVENTS
// …

Concurrency

TeleQuickClient requires &mut self for RPCs because it owns the underlying quinn::Connection and the audio uni-stream. Wrap it in Arc<Mutex<...>> if multiple tasks need to call RPCs. The receive loop runs on a dedicated tokio::task and invokes your callbacks in that task’s context. Keep callbacks short; offload heavy work to a mpsc::channel.

Errors

ErrorCause
Failed to load native library (panic)lib_path invalid. Check the file exists and arch matches.
quinn::ConnectErrorGateway unreachable or TLS handshake failed.
std::io::Error("write") from send_rpcConnection dropped mid-write. Retry after connect.