Class TwitchEventSocket

java.lang.Object
com.github.twitch4j.eventsub.socket.TwitchEventSocket
All Implemented Interfaces:
IEventSubSocket, AutoCloseable

public final class TwitchEventSocket extends Object implements IEventSubSocket
A single EventSub websocket for a single user id.
  • Field Details

    • REQUIRED_THREAD_COUNT

      public static final int REQUIRED_THREAD_COUNT
      See Also:
    • MAX_SUBSCRIPTIONS_PER_SOCKET

      public static final int MAX_SUBSCRIPTIONS_PER_SOCKET
      Each WebSocket connection may create a maximum of 300 enabled subscriptions (disabled subscriptions don't count against the limit).
      See Also:
    • WEB_SOCKET_SERVER

      public static final String WEB_SOCKET_SERVER
      The WebSocket Server
      See Also:
  • Method Details

    • connect

      public void connect()
      Connecting to EventSub-WS
      Specified by:
      connect in interface IEventSubSocket
      See Also:
    • disconnect

      public void disconnect()
      Disconnecting from EventSub-WS
      Specified by:
      disconnect in interface IEventSubSocket
      See Also:
    • reconnect

      public void reconnect()
      Reconnecting to EventSub-WS
      Specified by:
      reconnect in interface IEventSubSocket
      See Also:
    • close

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

      public boolean register(com.github.philippheuer.credentialmanager.domain.OAuth2Credential token, EventSubSubscription sub)
      Description copied from interface: IEventSubSocket
      Creates (or schedules) an eventsub subscription for this socket.
      Specified by:
      register in interface IEventSubSocket
      Parameters:
      token - the token to use for creating this subscription via helix
      sub - the eventsub subscription to be registered
      Returns:
      whether this subscription was not already registered to this pool (and, if the websocket is already connected, whether the subscription was successful)
    • unregister

      public boolean unregister(EventSubSubscription subscription)
      Description copied from interface: IEventSubSocket
      Deletes an eventsub subscription from helix (and this socket).
      Specified by:
      unregister in interface IEventSubSocket
      Parameters:
      subscription - the eventsub subscription to be destroyed
      Returns:
      whether the specified subscription was previously registered with this socket
    • getSubscriptions

      public Collection<EventSubSubscription> getSubscriptions()
      Specified by:
      getSubscriptions in interface IEventSubSocket
      Returns:
      the eventsub subscriptions associated with this socket
    • getLatency

      public long getLatency()
      Specified by:
      getLatency in interface IEventSubSocket
      Returns:
      the most recently measured round-trip latency for the socket(s) in milliseconds, or -1 if unknown
    • getState

      public WebsocketConnectionState getState()
    • builder

    • getDefaultToken

      @Nullable public @Nullable com.github.philippheuer.credentialmanager.domain.OAuth2Credential getDefaultToken()
      Default Helix Token
      Specified by:
      getDefaultToken in interface IEventSubSocket
      Returns:
      the default token to use when creating subscriptions
    • getEventManager

      @NotNull public @NotNull com.github.philippheuer.events4j.core.EventManager getEventManager()
      EventManager
      Specified by:
      getEventManager in interface IEventSubSocket
      Returns:
      the event manager for eventsub notifications
    • getWebsocketId

      @Nullable public @Nullable String getWebsocketId()
      The Twitch-assigned id associated with this websocket, which is used when creating eventsub subscriptions via the API.