Class WebsocketConnection
java.lang.Object
com.github.twitch4j.client.websocket.WebsocketConnection
- All Implemented Interfaces:
AutoCloseable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AtomicBooleanWhetherclose()has been calledprotected final CountDownLatchLatch used to indicate that the underlying socket has fully disconnected followingclose().protected final WebsocketConnectionConfigconnection configurationprotected final AtomicLongTracks the timestamp of the last outbound pingprotected longprotected final com.neovisionaries.ws.client.WebSocketAdapterWebSocket Adapterprotected final com.neovisionaries.ws.client.WebSocketFactoryWebSocket Factory -
Constructor Summary
ConstructorsConstructorDescriptionWebsocketConnection(Consumer<WebsocketConnectionConfig> configSpec) TwitchWebsocketConnection -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidconnect()Connect to the WebSocketprotected com.neovisionaries.ws.client.WebSocketvoidDisconnect from the WebSocketconnection configurationlongvoidReconnecting to the WebSocketbooleansends a message to the websocket serverprotected voidsetState(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:
closein interfaceAutoCloseable- Throws:
Exception
-
getConfig
connection configuration -
getLatency
public long getLatency()
-