Class WebsocketConnection

java.lang.Object
com.github.twitch4j.client.websocket.WebsocketConnection
All Implemented Interfaces:
AutoCloseable

public class WebsocketConnection extends Object implements AutoCloseable
  • Field Details

    • config

      protected final WebsocketConnectionConfig config
      connection configuration
    • webSocketFactory

      protected final com.neovisionaries.ws.client.WebSocketFactory webSocketFactory
      WebSocket Factory
    • webSocketAdapter

      protected final com.neovisionaries.ws.client.WebSocketAdapter webSocketAdapter
      WebSocket Adapter
    • lastPing

      protected final AtomicLong lastPing
      Tracks the timestamp of the last outbound ping
    • latency

      protected volatile long latency
    • closed

      protected final AtomicBoolean closed
      Whether close() has been called
    • closeLatch

      protected final CountDownLatch closeLatch
      Latch used to indicate that the underlying socket has fully disconnected following close().
  • Constructor Details

    • WebsocketConnection

      public WebsocketConnection(Consumer<WebsocketConnectionConfig> configSpec)
      TwitchWebsocketConnection
      Parameters:
      configSpec - the websocket connection configuration
  • Method Details

    • createWebsocket

      protected com.neovisionaries.ws.client.WebSocket createWebsocket() throws IOException
      Throws:
      IOException
    • setState

      protected void setState(WebsocketConnectionState newState)
    • 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

      public boolean sendText(String message)
      sends a message to the websocket server
      Parameters:
      message - message content
    • getConnectionState

      public WebsocketConnectionState getConnectionState()
      Returns:
      the socket's connection state
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • getConfig

      public WebsocketConnectionConfig getConfig()
      connection configuration
    • getLatency

      public long getLatency()