Package com.mewna.catnip.shard
Class CatnipShardImpl
java.lang.Object
com.mewna.catnip.shard.CatnipShardImpl
- All Implemented Interfaces:
CatnipShard
,WebSocket.Listener
A catnip shard encapsulates a single websocket connection to Discord's
real-time gateway. Shards should be deployed/undeployed by a
ShardManager
;
see DefaultShardManager
and AbstractShardManager
for more.
Shards are controlled by calling the methods exposed on the CatnipShard
;
it is NOT recommended that you store a reference to a shard object; and instead
poll the ShardManager
for the shard when needed.- Since:
- 8/31/18.
- Author:
- amy
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic com.grack.nanojson.JsonObject
basePayload
(GatewayOp op) static com.grack.nanojson.JsonObject
basePayload
(GatewayOp op, com.grack.nanojson.JsonObject payload) static com.grack.nanojson.JsonObject
basePayload
(GatewayOp op, Integer payload) io.reactivex.rxjava3.core.Single<ShardConnectState>
connect()
void
boolean
Checks whether or not the current shard is currently connected to the websocket gateway.long
Return the shard's computed gateway latency, ie.Get the lifecycle state for the current shard.onBinary
(WebSocket webSocket, ByteBuffer data, boolean last) void
void
onText
(WebSocket webSocket, CharSequence data, boolean last) presence()
Return the shard's current presence.void
queueSendToSocket
(com.grack.nanojson.JsonObject payload) void
queueVoiceStateUpdate
(com.grack.nanojson.JsonObject json) void
sendToSocket
(com.grack.nanojson.JsonObject payload) trace()
Fetches the trace from the shard.void
updatePresence
(PresenceImpl presence) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.net.http.WebSocket.Listener
onPing, onPong
-
Field Details
-
ZLIB_SUFFIX
public static final int ZLIB_SUFFIX- See Also:
-
-
Constructor Details
-
CatnipShardImpl
-
-
Method Details
-
basePayload
-
basePayload
public static com.grack.nanojson.JsonObject basePayload(@Nonnull GatewayOp op, @Nullable com.grack.nanojson.JsonObject payload) -
basePayload
-
onOpen
- Specified by:
onOpen
in interfaceWebSocket.Listener
-
onText
- Specified by:
onText
in interfaceWebSocket.Listener
-
onBinary
- Specified by:
onBinary
in interfaceWebSocket.Listener
-
onError
- Specified by:
onError
in interfaceWebSocket.Listener
-
onClose
- Specified by:
onClose
in interfaceWebSocket.Listener
-
isConnected
public boolean isConnected()Description copied from interface:CatnipShard
Checks whether or not the current shard is currently connected to the websocket gateway. This is done as a boolean because - at least for now - there's only 2 meaningful states: connected, and queued to be connected.- Specified by:
isConnected
in interfaceCatnipShard
- Returns:
- Whether or not the shard with the given id is currently connected to the websocket gateway.
-
lastHeartbeatLatency
public long lastHeartbeatLatency()Description copied from interface:CatnipShard
Return the shard's computed gateway latency, ie. the time it takes for the shard to send a heartbeat to Discord and get a response.- Specified by:
lastHeartbeatLatency
in interfaceCatnipShard
- Returns:
- The shard's computed gateway latency.
-
connect
- Specified by:
connect
in interfaceCatnipShard
-
disconnect
public void disconnect()- Specified by:
disconnect
in interfaceCatnipShard
-
queueSendToSocket
public void queueSendToSocket(@Nonnull com.grack.nanojson.JsonObject payload) - Specified by:
queueSendToSocket
in interfaceCatnipShard
-
sendToSocket
public void sendToSocket(@Nonnull com.grack.nanojson.JsonObject payload) - Specified by:
sendToSocket
in interfaceCatnipShard
-
updatePresence
- Specified by:
updatePresence
in interfaceCatnipShard
-
presence
Description copied from interface:CatnipShard
Return the shard's current presence.- Specified by:
presence
in interfaceCatnipShard
- Returns:
- The shard's current presence.
-
queueVoiceStateUpdate
public void queueVoiceStateUpdate(@Nonnull com.grack.nanojson.JsonObject json) - Specified by:
queueVoiceStateUpdate
in interfaceCatnipShard
-
shardInfo
-
trace
Description copied from interface:CatnipShard
Fetches the trace from the shard.- Specified by:
trace
in interfaceCatnipShard
- Returns:
- The shard's trace.
-
lifecycleState
Description copied from interface:CatnipShard
Get the lifecycle state for the current shard. This provides more meaningful info thanCatnipShard.isConnected()
, because it provides more granular info about the shard's state. However, it does not differentiate between "connected" or not per se; it is up to the end-user to determine whether or not the lifecycle state is actually a state of being "connected."- Specified by:
lifecycleState
in interfaceCatnipShard
- Returns:
- The lifecycle state of the shard.
-