Package org.javacord.core.util.gateway
Class DiscordWebSocketAdapter
- java.lang.Object
-
- com.neovisionaries.ws.client.WebSocketAdapter
-
- org.javacord.core.util.gateway.DiscordWebSocketAdapter
-
- All Implemented Interfaces:
com.neovisionaries.ws.client.WebSocketListener
public class DiscordWebSocketAdapter extends com.neovisionaries.ws.client.WebSocketAdapter
The main websocket adapter.
-
-
Constructor Summary
Constructors Constructor Description DiscordWebSocketAdapter(DiscordApiImpl api)
Creates a new discord websocket adapter.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
disconnect()
Disconnects from the websocket.com.neovisionaries.ws.client.WebSocket
getWebSocket()
Gets the websocket of the adapter.void
handleCallbackError(com.neovisionaries.ws.client.WebSocket websocket, java.lang.Throwable cause)
java.util.concurrent.CompletableFuture<java.lang.Boolean>
isReady()
Gets the Future which tells whether the connection is ready or failed.void
onBinaryMessage(com.neovisionaries.ws.client.WebSocket websocket, byte[] binary)
void
onConnectError(com.neovisionaries.ws.client.WebSocket websocket, com.neovisionaries.ws.client.WebSocketException exception)
void
onDisconnected(com.neovisionaries.ws.client.WebSocket websocket, com.neovisionaries.ws.client.WebSocketFrame serverCloseFrame, com.neovisionaries.ws.client.WebSocketFrame clientCloseFrame, boolean closedByServer)
void
onError(com.neovisionaries.ws.client.WebSocket websocket, com.neovisionaries.ws.client.WebSocketException cause)
void
onTextMessage(com.neovisionaries.ws.client.WebSocket websocket, java.lang.String text)
void
onUnexpectedError(com.neovisionaries.ws.client.WebSocket websocket, com.neovisionaries.ws.client.WebSocketException cause)
void
queueRequestGuildMembers(Server server)
Adds a server id to be queued for the "request guild members" packet.void
sendCloseFrame(int closeCode)
Send a close frame with the given close code after ratelimit allows.void
sendCloseFrame(int closeCode, java.lang.String reason)
Send a close frame with the given close code and reason after ratelimit allows.void
sendCloseFrame(com.neovisionaries.ws.client.WebSocket webSocket, int closeCode)
Send a close frame over the given web socket with the given close code after ratelimit allows.void
sendCloseFrame(com.neovisionaries.ws.client.WebSocket webSocket, int closeCode, java.lang.String reason)
Send a close frame over the given web socket with the given close code and reason after ratelimit allows.void
sendFrame(com.neovisionaries.ws.client.WebSocketFrame frame)
Send the given web socket frame after ratelimit allows.void
sendLifecycleFrame(com.neovisionaries.ws.client.WebSocketFrame frame)
Send the given lifecycle web socket frame after ratelimit allows.void
sendLifecycleFrame(com.neovisionaries.ws.client.WebSocket webSocket, com.neovisionaries.ws.client.WebSocketFrame frame)
Send the given lifecycle web socket frame over the given web socket after ratelimit allows.void
sendLifecycleTextFrame(com.neovisionaries.ws.client.WebSocket webSocket, java.lang.String message)
Send a lifecycle text frame over the given web socket with the given message after ratelimit allows.void
sendLifecycleTextFrame(java.lang.String message)
Send a lifecycle text frame with the given message after ratelimit allows.void
sendTextFrame(java.lang.String message)
Send a text frame with the given message after ratelimit allows.void
sendVoiceStateUpdate(Server server, ServerVoiceChannel channel, java.lang.Boolean selfMuted, java.lang.Boolean selfDeafened)
Sends the voice state update packet.static void
setGateway(java.lang.String gateway)
Sets the gateway used to connect.void
updateStatus()
Sends the update status packet.-
Methods inherited from class com.neovisionaries.ws.client.WebSocketAdapter
onBinaryFrame, onCloseFrame, onConnected, onContinuationFrame, onFrame, onFrameError, onFrameSent, onFrameUnsent, onMessageDecompressionError, onMessageError, onPingFrame, onPongFrame, onSendError, onSendingFrame, onSendingHandshake, onStateChanged, onTextFrame, onTextMessage, onTextMessageError, onThreadCreated, onThreadStarted, onThreadStopping
-
-
-
-
Constructor Detail
-
DiscordWebSocketAdapter
public DiscordWebSocketAdapter(DiscordApiImpl api)
Creates a new discord websocket adapter.- Parameters:
api
- The discord api instance.
-
-
Method Detail
-
setGateway
public static void setGateway(java.lang.String gateway)
Sets the gateway used to connect.- Parameters:
gateway
- The gateway to set.
-
disconnect
public void disconnect()
Disconnects from the websocket.
-
onDisconnected
public void onDisconnected(com.neovisionaries.ws.client.WebSocket websocket, com.neovisionaries.ws.client.WebSocketFrame serverCloseFrame, com.neovisionaries.ws.client.WebSocketFrame clientCloseFrame, boolean closedByServer)
- Specified by:
onDisconnected
in interfacecom.neovisionaries.ws.client.WebSocketListener
- Overrides:
onDisconnected
in classcom.neovisionaries.ws.client.WebSocketAdapter
-
onTextMessage
public void onTextMessage(com.neovisionaries.ws.client.WebSocket websocket, java.lang.String text) throws java.lang.Exception
- Specified by:
onTextMessage
in interfacecom.neovisionaries.ws.client.WebSocketListener
- Overrides:
onTextMessage
in classcom.neovisionaries.ws.client.WebSocketAdapter
- Throws:
java.lang.Exception
-
onBinaryMessage
public void onBinaryMessage(com.neovisionaries.ws.client.WebSocket websocket, byte[] binary) throws java.lang.Exception
- Specified by:
onBinaryMessage
in interfacecom.neovisionaries.ws.client.WebSocketListener
- Overrides:
onBinaryMessage
in classcom.neovisionaries.ws.client.WebSocketAdapter
- Throws:
java.lang.Exception
-
sendVoiceStateUpdate
public void sendVoiceStateUpdate(Server server, ServerVoiceChannel channel, java.lang.Boolean selfMuted, java.lang.Boolean selfDeafened)
Sends the voice state update packet.- Parameters:
server
- The server to send the voice state update for. Can benull
ifchannel
is given.channel
- The channel to connect to ornull
to disconnect from voice.selfMuted
- Whether to self-mute on the given server. Ifnull
, current state remains unchanged.selfDeafened
- Whether to self-deafen on the given server. Ifnull
, current state remains unchanged.
-
getWebSocket
public com.neovisionaries.ws.client.WebSocket getWebSocket()
Gets the websocket of the adapter.- Returns:
- The websocket of the adapter.
-
isReady
public java.util.concurrent.CompletableFuture<java.lang.Boolean> isReady()
Gets the Future which tells whether the connection is ready or failed.- Returns:
- The Future.
-
updateStatus
public void updateStatus()
Sends the update status packet.
-
sendCloseFrame
public void sendCloseFrame(int closeCode)
Send a close frame with the given close code after ratelimit allows.- Parameters:
closeCode
- The close code for the close frame.
-
sendCloseFrame
public void sendCloseFrame(com.neovisionaries.ws.client.WebSocket webSocket, int closeCode)
Send a close frame over the given web socket with the given close code after ratelimit allows.- Parameters:
webSocket
- The web socket to send the close frame to.closeCode
- The close code for the close frame.
-
sendCloseFrame
public void sendCloseFrame(int closeCode, java.lang.String reason)
Send a close frame with the given close code and reason after ratelimit allows.- Parameters:
closeCode
- The close code for the close frame.reason
- The reason for the close frame.
-
sendCloseFrame
public void sendCloseFrame(com.neovisionaries.ws.client.WebSocket webSocket, int closeCode, java.lang.String reason)
Send a close frame over the given web socket with the given close code and reason after ratelimit allows.- Parameters:
webSocket
- The web socket to send the close frame to.closeCode
- The close code for the close frame.reason
- The reason for the close frame.
-
sendLifecycleTextFrame
public void sendLifecycleTextFrame(java.lang.String message)
Send a lifecycle text frame with the given message after ratelimit allows.- Parameters:
message
- The message for the text frame.
-
sendLifecycleTextFrame
public void sendLifecycleTextFrame(com.neovisionaries.ws.client.WebSocket webSocket, java.lang.String message)
Send a lifecycle text frame over the given web socket with the given message after ratelimit allows.- Parameters:
webSocket
- The web socket to send the text frame to.message
- The message for the text frame.
-
sendTextFrame
public void sendTextFrame(java.lang.String message)
Send a text frame with the given message after ratelimit allows.- Parameters:
message
- The message for the text frame.
-
sendLifecycleFrame
public void sendLifecycleFrame(com.neovisionaries.ws.client.WebSocketFrame frame)
Send the given lifecycle web socket frame after ratelimit allows.- Parameters:
frame
- The web socket frame to send.
-
sendLifecycleFrame
public void sendLifecycleFrame(com.neovisionaries.ws.client.WebSocket webSocket, com.neovisionaries.ws.client.WebSocketFrame frame)
Send the given lifecycle web socket frame over the given web socket after ratelimit allows.- Parameters:
webSocket
- The web socket to send the frame to.frame
- The web socket frame to send.
-
sendFrame
public void sendFrame(com.neovisionaries.ws.client.WebSocketFrame frame)
Send the given web socket frame after ratelimit allows.- Parameters:
frame
- The web socket frame to send.
-
queueRequestGuildMembers
public void queueRequestGuildMembers(Server server)
Adds a server id to be queued for the "request guild members" packet.- Parameters:
server
- The server.
-
onError
public void onError(com.neovisionaries.ws.client.WebSocket websocket, com.neovisionaries.ws.client.WebSocketException cause)
- Specified by:
onError
in interfacecom.neovisionaries.ws.client.WebSocketListener
- Overrides:
onError
in classcom.neovisionaries.ws.client.WebSocketAdapter
-
handleCallbackError
public void handleCallbackError(com.neovisionaries.ws.client.WebSocket websocket, java.lang.Throwable cause)
- Specified by:
handleCallbackError
in interfacecom.neovisionaries.ws.client.WebSocketListener
- Overrides:
handleCallbackError
in classcom.neovisionaries.ws.client.WebSocketAdapter
-
onUnexpectedError
public void onUnexpectedError(com.neovisionaries.ws.client.WebSocket websocket, com.neovisionaries.ws.client.WebSocketException cause)
- Specified by:
onUnexpectedError
in interfacecom.neovisionaries.ws.client.WebSocketListener
- Overrides:
onUnexpectedError
in classcom.neovisionaries.ws.client.WebSocketAdapter
-
onConnectError
public void onConnectError(com.neovisionaries.ws.client.WebSocket websocket, com.neovisionaries.ws.client.WebSocketException exception)
- Specified by:
onConnectError
in interfacecom.neovisionaries.ws.client.WebSocketListener
- Overrides:
onConnectError
in classcom.neovisionaries.ws.client.WebSocketAdapter
-
-