Trait titanium::desktop::discord::DiscordIpc
pub trait DiscordIpc {
// Required method
fn close(&mut self) -> Result<(), Box<dyn Error + 'static, Global>>;
// Provided methods
fn connect(&mut self) -> Result<(), Box<dyn Error + 'static, Global>> { ... }
fn reconnect(&mut self) -> Result<(), Box<dyn Error + 'static, Global>> { ... }
fn send_handshake(&mut self) -> Result<(), Box<dyn Error + 'static, Global>> { ... }
fn send(
&mut self,
data: Value,
opcode: u8
) -> Result<(), Box<dyn Error + 'static, Global>> { ... }
fn recv(&mut self) -> Result<(u32, Value), Box<dyn Error + 'static, Global>> { ... }
fn set_activity(
&mut self,
activity_payload: Activity<'_>
) -> Result<(), Box<dyn Error + 'static, Global>> { ... }
fn clear_activity(&mut self) -> Result<(), Box<dyn Error + 'static, Global>> { ... }
}
Expand description
A client that connects to and communicates with the Discord IPC.
Implemented via the DiscordRPCClient
struct.
Required Methods§
Provided Methods§
fn connect(&mut self) -> Result<(), Box<dyn Error + 'static, Global>>
fn connect(&mut self) -> Result<(), Box<dyn Error + 'static, Global>>
Connects the client to the Discord IPC.
This method attempts to first establish a connection, and then sends a handshake.
Errors
Returns an Err
variant if the client
fails to connect to the socket, or if it fails to
send a handshake.
Examples
let mut client = discord_rich_presence::new_client("<some client id>")?;
client.connect()?;
fn reconnect(&mut self) -> Result<(), Box<dyn Error + 'static, Global>>
fn reconnect(&mut self) -> Result<(), Box<dyn Error + 'static, Global>>
Reconnects to the Discord IPC.
This method closes the client’s active connection, then re-connects it and re-sends a handshake.
Errors
Returns an Err
variant if the client
failed to connect to the socket, or if it failed to
send a handshake.
Examples
let mut client = discord_rich_presence::new_client("<some client id>")?;
client.connect()?;
client.close()?;
client.reconnect()?;
fn recv(&mut self) -> Result<(u32, Value), Box<dyn Error + 'static, Global>>
fn recv(&mut self) -> Result<(u32, Value), Box<dyn Error + 'static, Global>>
Receives an opcode and JSON data from the Discord IPC.
This method returns any data received from the IPC. It returns a tuple containing the opcode, and the JSON data.
Errors
Returns an Err
variant if reading the socket was
unsuccessful.
Examples
client.connect_ipc()?;
client.send_handshake()?;
println!("{:?}", client.recv()?);
fn set_activity(
&mut self,
activity_payload: Activity<'_>
) -> Result<(), Box<dyn Error + 'static, Global>>
fn set_activity( &mut self, activity_payload: Activity<'_> ) -> Result<(), Box<dyn Error + 'static, Global>>
fn clear_activity(&mut self) -> Result<(), Box<dyn Error + 'static, Global>>
fn clear_activity(&mut self) -> Result<(), Box<dyn Error + 'static, Global>>
Works the same as as set_activity
but clears activity instead.
Errors
Returns an Err
variant if sending the payload failed.