libivon 0.1.0
Voice-over-IP library
Loading...
Searching...
No Matches
ivon::VoiceSessionWrapper Class Reference

Consumer-facing C++ wrapper around the voice session C ABI. More...

#include <ivon_voice_session_wrapper.hpp>

Classes

struct  Config
 Combined configuration for the voice session. More...
 
struct  SpeakingInfo
 Speaking state change with client ID mapping. More...
 

Public Types

using OutputFrame = AudioOutputFrame
 Structured output frame info returned by try_read_output().
 
using PcmSourceCallback = ::ivon::PcmSourceCallback
 Set the PCM source callback for local audio capture.
 
using VoiceJoinedCallback = std::function< void(const std::string &group_id, bool success, const std::string &error_message)>
 
using SpeakingCallback = std::function< void(const SpeakingInfo &info)>
 
using VoiceErrorCallback = std::function< void(const std::string &group_id, const std::string &error_message)>
 
using MemberJoinedCallback = std::function< void(const std::string &group_id, uint64_t sender_id, const std::string &client_id)>
 
using MemberLeftCallback = std::function< void(const std::string &group_id, uint64_t sender_id, const std::string &client_id)>
 

Public Member Functions

 VoiceSessionWrapper (const Config &cfg)
 Construct a wrapper and create the underlying voice session.
 
 ~VoiceSessionWrapper ()
 
 VoiceSessionWrapper (const VoiceSessionWrapper &)=delete
 
VoiceSessionWrapperoperator= (const VoiceSessionWrapper &)=delete
 
 VoiceSessionWrapper (VoiceSessionWrapper &&)=delete
 
VoiceSessionWrapperoperator= (VoiceSessionWrapper &&)=delete
 
expected_void< NegotiationErrorconnect ()
 Connect to the server (blocking).
 
void disconnect ()
 Disconnect from the server and stop audio processing.
 
void start_audio ()
 Start the audio processor (tick coordinator + worker threads).
 
void stop_audio ()
 Stop the audio processor.
 
void set_pcm_source (PcmSourceCallback cb)
 
void start_speaking (ivon_speaking_mode_t mode=IVON_SPEAKING_MODE_PTT)
 Start speaking. The PCM source callback will begin firing.
 
void enable_transmit (const std::string &group_id={})
 Enable audio transmission.
 
void disable_transmit (const std::string &group_id={})
 Disable audio transmission.
 
bool join_voice_group (const std::string &group_id)
 Manually join a voice group.
 
bool leave_voice_group (const std::string &group_id)
 Leave a voice group. Returns false if not connected.
 
bool is_voice_group_joined (const std::string &group_id={}) const noexcept
 Check if a voice group has been successfully joined.
 
ClientWrapperclient () noexcept
 Get a reference to the non-owning ClientWrapper.
 
const ClientWrapperclient () const noexcept
 
ivon_client_t client_handle () const noexcept
 Get the underlying client handle (non-owning).
 
AudioWrapperaudio () noexcept
 Get a reference to the non-owning AudioWrapper.
 
const AudioWrapperaudio () const noexcept
 
ivon_audio_t audio_handle () const noexcept
 Get the underlying audio processor handle (non-owning).
 
uint64_t local_sender_id () const noexcept
 Get the local fanout sender ID (0 if not yet connected).
 
void on_tofu_verify (TofuVerifyCallback cb)
 Forward to client().on_tofu_verify().
 
void on_password_required (PasswordCallback cb)
 Forward to client().on_password_required().
 
void on_client_message (ClientMessageCallback cb)
 Forward to client().on_client_message().
 
void on_client_joined (ClientJoinedCallback cb)
 Forward to client().on_client_joined().
 
void on_client_left (ClientLeftCallback cb)
 Forward to client().on_client_left().
 
void on_kicked (KickedCallback cb)
 Forward to client().on_kicked().
 
void on_disconnected (DisconnectedCallback cb)
 Forward to client().on_disconnected().
 
void on_connection_state_changed (ConnectionStateCallback cb)
 Forward to client().on_connection_state_changed().
 
void on_group_left (GroupLeaveCallback cb)
 Forward to client().on_group_left().
 
void on_group_kicked (GroupKickedCallback cb)
 Forward to client().on_group_kicked().
 
void on_group_list (GroupListCallback cb)
 Forward to client().on_group_list().
 
void on_server_properties (ServerPropertiesCallback cb)
 Forward to client().on_server_properties().
 
void on_server_property_update (ServerPropertyUpdateCallback cb)
 Forward to client().on_server_property_update().
 
void on_group_property_update (GroupPropertyUpdateCallback cb)
 Forward to client().on_group_property_update().
 
bool send_client_message (const std::string &client_id, const std::string &type, const std::vector< uint8_t > &buffer)
 Send a typed message to a specific remote client.
 
bool send_broadcast_message (const std::string &type, const std::vector< uint8_t > &buffer)
 Broadcast a typed message to all connected clients.
 
bool send_group_message (const std::string &group_id, const std::string &type, const std::vector< uint8_t > &buffer)
 Send a typed message to all members of a group.
 
size_t get_remote_client_count () const noexcept
 Get the count of remote clients in the session.
 
bool has_remote_client (const std::string &client_id) const noexcept
 Check if a remote client with the given ID exists.
 
std::vector< std::string > get_remote_client_ids () const
 Get all remote client IDs as a vector.
 
bool set_mute (const std::string &group_id, const std::string &target_client_id, bool muted)
 Mute or unmute a target client in a specific group.
 
bool request_group_list ()
 Request the list of available groups from the server.
 
std::vector< std::string > get_group_ids () const
 Get all group IDs this client is a member of.
 
void on_voice_joined (VoiceJoinedCallback cb)
 Set callback for voice group join result.
 
void on_speaking (SpeakingCallback cb)
 Set callback for remote speaking state changes.
 
void on_voice_error (VoiceErrorCallback cb)
 Set callback for voice group runtime errors.
 
void on_member_joined (MemberJoinedCallback cb)
 Set callback for when a member joins the voice group.
 
void on_member_left (MemberLeftCallback cb)
 Set callback for when a member leaves the voice group.
 
std::set< uint64_t > get_speaking_senders () const
 Get the sender IDs of currently speaking remote senders.
 
ivon_audio_stats_t get_audio_stats () const noexcept
 Get aggregate audio statistics snapshot.
 
void set_log_level (int level)
 Set the runtime log level for the session's internal loggers.
 
int get_log_level () const
 Get the current log level.
 
ivon_voice_session_t handle () const noexcept
 Get the underlying opaque C handle.
 

Detailed Description

Consumer-facing C++ wrapper around the voice session C ABI.

RAII handle: the constructor creates the session, the destructor destroys it. Non-copyable, non-moveable; use std::unique_ptr for deferred initialization or ownership transfer.

Member Typedef Documentation

◆ MemberJoinedCallback

using ivon::VoiceSessionWrapper::MemberJoinedCallback = std::function<void(const std::string &group_id, uint64_t sender_id, const std::string &client_id)>

◆ MemberLeftCallback

using ivon::VoiceSessionWrapper::MemberLeftCallback = std::function<void(const std::string &group_id, uint64_t sender_id, const std::string &client_id)>

◆ OutputFrame

Structured output frame info returned by try_read_output().

◆ PcmSourceCallback

Set the PCM source callback for local audio capture.

Called every 20 ms while speaking. Fill the provided buffer with mono float PCM samples.

◆ SpeakingCallback

using ivon::VoiceSessionWrapper::SpeakingCallback = std::function<void(const SpeakingInfo &info)>

◆ VoiceErrorCallback

using ivon::VoiceSessionWrapper::VoiceErrorCallback = std::function<void(const std::string &group_id, const std::string &error_message)>

◆ VoiceJoinedCallback

using ivon::VoiceSessionWrapper::VoiceJoinedCallback = std::function<void(const std::string &group_id, bool success, const std::string &error_message)>

Constructor & Destructor Documentation

◆ VoiceSessionWrapper() [1/3]

ivon::VoiceSessionWrapper::VoiceSessionWrapper ( const Config cfg)
inlineexplicit

Construct a wrapper and create the underlying voice session.

Exceptions
std::runtime_errorif creation fails.

◆ ~VoiceSessionWrapper()

ivon::VoiceSessionWrapper::~VoiceSessionWrapper ( )
inline

◆ VoiceSessionWrapper() [2/3]

ivon::VoiceSessionWrapper::VoiceSessionWrapper ( const VoiceSessionWrapper )
delete

◆ VoiceSessionWrapper() [3/3]

ivon::VoiceSessionWrapper::VoiceSessionWrapper ( VoiceSessionWrapper &&  )
delete

Member Function Documentation

◆ audio() [1/2]

const AudioWrapper & ivon::VoiceSessionWrapper::audio ( ) const
inlinenoexcept

◆ audio() [2/2]

AudioWrapper & ivon::VoiceSessionWrapper::audio ( )
inlinenoexcept

Get a reference to the non-owning AudioWrapper.

Use for calling audio methods (is_speaking, stop_speaking, try_read_output, set_sender_muted, etc.) with C++ ergonomics.

Note
Returns nullptr-backed wrapper before start_audio(); audio methods are safe to call but will no-op / return defaults.

◆ audio_handle()

ivon_audio_t ivon::VoiceSessionWrapper::audio_handle ( ) const
inlinenoexcept

Get the underlying audio processor handle (non-owning).

Prefer audio() for ergonomic C++ access. This raw handle is useful when mixing wrapper code with direct C ABI calls.

Warning
Do NOT destroy this handle.

◆ client() [1/2]

const ClientWrapper & ivon::VoiceSessionWrapper::client ( ) const
inlinenoexcept

◆ client() [2/2]

ClientWrapper & ivon::VoiceSessionWrapper::client ( )
inlinenoexcept

Get a reference to the non-owning ClientWrapper.

Use for registering non-audio callbacks (chat, presence, TOFU) and calling client methods like send_client_message().

Warning
Do NOT replace audio/group callbacks (on_fanout_data, on_group_joined, etc.) — they are managed internally by the voice session.

◆ client_handle()

ivon_client_t ivon::VoiceSessionWrapper::client_handle ( ) const
inlinenoexcept

Get the underlying client handle (non-owning).

Prefer client() for ergonomic C++ access. This raw handle is useful when mixing wrapper code with direct C ABI calls.

Warning
Do NOT destroy this handle.

◆ connect()

expected_void< NegotiationError > ivon::VoiceSessionWrapper::connect ( )
inline

Connect to the server (blocking).

If voice_group_id was set in the config, the session will automatically join that group after connection. Additional groups from voice_group_ids are joined afterwards.

◆ disable_transmit()

void ivon::VoiceSessionWrapper::disable_transmit ( const std::string &  group_id = {})
inline

Disable audio transmission.

Parameters
group_idGroup to disable (empty = all groups).

◆ disconnect()

void ivon::VoiceSessionWrapper::disconnect ( )
inline

Disconnect from the server and stop audio processing.

◆ enable_transmit()

void ivon::VoiceSessionWrapper::enable_transmit ( const std::string &  group_id = {})
inline

Enable audio transmission.

Automatically called on successful auto-join. Only needed when managing group membership manually.

Parameters
group_idGroup to enable (empty = all groups).

◆ get_audio_stats()

ivon_audio_stats_t ivon::VoiceSessionWrapper::get_audio_stats ( ) const
inlinenoexcept

Get aggregate audio statistics snapshot.

Returns decoder, encoder, and pipeline counters. Values are approximate while the session is running.

◆ get_group_ids()

std::vector< std::string > ivon::VoiceSessionWrapper::get_group_ids ( ) const
inline

Get all group IDs this client is a member of.

◆ get_log_level()

int ivon::VoiceSessionWrapper::get_log_level ( ) const
inline

Get the current log level.

Returns
One of the IVON_LOG_LEVEL_* constants.

◆ get_remote_client_count()

size_t ivon::VoiceSessionWrapper::get_remote_client_count ( ) const
inlinenoexcept

Get the count of remote clients in the session.

◆ get_remote_client_ids()

std::vector< std::string > ivon::VoiceSessionWrapper::get_remote_client_ids ( ) const
inline

Get all remote client IDs as a vector.

◆ get_speaking_senders()

std::set< uint64_t > ivon::VoiceSessionWrapper::get_speaking_senders ( ) const
inline

Get the sender IDs of currently speaking remote senders.

◆ handle()

ivon_voice_session_t ivon::VoiceSessionWrapper::handle ( ) const
inlinenoexcept

Get the underlying opaque C handle.

◆ has_remote_client()

bool ivon::VoiceSessionWrapper::has_remote_client ( const std::string &  client_id) const
inlinenoexcept

Check if a remote client with the given ID exists.

◆ is_voice_group_joined()

bool ivon::VoiceSessionWrapper::is_voice_group_joined ( const std::string &  group_id = {}) const
inlinenoexcept

Check if a voice group has been successfully joined.

Parameters
group_idThe group to check (empty = any group).

◆ join_voice_group()

bool ivon::VoiceSessionWrapper::join_voice_group ( const std::string &  group_id)
inline

Manually join a voice group.

Use when voice_group_id was empty in the config. Returns false if not connected.

◆ leave_voice_group()

bool ivon::VoiceSessionWrapper::leave_voice_group ( const std::string &  group_id)
inline

Leave a voice group. Returns false if not connected.

Parameters
group_idThe group to leave.

◆ local_sender_id()

uint64_t ivon::VoiceSessionWrapper::local_sender_id ( ) const
inlinenoexcept

Get the local fanout sender ID (0 if not yet connected).

◆ on_client_joined()

void ivon::VoiceSessionWrapper::on_client_joined ( ClientJoinedCallback  cb)
inline

◆ on_client_left()

void ivon::VoiceSessionWrapper::on_client_left ( ClientLeftCallback  cb)
inline

◆ on_client_message()

void ivon::VoiceSessionWrapper::on_client_message ( ClientMessageCallback  cb)
inline

◆ on_connection_state_changed()

void ivon::VoiceSessionWrapper::on_connection_state_changed ( ConnectionStateCallback  cb)
inline

◆ on_disconnected()

void ivon::VoiceSessionWrapper::on_disconnected ( DisconnectedCallback  cb)
inline

◆ on_group_kicked()

void ivon::VoiceSessionWrapper::on_group_kicked ( GroupKickedCallback  cb)
inline

◆ on_group_left()

void ivon::VoiceSessionWrapper::on_group_left ( GroupLeaveCallback  cb)
inline

◆ on_group_list()

void ivon::VoiceSessionWrapper::on_group_list ( GroupListCallback  cb)
inline

◆ on_group_property_update()

void ivon::VoiceSessionWrapper::on_group_property_update ( GroupPropertyUpdateCallback  cb)
inline

◆ on_kicked()

void ivon::VoiceSessionWrapper::on_kicked ( KickedCallback  cb)
inline

Forward to client().on_kicked().

◆ on_member_joined()

void ivon::VoiceSessionWrapper::on_member_joined ( MemberJoinedCallback  cb)
inline

Set callback for when a member joins the voice group.

◆ on_member_left()

void ivon::VoiceSessionWrapper::on_member_left ( MemberLeftCallback  cb)
inline

Set callback for when a member leaves the voice group.

◆ on_password_required()

void ivon::VoiceSessionWrapper::on_password_required ( PasswordCallback  cb)
inline

◆ on_server_properties()

void ivon::VoiceSessionWrapper::on_server_properties ( ServerPropertiesCallback  cb)
inline

◆ on_server_property_update()

void ivon::VoiceSessionWrapper::on_server_property_update ( ServerPropertyUpdateCallback  cb)
inline

◆ on_speaking()

void ivon::VoiceSessionWrapper::on_speaking ( SpeakingCallback  cb)
inline

Set callback for remote speaking state changes.

◆ on_tofu_verify()

void ivon::VoiceSessionWrapper::on_tofu_verify ( TofuVerifyCallback  cb)
inline

◆ on_voice_error()

void ivon::VoiceSessionWrapper::on_voice_error ( VoiceErrorCallback  cb)
inline

Set callback for voice group runtime errors.

◆ on_voice_joined()

void ivon::VoiceSessionWrapper::on_voice_joined ( VoiceJoinedCallback  cb)
inline

Set callback for voice group join result.

◆ operator=() [1/2]

VoiceSessionWrapper & ivon::VoiceSessionWrapper::operator= ( const VoiceSessionWrapper )
delete

◆ operator=() [2/2]

VoiceSessionWrapper & ivon::VoiceSessionWrapper::operator= ( VoiceSessionWrapper &&  )
delete

◆ request_group_list()

bool ivon::VoiceSessionWrapper::request_group_list ( )
inline

Request the list of available groups from the server.

◆ send_broadcast_message()

bool ivon::VoiceSessionWrapper::send_broadcast_message ( const std::string &  type,
const std::vector< uint8_t > &  buffer 
)
inline

Broadcast a typed message to all connected clients.

◆ send_client_message()

bool ivon::VoiceSessionWrapper::send_client_message ( const std::string &  client_id,
const std::string &  type,
const std::vector< uint8_t > &  buffer 
)
inline

Send a typed message to a specific remote client.

◆ send_group_message()

bool ivon::VoiceSessionWrapper::send_group_message ( const std::string &  group_id,
const std::string &  type,
const std::vector< uint8_t > &  buffer 
)
inline

Send a typed message to all members of a group.

◆ set_log_level()

void ivon::VoiceSessionWrapper::set_log_level ( int  level)
inline

Set the runtime log level for the session's internal loggers.

Parameters
levelOne of the IVON_LOG_LEVEL_* constants (0=trace .. 6=off).

◆ set_mute()

bool ivon::VoiceSessionWrapper::set_mute ( const std::string &  group_id,
const std::string &  target_client_id,
bool  muted 
)
inline

Mute or unmute a target client in a specific group.

◆ set_pcm_source()

void ivon::VoiceSessionWrapper::set_pcm_source ( PcmSourceCallback  cb)
inline

◆ start_audio()

void ivon::VoiceSessionWrapper::start_audio ( )
inline

Start the audio processor (tick coordinator + worker threads).

◆ start_speaking()

void ivon::VoiceSessionWrapper::start_speaking ( ivon_speaking_mode_t  mode = IVON_SPEAKING_MODE_PTT)
inline

Start speaking. The PCM source callback will begin firing.

◆ stop_audio()

void ivon::VoiceSessionWrapper::stop_audio ( )
inline

Stop the audio processor.


The documentation for this class was generated from the following file: