[][src]Struct mixer_wrappers::chat::ChatClient

pub struct ChatClient {
    pub join_handle: JoinHandle<()>,
    // some fields omitted
}

Wrapper for connecting and interacting with the chat server.

Fields

join_handle: JoinHandle<()>

Internal thread join handle

Implementations

impl ChatClient[src]

pub fn connect(
    endpoint: &str,
    client_id: &str
) -> Result<(Self, Receiver<String>), Error>
[src]

Connect to the chat server.

Per the documentation, connecting to the chat server isn't as straightforward as connecting to Constellation, as the client must first make a call to the REST API to fetch information about the chat connection, including the endpoint to connect to. This function does not handle that process; use the REST API included in this crate to get that information.

Arguments

  • endpoint - chat websocket endpoint to connect to
  • client_id - your client ID

Examples

use mixer_wrappers::ChatClient;
let (mut client, receiver) = ChatClient::connect("aaa", "bbb").unwrap();

pub fn authenticate(
    &mut self,
    channel_id: usize,
    user_id: Option<usize>,
    auth_key: Option<&str>
) -> Result<(), Error>
[src]

Authenticate with the server. This must be done after connecting.

Per the documentation, you can either authenticate anonymously, or as an actual user. The former is done by passing this function Nones for the second and third parameters.

Arguments

  • channel_id - channel to connect to, fetched from the REST API
  • user_id - Option of user to auth as
  • auth_key - Option of user key to use

Examples

if let Err(e) = client.authenticate(123, Some(456), Some("ccc")) {
    // ...
}

pub fn call_method(
    &mut self,
    method: &str,
    arguments: &[Value]
) -> Result<(), Error>
[src]

Call a method, sending data to the socket.

The arguments parameter is so dynamic because while the arguments parameter is an array, it's JSON, so there can be any number of elements in the array of different types.

Arguments

  • method - method name
  • arguments - method arguments

Examples

if let Err(e) = client.call_method("some_method", &[json!(123), json!("abc")]) {
    // ...
}

pub fn parse(message: &str) -> Result<StreamMessage, Error>[src]

Helper method to parse the JSON messages into structs.

Arguments

  • message - String message from the receiver

Examples

let message = ChatClient::parse("{\"type\":\"event\"...}").unwrap();

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Err = <U as TryFrom<T>>::Err

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,