public void close() { if (socket != null) socket.sendClose(1000); }
public void close(int code) { if (socket != null) socket.sendClose(code); }
public void close(int code, String reason) { if (socket != null) socket.sendClose(code, reason); }
@Override public void onConnected(WebSocket websocket, Map<String, List<String>> headers) { if (shutdown) { //Somehow this AudioWebSocket was shutdown before we finished connecting.... // thus we just disconnect here since we were asked to shutdown socket.sendClose(1000); return; } if (reconnecting) resume(); else identify(); changeStatus(ConnectionStatus.CONNECTING_AWAITING_AUTHENTICATION); audioConnection.prepareReady(); reconnecting = false; }
public void close() { if (keepAliveThread != null) { keepAliveThread.interrupt(); keepAliveThread = null; } socket.sendClose(); }
audioConnection.udpSocket.close(); if (socket != null) socket.sendClose();
public void close() { connected = false; ready = false; JSONObject obj = new JSONObject() .put("op", 4) .put("d", new JSONObject() .put("guild_id", JSONObject.NULL) .put("channel_id", JSONObject.NULL) .put("self_mute", false) .put("self_deaf", false) ); api.getClient().send(obj.toString()); if (keepAliveThread != null) { keepAliveThread.interrupt(); keepAliveThread = null; } if (udpKeepAliveThread != null) { udpKeepAliveThread.interrupt(); udpKeepAliveThread = null; } udpSocket.close(); socket.sendClose(); api.getAudioManager().setAudioConnection(null); }
/** * Disconnects from the websocket. */ public void disconnect() { reconnect = false; websocket.get().sendClose(WebSocketCloseReason.DISCONNECT.getNumericCloseCode()); // cancel heartbeat timer if within one minute no disconnect event was dispatched api.getThreadPool().getDaemonScheduler().schedule(() -> heartbeatTimer.updateAndGet(future -> { if (future != null) { future.cancel(false); } return null; }), 1, TimeUnit.MINUTES); }
/** * Starts the heartbeat. * * @param websocket The websocket the heartbeat should be sent to. * @param heartbeatInterval The heartbeat interval. * @return The timer used for the heartbeat. */ private Future<?> startHeartbeat(final WebSocket websocket, final int heartbeatInterval) { // first heartbeat should assume last heartbeat was answered properly heartbeatAckReceived.set(true); return api.getThreadPool().getScheduler().scheduleWithFixedDelay(() -> { try { if (heartbeatAckReceived.getAndSet(false)) { sendHeartbeat(websocket); logger.debug("Sent heartbeat (interval: {})", heartbeatInterval); } else { websocket.sendClose(WebSocketCloseReason.HEARTBEAT_NOT_PROPERLY_ANSWERED.getNumericCloseCode(), WebSocketCloseReason.HEARTBEAT_NOT_PROPERLY_ANSWERED.getCloseReason()); } } catch (Throwable t) { logger.error("Failed to send heartbeat or close web socket!", t); } }, 0, heartbeatInterval, TimeUnit.MILLISECONDS); }
break; case RECONNECT: websocket.sendClose(WebSocketCloseReason.COMMANDED_RECONNECT.getNumericCloseCode(), WebSocketCloseReason.COMMANDED_RECONNECT.getCloseReason()); break;