Class TwitchEventSocketPool

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

public final class TwitchEventSocketPool extends Object implements IEventSubSocket
A pool for EventSub websocket subscriptions across multiple users.

Should not be used with the "conduit" transport type.

  • Method Details

    • connect

      public void connect()
      Description copied from interface: IEventSubSocket
      Establishes a connection to the EventSub WebSocket server.
      Specified by:
      connect in interface IEventSubSocket
      See Also:
    • disconnect

      public void disconnect()
      Description copied from interface: IEventSubSocket
      Disconnects from the WebSocket server.
      Specified by:
      disconnect in interface IEventSubSocket
      See Also:
    • reconnect

      public void reconnect()
      Description copied from interface: IEventSubSocket
      Reconnects to the WebSocket server.
      Specified by:
      reconnect in interface IEventSubSocket
      See Also:
    • register

      public boolean register(com.github.philippheuer.credentialmanager.domain.OAuth2Credential credential, EventSubSubscription sub)
      Description copied from interface: IEventSubSocket
      Creates (or schedules) an eventsub subscription for this socket.
      Specified by:
      register in interface IEventSubSocket
      Parameters:
      credential - 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 sub)
      Description copied from interface: IEventSubSocket
      Deletes an eventsub subscription from helix (and this socket).
      Specified by:
      unregister in interface IEventSubSocket
      Parameters:
      sub - 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
    • close

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

      @Nullable public @Nullable com.github.philippheuer.credentialmanager.domain.OAuth2Credential getDefaultToken()
      Specified by:
      getDefaultToken in interface IEventSubSocket
      Returns:
      the default token to use when creating subscriptions
    • 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
    • numConnections

      public int numConnections()
      Returns:
      the number of open connections held by this pool.
    • numSubscriptions

      public int numSubscriptions()
      Returns:
      the total number of subscriptions held by all connections.
    • builder

    • getEventManager

      public com.github.philippheuer.events4j.core.EventManager getEventManager()
      The default EventManager for this connection pool, if specified.
      Specified by:
      getEventManager in interface IEventSubSocket
      Returns:
      the event manager for eventsub notifications