Class WebsocketConnection
java.lang.Object
com.github.twitch4j.client.websocket.WebsocketConnection
- All Implemented Interfaces:
AutoCloseable
-
Field Summary
Modifier and TypeFieldDescriptionprotected final AtomicBoolean
Whetherclose()
has been calledprotected final CountDownLatch
Latch used to indicate that the underlying socket has fully disconnected followingclose()
.protected final WebsocketConnectionConfig
connection configurationprotected final AtomicLong
Tracks the timestamp of the last outbound pingprotected long
protected final com.neovisionaries.ws.client.WebSocketAdapter
WebSocket Adapterprotected final com.neovisionaries.ws.client.WebSocketFactory
WebSocket Factory -
Constructor Summary
ConstructorDescriptionWebsocketConnection
(Consumer<WebsocketConnectionConfig> configSpec) TwitchWebsocketConnection -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
connect()
Connect to the WebSocketprotected com.neovisionaries.ws.client.WebSocket
void
Disconnect from the WebSocketconnection configurationlong
void
Reconnecting to the WebSocketboolean
sends a message to the websocket serverprotected void
setState
(WebsocketConnectionState newState)
-
Field Details
-
config
connection configuration -
webSocketFactory
protected final com.neovisionaries.ws.client.WebSocketFactory webSocketFactoryWebSocket Factory -
webSocketAdapter
protected final com.neovisionaries.ws.client.WebSocketAdapter webSocketAdapterWebSocket Adapter -
lastPing
Tracks the timestamp of the last outbound ping -
latency
protected volatile long latency -
closed
Whetherclose()
has been called -
closeLatch
Latch used to indicate that the underlying socket has fully disconnected followingclose()
.
-
-
Constructor Details
-
WebsocketConnection
TwitchWebsocketConnection- Parameters:
configSpec
- the websocket connection configuration
-
-
Method Details
-
createWebsocket
- Throws:
IOException
-
setState
-
connect
public void connect()Connect to the WebSocket -
disconnect
public void disconnect()Disconnect from the WebSocket -
reconnect
public void reconnect()Reconnecting to the WebSocket -
sendText
sends a message to the websocket server- Parameters:
message
- message content
-
getConnectionState
- Returns:
- the socket's connection state
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
getConfig
connection configuration -
getLatency
public long getLatency()
-