pub struct LiveChatClient { /* private fields */ }Expand description
Client for receiving live chat messages over Kick’s Pusher WebSocket.
Connects to the public Pusher channel for a chatroom and yields chat messages in real time. No authentication is required.
§Connecting
There are two ways to connect:
connect_by_username— pass a Kick username and the chatroom ID is resolved automatically (requirescurlon PATH).connect— pass a chatroom ID directly.
§Example
use kick_api::LiveChatClient;
let mut chat = LiveChatClient::connect_by_username("xqc").await?;
while let Some(msg) = chat.next_message().await? {
println!("{}: {}", msg.sender.username, msg.content);
}Implementations§
Source§impl LiveChatClient
impl LiveChatClient
Sourcepub async fn connect_by_username(username: &str) -> Result<Self>
pub async fn connect_by_username(username: &str) -> Result<Self>
Connect to a chatroom by the channel’s username/slug.
Looks up the chatroom ID via Kick’s public API and connects to the WebSocket. No authentication is required.
§Example
use kick_api::LiveChatClient;
let mut chat = LiveChatClient::connect_by_username("xqc").await?;
while let Some(msg) = chat.next_message().await? {
println!("{}: {}", msg.sender.username, msg.content);
}Sourcepub async fn connect(chatroom_id: u64) -> Result<Self>
pub async fn connect(chatroom_id: u64) -> Result<Self>
Connect to a chatroom by its ID.
Opens a WebSocket to Pusher and subscribes to the chatroom’s public channel. No authentication is required.
To find a channel’s chatroom ID, visit
https://kick.com/api/v2/channels/{slug} in a browser and look for
"chatroom":{"id":.
Sourcepub async fn next_event(&mut self) -> Result<Option<PusherEvent>>
pub async fn next_event(&mut self) -> Result<Option<PusherEvent>>
Receive the next raw Pusher event.
Returns all events from the subscribed channel (chat messages, pins,
subs, bans, etc.). Automatically handles Pusher-level pings and
internal protocol events. Returns None if the connection is closed.
Sourcepub async fn next_message(&mut self) -> Result<Option<LiveChatMessage>>
pub async fn next_message(&mut self) -> Result<Option<LiveChatMessage>>
Receive the next chat message.
Blocks until a chat message arrives. Automatically handles Pusher-level
pings and skips non-chat events. Returns None if the connection is
closed.