diff --git a/crates/teamtalk/src/client/hooks/builders.rs b/crates/teamtalk/src/client/hooks/builders.rs deleted file mode 100644 index bc484f6..0000000 --- a/crates/teamtalk/src/client/hooks/builders.rs +++ /dev/null @@ -1,574 +0,0 @@ -use super::ClientHooks; -use crate::client::{Client, Message}; -use crate::events::Event; -use crate::types::{ChannelId, TextMessage, User}; - -impl ClientHooks { - /// Registers a handler for every event. - #[must_use] - pub fn on_event(mut self, hook: impl FnMut(&Client, Event, &Message) + Send + 'static) -> Self { - self.on_event = Some(Box::new(hook)); - self - } - - /// Registers a handler for successful connections. - #[must_use] - pub fn on_connect_success(mut self, hook: impl FnMut(&Client) + Send + 'static) -> Self { - self.on_connect_success = Some(Box::new(hook)); - self - } - - /// Registers a handler for failed connections. - #[must_use] - pub fn on_connect_failed(mut self, hook: impl FnMut(&Client) + Send + 'static) -> Self { - self.on_connect_failed = Some(Box::new(hook)); - self - } - - /// Registers a handler for connection encryption errors. - #[must_use] - pub fn on_connect_crypt_error(mut self, hook: impl FnMut(&Client) + Send + 'static) -> Self { - self.on_connect_crypt_error = Some(Box::new(hook)); - self - } - - /// Registers a handler for max payload updates. - #[must_use] - pub fn on_connect_max_payload_updated( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_connect_max_payload_updated = Some(Box::new(hook)); - self - } - - /// Registers a handler for connection loss. - #[must_use] - pub fn on_connection_lost(mut self, hook: impl FnMut(&Client) + Send + 'static) -> Self { - self.on_connection_lost = Some(Box::new(hook)); - self - } - - /// Registers a handler for command processing notifications. - #[must_use] - pub fn on_cmd_processing( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_cmd_processing = Some(Box::new(hook)); - self - } - - /// Registers a handler for command errors. - #[must_use] - pub fn on_cmd_error(mut self, hook: impl FnMut(&Client, &Message) + Send + 'static) -> Self { - self.on_cmd_error = Some(Box::new(hook)); - self - } - - /// Registers a handler for command success notifications. - #[must_use] - pub fn on_cmd_success(mut self, hook: impl FnMut(&Client, &Message) + Send + 'static) -> Self { - self.on_cmd_success = Some(Box::new(hook)); - self - } - - /// Registers a handler for successful login. - #[must_use] - pub fn on_logged_in(mut self, hook: impl FnMut(&Client) + Send + 'static) -> Self { - self.on_logged_in = Some(Box::new(hook)); - self - } - - /// Registers a handler for logout. - #[must_use] - pub fn on_logged_out(mut self, hook: impl FnMut(&Client) + Send + 'static) -> Self { - self.on_logged_out = Some(Box::new(hook)); - self - } - - /// Registers a handler for being kicked. - #[must_use] - pub fn on_myself_kicked( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_myself_kicked = Some(Box::new(hook)); - self - } - - /// Registers a handler for user login events. - #[must_use] - pub fn on_user_logged_in(mut self, hook: impl FnMut(&Client, User) + Send + 'static) -> Self { - self.on_user_logged_in = Some(Box::new(hook)); - self - } - - /// Registers a handler for user logout events. - #[must_use] - pub fn on_user_logged_out(mut self, hook: impl FnMut(&Client, User) + Send + 'static) -> Self { - self.on_user_logged_out = Some(Box::new(hook)); - self - } - - /// Registers a handler for user updates. - #[must_use] - pub fn on_user_update(mut self, hook: impl FnMut(&Client, User) + Send + 'static) -> Self { - self.on_user_update = Some(Box::new(hook)); - self - } - - /// Registers a handler for channel joins. - #[must_use] - pub fn on_joined(mut self, hook: impl FnMut(&Client, ChannelId) + Send + 'static) -> Self { - self.on_joined = Some(Box::new(hook)); - self - } - - /// Registers a handler for any user join event. - #[must_use] - pub fn on_user_joined(mut self, hook: impl FnMut(&Client, User) + Send + 'static) -> Self { - self.on_user_joined = Some(Box::new(hook)); - self - } - - /// Registers a handler for any user leave event. - #[must_use] - pub fn on_user_left(mut self, hook: impl FnMut(&Client, User) + Send + 'static) -> Self { - self.on_user_left = Some(Box::new(hook)); - self - } - - /// Registers a handler for channel or user text messages. - #[must_use] - pub fn on_text_message( - mut self, - hook: impl FnMut(&Client, TextMessage) + Send + 'static, - ) -> Self { - self.on_text_message = Some(Box::new(hook)); - self - } - - /// Registers a handler for channel creation events. - #[must_use] - pub fn on_channel_created( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_channel_created = Some(Box::new(hook)); - self - } - - /// Registers a handler for channel update events. - #[must_use] - pub fn on_channel_updated( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_channel_updated = Some(Box::new(hook)); - self - } - - /// Registers a handler for channel removal events. - #[must_use] - pub fn on_channel_removed( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_channel_removed = Some(Box::new(hook)); - self - } - - /// Registers a handler for server updates. - #[must_use] - pub fn on_server_update( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_server_update = Some(Box::new(hook)); - self - } - - /// Registers a handler for server statistics updates. - #[must_use] - pub fn on_server_statistics( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_server_statistics = Some(Box::new(hook)); - self - } - - /// Registers a handler for new file events. - #[must_use] - pub fn on_file_new(mut self, hook: impl FnMut(&Client, &Message) + Send + 'static) -> Self { - self.on_file_new = Some(Box::new(hook)); - self - } - - /// Registers a handler for file removal events. - #[must_use] - pub fn on_file_remove(mut self, hook: impl FnMut(&Client, &Message) + Send + 'static) -> Self { - self.on_file_remove = Some(Box::new(hook)); - self - } - - /// Registers a handler for user account events. - #[must_use] - pub fn on_user_account(mut self, hook: impl FnMut(&Client, &Message) + Send + 'static) -> Self { - self.on_user_account = Some(Box::new(hook)); - self - } - - /// Registers a handler for banned user events. - #[must_use] - pub fn on_banned_user(mut self, hook: impl FnMut(&Client, &Message) + Send + 'static) -> Self { - self.on_banned_user = Some(Box::new(hook)); - self - } - - /// Registers a handler for user account creation events. - #[must_use] - pub fn on_user_account_created( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_user_account_created = Some(Box::new(hook)); - self - } - - /// Registers a handler for user account removal events. - #[must_use] - pub fn on_user_account_removed( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_user_account_removed = Some(Box::new(hook)); - self - } - - /// Registers a handler for user state changes. - #[must_use] - pub fn on_user_state_change( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_user_state_change = Some(Box::new(hook)); - self - } - - /// Registers a handler for video capture frames. - #[must_use] - pub fn on_video_capture_frame( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_video_capture_frame = Some(Box::new(hook)); - self - } - - /// Registers a handler for media file video frames. - #[must_use] - pub fn on_media_file_video( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_media_file_video = Some(Box::new(hook)); - self - } - - /// Registers a handler for desktop window updates. - #[must_use] - pub fn on_desktop_window( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_desktop_window = Some(Box::new(hook)); - self - } - - /// Registers a handler for desktop cursor updates. - #[must_use] - pub fn on_desktop_cursor( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_desktop_cursor = Some(Box::new(hook)); - self - } - - /// Registers a handler for desktop input updates. - #[must_use] - pub fn on_desktop_input( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_desktop_input = Some(Box::new(hook)); - self - } - - /// Registers a handler for recorded media file events. - #[must_use] - pub fn on_user_record_media_file( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_user_record_media_file = Some(Box::new(hook)); - self - } - - /// Registers a handler for audio block events. - #[must_use] - pub fn on_audio_block(mut self, hook: impl FnMut(&Client, &Message) + Send + 'static) -> Self { - self.on_audio_block = Some(Box::new(hook)); - self - } - - /// Registers a handler for internal error events. - #[must_use] - pub fn on_internal_error( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_internal_error = Some(Box::new(hook)); - self - } - - /// Registers a handler for voice activation events. - #[must_use] - pub fn on_voice_activation( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_voice_activation = Some(Box::new(hook)); - self - } - - /// Registers a handler for hotkey events. - #[must_use] - pub fn on_hotkey(mut self, hook: impl FnMut(&Client, &Message) + Send + 'static) -> Self { - self.on_hotkey = Some(Box::new(hook)); - self - } - - /// Registers a handler for hotkey test events. - #[must_use] - pub fn on_hotkey_test(mut self, hook: impl FnMut(&Client, &Message) + Send + 'static) -> Self { - self.on_hotkey_test = Some(Box::new(hook)); - self - } - - /// Registers a handler for file transfer events. - #[must_use] - pub fn on_file_transfer( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_file_transfer = Some(Box::new(hook)); - self - } - - /// Registers a handler for desktop window transfer events. - #[must_use] - pub fn on_desktop_window_transfer( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_desktop_window_transfer = Some(Box::new(hook)); - self - } - - /// Registers a handler for stream media file events. - #[must_use] - pub fn on_stream_media_file( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_stream_media_file = Some(Box::new(hook)); - self - } - - /// Registers a handler for local media file events. - #[must_use] - pub fn on_local_media_file( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_local_media_file = Some(Box::new(hook)); - self - } - - /// Registers a handler for audio input events. - #[must_use] - pub fn on_audio_input(mut self, hook: impl FnMut(&Client, &Message) + Send + 'static) -> Self { - self.on_audio_input = Some(Box::new(hook)); - self - } - - /// Registers a handler for first voice stream packet events. - #[must_use] - pub fn on_user_first_voice_stream_packet( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_user_first_voice_stream_packet = Some(Box::new(hook)); - self - } - - /// Registers a handler for sound device added events. - #[must_use] - pub fn on_sound_device_added( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_sound_device_added = Some(Box::new(hook)); - self - } - - /// Registers a handler for sound device removed events. - #[must_use] - pub fn on_sound_device_removed( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_sound_device_removed = Some(Box::new(hook)); - self - } - - /// Registers a handler for sound device unplugged events. - #[must_use] - pub fn on_sound_device_unplugged( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_sound_device_unplugged = Some(Box::new(hook)); - self - } - - /// Registers a handler for default sound input device changes. - #[must_use] - pub fn on_sound_device_new_default_input( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_sound_device_new_default_input = Some(Box::new(hook)); - self - } - - /// Registers a handler for default sound output device changes. - #[must_use] - pub fn on_sound_device_new_default_output( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_sound_device_new_default_output = Some(Box::new(hook)); - self - } - - /// Registers a handler for default sound input communications device changes. - #[must_use] - pub fn on_sound_device_new_default_input_com_device( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_sound_device_new_default_input_com_device = Some(Box::new(hook)); - self - } - - /// Registers a handler for default sound output communications device changes. - #[must_use] - pub fn on_sound_device_new_default_output_com_device( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_sound_device_new_default_output_com_device = Some(Box::new(hook)); - self - } - - /// Registers a handler for reconnecting notifications. - #[must_use] - pub fn on_reconnecting(mut self, hook: impl FnMut(&Client, &Message) + Send + 'static) -> Self { - self.on_reconnecting = Some(Box::new(hook)); - self - } - - /// Registers a handler before an automatic reconnect attempt. - #[must_use] - pub fn on_before_reconnect( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_before_reconnect = Some(Box::new(hook)); - self - } - - /// Registers a handler after an automatic reconnect succeeds. - #[must_use] - pub fn on_after_reconnect( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_after_reconnect = Some(Box::new(hook)); - self - } - - /// Registers a handler when automatic reconnect gives up. - #[must_use] - pub fn on_reconnect_failed( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_reconnect_failed = Some(Box::new(hook)); - self - } - - /// Registers a handler before an automatic login retry. - #[must_use] - pub fn on_before_auto_login( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_before_auto_login = Some(Box::new(hook)); - self - } - - /// Registers a handler when automatic login gives up. - #[must_use] - pub fn on_auto_login_failed( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_auto_login_failed = Some(Box::new(hook)); - self - } - - /// Registers a handler before an automatic join retry. - #[must_use] - pub fn on_before_auto_join( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_before_auto_join = Some(Box::new(hook)); - self - } - - /// Registers a handler when automatic join gives up. - #[must_use] - pub fn on_auto_join_failed( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_auto_join_failed = Some(Box::new(hook)); - self - } - - /// Registers a handler after full in-session recovery reaches Joined. - #[must_use] - pub fn on_auto_recover_completed( - mut self, - hook: impl FnMut(&Client, &Message) + Send + 'static, - ) -> Self { - self.on_auto_recover_completed = Some(Box::new(hook)); - self - } -} diff --git a/crates/teamtalk/src/client/hooks/builders/connection.rs b/crates/teamtalk/src/client/hooks/builders/connection.rs new file mode 100644 index 0000000..bd1b8f4 --- /dev/null +++ b/crates/teamtalk/src/client/hooks/builders/connection.rs @@ -0,0 +1,73 @@ +//! Hook registrations for connection- and command-lifecycle events. +//! +//! Events in this module are emitted by the TeamTalk SDK while the +//! client is establishing, maintaining, or losing a connection, and +//! for command-processing notifications that are not tied to a +//! specific command result. + +use crate::client::hooks::ClientHooks; +use crate::client::{Client, Message}; + +impl ClientHooks { + /// Registers a handler for successful connections. + #[must_use] + pub fn on_connect_success(mut self, hook: impl FnMut(&Client) + Send + 'static) -> Self { + self.on_connect_success = Some(Box::new(hook)); + self + } + + /// Registers a handler for failed connections. + #[must_use] + pub fn on_connect_failed(mut self, hook: impl FnMut(&Client) + Send + 'static) -> Self { + self.on_connect_failed = Some(Box::new(hook)); + self + } + + /// Registers a handler for connection encryption errors. + #[must_use] + pub fn on_connect_crypt_error(mut self, hook: impl FnMut(&Client) + Send + 'static) -> Self { + self.on_connect_crypt_error = Some(Box::new(hook)); + self + } + + /// Registers a handler for max payload updates. + #[must_use] + pub fn on_connect_max_payload_updated( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_connect_max_payload_updated = Some(Box::new(hook)); + self + } + + /// Registers a handler for connection loss. + #[must_use] + pub fn on_connection_lost(mut self, hook: impl FnMut(&Client) + Send + 'static) -> Self { + self.on_connection_lost = Some(Box::new(hook)); + self + } + + /// Registers a handler for command processing notifications. + #[must_use] + pub fn on_cmd_processing( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_cmd_processing = Some(Box::new(hook)); + self + } + + /// Registers a handler for command errors. + #[must_use] + pub fn on_cmd_error(mut self, hook: impl FnMut(&Client, &Message) + Send + 'static) -> Self { + self.on_cmd_error = Some(Box::new(hook)); + self + } + + /// Registers a handler for command success notifications. + #[must_use] + pub fn on_cmd_success(mut self, hook: impl FnMut(&Client, &Message) + Send + 'static) -> Self { + self.on_cmd_success = Some(Box::new(hook)); + self + } +} diff --git a/crates/teamtalk/src/client/hooks/builders/directory.rs b/crates/teamtalk/src/client/hooks/builders/directory.rs new file mode 100644 index 0000000..ac6f179 --- /dev/null +++ b/crates/teamtalk/src/client/hooks/builders/directory.rs @@ -0,0 +1,106 @@ +//! Hook registrations for channel, server, file, account, and ban +//! directory mutations (the "slow-changing state" events delivered +//! after login). + +use crate::client::hooks::ClientHooks; +use crate::client::{Client, Message}; + +impl ClientHooks { + /// Registers a handler for channel creation events. + #[must_use] + pub fn on_channel_created( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_channel_created = Some(Box::new(hook)); + self + } + + /// Registers a handler for channel update events. + #[must_use] + pub fn on_channel_updated( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_channel_updated = Some(Box::new(hook)); + self + } + + /// Registers a handler for channel removal events. + #[must_use] + pub fn on_channel_removed( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_channel_removed = Some(Box::new(hook)); + self + } + + /// Registers a handler for server updates. + #[must_use] + pub fn on_server_update( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_server_update = Some(Box::new(hook)); + self + } + + /// Registers a handler for server statistics updates. + #[must_use] + pub fn on_server_statistics( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_server_statistics = Some(Box::new(hook)); + self + } + + /// Registers a handler for new file events. + #[must_use] + pub fn on_file_new(mut self, hook: impl FnMut(&Client, &Message) + Send + 'static) -> Self { + self.on_file_new = Some(Box::new(hook)); + self + } + + /// Registers a handler for file removal events. + #[must_use] + pub fn on_file_remove(mut self, hook: impl FnMut(&Client, &Message) + Send + 'static) -> Self { + self.on_file_remove = Some(Box::new(hook)); + self + } + + /// Registers a handler for user account events. + #[must_use] + pub fn on_user_account(mut self, hook: impl FnMut(&Client, &Message) + Send + 'static) -> Self { + self.on_user_account = Some(Box::new(hook)); + self + } + + /// Registers a handler for banned user events. + #[must_use] + pub fn on_banned_user(mut self, hook: impl FnMut(&Client, &Message) + Send + 'static) -> Self { + self.on_banned_user = Some(Box::new(hook)); + self + } + + /// Registers a handler for user account creation events. + #[must_use] + pub fn on_user_account_created( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_user_account_created = Some(Box::new(hook)); + self + } + + /// Registers a handler for user account removal events. + #[must_use] + pub fn on_user_account_removed( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_user_account_removed = Some(Box::new(hook)); + self + } +} diff --git a/crates/teamtalk/src/client/hooks/builders/media.rs b/crates/teamtalk/src/client/hooks/builders/media.rs new file mode 100644 index 0000000..87792ad --- /dev/null +++ b/crates/teamtalk/src/client/hooks/builders/media.rs @@ -0,0 +1,225 @@ +//! Hook registrations for audio/video/desktop media events, transfer +//! events, and voice-activation / hotkey events. + +use crate::client::hooks::ClientHooks; +use crate::client::{Client, Message}; + +impl ClientHooks { + /// Registers a handler for video capture frames. + #[must_use] + pub fn on_video_capture_frame( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_video_capture_frame = Some(Box::new(hook)); + self + } + + /// Registers a handler for media file video frames. + #[must_use] + pub fn on_media_file_video( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_media_file_video = Some(Box::new(hook)); + self + } + + /// Registers a handler for desktop window updates. + #[must_use] + pub fn on_desktop_window( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_desktop_window = Some(Box::new(hook)); + self + } + + /// Registers a handler for desktop cursor updates. + #[must_use] + pub fn on_desktop_cursor( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_desktop_cursor = Some(Box::new(hook)); + self + } + + /// Registers a handler for desktop input updates. + #[must_use] + pub fn on_desktop_input( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_desktop_input = Some(Box::new(hook)); + self + } + + /// Registers a handler for recorded media file events. + #[must_use] + pub fn on_user_record_media_file( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_user_record_media_file = Some(Box::new(hook)); + self + } + + /// Registers a handler for audio block events. + #[must_use] + pub fn on_audio_block(mut self, hook: impl FnMut(&Client, &Message) + Send + 'static) -> Self { + self.on_audio_block = Some(Box::new(hook)); + self + } + + /// Registers a handler for voice activation events. + #[must_use] + pub fn on_voice_activation( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_voice_activation = Some(Box::new(hook)); + self + } + + /// Registers a handler for hotkey events. + #[must_use] + pub fn on_hotkey(mut self, hook: impl FnMut(&Client, &Message) + Send + 'static) -> Self { + self.on_hotkey = Some(Box::new(hook)); + self + } + + /// Registers a handler for hotkey test events. + #[must_use] + pub fn on_hotkey_test(mut self, hook: impl FnMut(&Client, &Message) + Send + 'static) -> Self { + self.on_hotkey_test = Some(Box::new(hook)); + self + } + + /// Registers a handler for file transfer events. + #[must_use] + pub fn on_file_transfer( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_file_transfer = Some(Box::new(hook)); + self + } + + /// Registers a handler for desktop window transfer events. + #[must_use] + pub fn on_desktop_window_transfer( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_desktop_window_transfer = Some(Box::new(hook)); + self + } + + /// Registers a handler for stream media file events. + #[must_use] + pub fn on_stream_media_file( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_stream_media_file = Some(Box::new(hook)); + self + } + + /// Registers a handler for local media file events. + #[must_use] + pub fn on_local_media_file( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_local_media_file = Some(Box::new(hook)); + self + } + + /// Registers a handler for audio input events. + #[must_use] + pub fn on_audio_input(mut self, hook: impl FnMut(&Client, &Message) + Send + 'static) -> Self { + self.on_audio_input = Some(Box::new(hook)); + self + } + + /// Registers a handler for first voice stream packet events. + #[must_use] + pub fn on_user_first_voice_stream_packet( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_user_first_voice_stream_packet = Some(Box::new(hook)); + self + } + + /// Registers a handler for sound device added events. + #[must_use] + pub fn on_sound_device_added( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_sound_device_added = Some(Box::new(hook)); + self + } + + /// Registers a handler for sound device removed events. + #[must_use] + pub fn on_sound_device_removed( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_sound_device_removed = Some(Box::new(hook)); + self + } + + /// Registers a handler for sound device unplugged events. + #[must_use] + pub fn on_sound_device_unplugged( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_sound_device_unplugged = Some(Box::new(hook)); + self + } + + /// Registers a handler for default sound input device changes. + #[must_use] + pub fn on_sound_device_new_default_input( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_sound_device_new_default_input = Some(Box::new(hook)); + self + } + + /// Registers a handler for default sound output device changes. + #[must_use] + pub fn on_sound_device_new_default_output( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_sound_device_new_default_output = Some(Box::new(hook)); + self + } + + /// Registers a handler for default sound input communications device changes. + #[must_use] + pub fn on_sound_device_new_default_input_com_device( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_sound_device_new_default_input_com_device = Some(Box::new(hook)); + self + } + + /// Registers a handler for default sound output communications device changes. + #[must_use] + pub fn on_sound_device_new_default_output_com_device( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_sound_device_new_default_output_com_device = Some(Box::new(hook)); + self + } +} diff --git a/crates/teamtalk/src/client/hooks/builders/mod.rs b/crates/teamtalk/src/client/hooks/builders/mod.rs new file mode 100644 index 0000000..86410d2 --- /dev/null +++ b/crates/teamtalk/src/client/hooks/builders/mod.rs @@ -0,0 +1,43 @@ +//! Hook registration builders split by event category. +//! +//! All submodules add `impl ClientHooks` methods to the single +//! [`ClientHooks`] struct defined in the parent module. Each +//! `on_*` method follows the same pattern: take `mut self`, box the +//! provided closure, store it under the matching optional field, and +//! return `self` for chaining. +//! +//! The file was previously a single 574-line monolith; splitting by +//! event category makes it easier to find a hook for a given +//! subsystem (connection vs session vs directory vs media vs +//! reconnect) and shortens each file well under the ~400-600 line +//! budget in `AGENTS.md`. +//! +//! External callers continue to use the builders through the same +//! `ClientHooks::new().on_*(...)` chain; there are no new public +//! items and no re-exports are necessary. +//! +//! [`ClientHooks`]: super::ClientHooks + +mod connection; +mod directory; +mod media; +mod reconnect; +mod session; + +use super::ClientHooks; +use crate::client::{Client, Message}; +use crate::events::Event; + +impl ClientHooks { + /// Registers a handler for every event. + /// + /// This is a catch-all hook invoked for every [`Event`] after any + /// event-specific hook has run. It is intentionally kept in the + /// top-level `builders/mod.rs` rather than under any subcategory + /// because it does not correspond to a specific TeamTalk event. + #[must_use] + pub fn on_event(mut self, hook: impl FnMut(&Client, Event, &Message) + Send + 'static) -> Self { + self.on_event = Some(Box::new(hook)); + self + } +} diff --git a/crates/teamtalk/src/client/hooks/builders/reconnect.rs b/crates/teamtalk/src/client/hooks/builders/reconnect.rs new file mode 100644 index 0000000..34ee255 --- /dev/null +++ b/crates/teamtalk/src/client/hooks/builders/reconnect.rs @@ -0,0 +1,104 @@ +//! Hook registrations for the automatic reconnect / auto-login / +//! auto-join recovery pipeline and for internal SDK errors. + +use crate::client::hooks::ClientHooks; +use crate::client::{Client, Message}; + +impl ClientHooks { + /// Registers a handler for internal error events. + #[must_use] + pub fn on_internal_error( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_internal_error = Some(Box::new(hook)); + self + } + + /// Registers a handler for reconnecting notifications. + #[must_use] + pub fn on_reconnecting(mut self, hook: impl FnMut(&Client, &Message) + Send + 'static) -> Self { + self.on_reconnecting = Some(Box::new(hook)); + self + } + + /// Registers a handler before an automatic reconnect attempt. + #[must_use] + pub fn on_before_reconnect( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_before_reconnect = Some(Box::new(hook)); + self + } + + /// Registers a handler after an automatic reconnect succeeds. + #[must_use] + pub fn on_after_reconnect( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_after_reconnect = Some(Box::new(hook)); + self + } + + /// Registers a handler when automatic reconnect gives up. + #[must_use] + pub fn on_reconnect_failed( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_reconnect_failed = Some(Box::new(hook)); + self + } + + /// Registers a handler before an automatic login retry. + #[must_use] + pub fn on_before_auto_login( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_before_auto_login = Some(Box::new(hook)); + self + } + + /// Registers a handler when automatic login gives up. + #[must_use] + pub fn on_auto_login_failed( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_auto_login_failed = Some(Box::new(hook)); + self + } + + /// Registers a handler before an automatic join retry. + #[must_use] + pub fn on_before_auto_join( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_before_auto_join = Some(Box::new(hook)); + self + } + + /// Registers a handler when automatic join gives up. + #[must_use] + pub fn on_auto_join_failed( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_auto_join_failed = Some(Box::new(hook)); + self + } + + /// Registers a handler after full in-session recovery reaches Joined. + #[must_use] + pub fn on_auto_recover_completed( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_auto_recover_completed = Some(Box::new(hook)); + self + } +} diff --git a/crates/teamtalk/src/client/hooks/builders/session.rs b/crates/teamtalk/src/client/hooks/builders/session.rs new file mode 100644 index 0000000..6476a34 --- /dev/null +++ b/crates/teamtalk/src/client/hooks/builders/session.rs @@ -0,0 +1,94 @@ +//! Hook registrations for session-lifecycle, user-presence, and +//! text-message events. + +use crate::client::hooks::ClientHooks; +use crate::client::{Client, Message}; +use crate::types::{ChannelId, TextMessage, User}; + +impl ClientHooks { + /// Registers a handler for successful login. + #[must_use] + pub fn on_logged_in(mut self, hook: impl FnMut(&Client) + Send + 'static) -> Self { + self.on_logged_in = Some(Box::new(hook)); + self + } + + /// Registers a handler for logout. + #[must_use] + pub fn on_logged_out(mut self, hook: impl FnMut(&Client) + Send + 'static) -> Self { + self.on_logged_out = Some(Box::new(hook)); + self + } + + /// Registers a handler for being kicked. + #[must_use] + pub fn on_myself_kicked( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_myself_kicked = Some(Box::new(hook)); + self + } + + /// Registers a handler for user login events. + #[must_use] + pub fn on_user_logged_in(mut self, hook: impl FnMut(&Client, User) + Send + 'static) -> Self { + self.on_user_logged_in = Some(Box::new(hook)); + self + } + + /// Registers a handler for user logout events. + #[must_use] + pub fn on_user_logged_out(mut self, hook: impl FnMut(&Client, User) + Send + 'static) -> Self { + self.on_user_logged_out = Some(Box::new(hook)); + self + } + + /// Registers a handler for user updates. + #[must_use] + pub fn on_user_update(mut self, hook: impl FnMut(&Client, User) + Send + 'static) -> Self { + self.on_user_update = Some(Box::new(hook)); + self + } + + /// Registers a handler for channel joins. + #[must_use] + pub fn on_joined(mut self, hook: impl FnMut(&Client, ChannelId) + Send + 'static) -> Self { + self.on_joined = Some(Box::new(hook)); + self + } + + /// Registers a handler for any user join event. + #[must_use] + pub fn on_user_joined(mut self, hook: impl FnMut(&Client, User) + Send + 'static) -> Self { + self.on_user_joined = Some(Box::new(hook)); + self + } + + /// Registers a handler for any user leave event. + #[must_use] + pub fn on_user_left(mut self, hook: impl FnMut(&Client, User) + Send + 'static) -> Self { + self.on_user_left = Some(Box::new(hook)); + self + } + + /// Registers a handler for channel or user text messages. + #[must_use] + pub fn on_text_message( + mut self, + hook: impl FnMut(&Client, TextMessage) + Send + 'static, + ) -> Self { + self.on_text_message = Some(Box::new(hook)); + self + } + + /// Registers a handler for user state changes. + #[must_use] + pub fn on_user_state_change( + mut self, + hook: impl FnMut(&Client, &Message) + Send + 'static, + ) -> Self { + self.on_user_state_change = Some(Box::new(hook)); + self + } +}