public final class IPCClient
extends java.lang.Object
implements java.io.Closeable
The ID provided should be the client ID of the particular application providing Rich Presence, which can be found here.
When initially created using IPCClient(long)
the client will be
inactive awaiting a call to connect(DiscordBuild...)
.
After the call, this client can send and receive Rich Presence data to and
from discord via sendRichPresence(RichPresence)
and
setListener(IPCListener)
respectively.
Please be mindful that the client created is initially unconnected, and
calling any methods that exchange data between this client and Discord before
a call to connect(DiscordBuild...)
will cause an
IllegalStateException
to be thrown.
This also means that the IPCClient cannot tell whether the client ID provided
is valid or not before a handshake.
Modifier and Type | Class and Description |
---|---|
static class |
IPCClient.Event
Constants representing events that can be subscribed to using
subscribe(Event) . |
static class |
IPCClient.Status
Constants representing various status that an
IPCClient can have. |
Constructor and Description |
---|
IPCClient(long clientId)
Constructs a new IPCClient using the provided
clientId . |
Modifier and Type | Method and Description |
---|---|
void |
close()
Attempts to close an open connection to Discord.
|
void |
connect(DiscordBuild... preferredOrder)
Opens the connection between the IPCClient and Discord.
|
DiscordBuild |
getDiscordBuild()
Gets the IPCClient's
DiscordBuild . |
IPCClient.Status |
getStatus()
Gets the IPCClient's current
IPCClient.Status . |
void |
sendRichPresence(RichPresence presence)
Sends a
RichPresence to the Discord client. |
void |
sendRichPresence(RichPresence presence,
Callback callback)
Sends a
RichPresence to the Discord client. |
void |
setListener(IPCListener listener)
Sets this IPCClient's
IPCListener to handle received events. |
void |
subscribe(IPCClient.Event sub)
Adds an event
IPCClient.Event to this IPCClient. |
void |
subscribe(IPCClient.Event sub,
Callback callback)
Adds an event
IPCClient.Event to this IPCClient. |
public IPCClient(long clientId)
clientId
.clientId
- The Rich Presence application's client ID, which can be found herepublic void setListener(IPCListener listener)
IPCListener
to handle received events.
A single IPCClient can only have one of these set at any given time.
Setting this null
will remove the currently active one.
This can be set safely before a call to connect(DiscordBuild...)
is
made.
listener
- The IPCListener
to set for this IPCClient.IPCListener
public void connect(DiscordBuild... preferredOrder) throws NoDiscordClientException
This must be called before any data is exchanged between the IPCClient and Discord.
preferredOrder
- the priority order of client builds to connect tojava.lang.IllegalStateException
- There is an open connection on this IPCClient.NoDiscordClientException
- No client of the provided build type
(s) was
found.public void sendRichPresence(RichPresence presence)
RichPresence
to the Discord client.
This is where the IPCClient will officially display a Rich Presence in the Discord client.
Sending this again will overwrite the last provided RichPresence
.
presence
- The RichPresence
to send.java.lang.IllegalStateException
- If a connection was not made prior to invoking this method.RichPresence
public void sendRichPresence(RichPresence presence, Callback callback)
RichPresence
to the Discord client.
This is where the IPCClient will officially display a Rich Presence in the Discord client.
Sending this again will overwrite the last provided RichPresence
.
presence
- The RichPresence
to send.callback
- A Callback
to handle success or errorjava.lang.IllegalStateException
- If a connection was not made prior to invoking this method.RichPresence
public void subscribe(IPCClient.Event sub)
IPCClient.Event
to this IPCClient.IPCClient.Event
is added more than once, it does nothing. Once
added, there is no way to remove the subscription other than closing
the connection and creating a new one.sub
- The event IPCClient.Event
to add.java.lang.IllegalStateException
- If a connection was not made prior to invoking this method.public void subscribe(IPCClient.Event sub, Callback callback)
IPCClient.Event
to this IPCClient.IPCClient.Event
is added more than once, it does nothing. Once
added, there is no way to remove the subscription other than closing
the connection and creating a new one.sub
- The event IPCClient.Event
to add.callback
- The Callback
to handle success or failurejava.lang.IllegalStateException
- If a connection was not made prior to invoking this method.public IPCClient.Status getStatus()
IPCClient.Status
.IPCClient.Status
.public void close()
connect(DiscordBuild...)
.close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.lang.IllegalStateException
- If a connection was not made prior to invoking this method.public DiscordBuild getDiscordBuild()
DiscordBuild
.
This is always the first specified DiscordBuild when making a call to
connect(DiscordBuild...)
, or the first one found if none or
DiscordBuild.ANY
is specified.
Note that specifying ANY doesn't mean that this will return ANY. In fact this method should never return the value ANY.
DiscordBuild
of this IPCClient.