Class ConnectedPlayer

java.lang.Object
live.crowdcontrol.cc4j.websocket.ConnectedPlayer
All Implemented Interfaces:
WebSocket.Listener, CCPlayer

@Internal public class ConnectedPlayer extends Object implements CCPlayer, WebSocket.Listener
A player connected to the server.
  • Field Details

    • JACKSON

      @NotNull public static final @NotNull com.fasterxml.jackson.databind.ObjectMapper JACKSON
    • log

      @NotNull protected static final @NotNull org.slf4j.Logger log
    • lock

      protected final ReentrantLock lock
    • subscriptions

      @NotNull protected final @NotNull Set<String> subscriptions
    • visible

      protected final Map<String,Boolean> visible
    • available

      protected final Map<String,Boolean> available
    • eventManager

      @NotNull protected final @NotNull EventManager eventManager
    • uuid

      @NotNull protected final @NotNull UUID uuid
    • tokenPath

      @NotNull protected final @NotNull Path tokenPath
    • parent

      @NotNull protected final @NotNull CrowdControl parent
    • pendingText

      @NotNull protected @NotNull StringBuilder pendingText
    • ws

      @Nullable protected @Nullable WebSocket ws
    • authCode

      @Nullable protected @Nullable String authCode
    • token

      @Nullable protected @Nullable String token
    • userToken

      @Nullable protected @Nullable UserToken userToken
    • gameSessionID

      @Nullable protected @Nullable String gameSessionID
    • lastGameSessionID

      @Nullable protected @Nullable String lastGameSessionID
    • pendingAuthCode

      @Nullable protected @Nullable CompletableFuture<Void> pendingAuthCode
    • sleep

      protected int sleep
    • disconnectTriggeredAt

      protected long disconnectTriggeredAt
    • keepAlive

      protected ScheduledFuture<?> keepAlive
    • timeout

      protected ScheduledFuture<?> timeout
  • Constructor Details

    • ConnectedPlayer

      public ConnectedPlayer(@NotNull @NotNull UUID uuid, @NotNull @NotNull CrowdControl parent)
  • Method Details

    • connect

      public void connect()
    • close

      public CompletableFuture<?> close()
    • clearKeepAlive

      public void clearKeepAlive()
    • resetKeepAlive

      public void resetKeepAlive()
    • onPong

      public CompletionStage<?> onPong(WebSocket webSocket, ByteBuffer message)
      Specified by:
      onPong in interface WebSocket.Listener
    • onOpen

      public void onOpen(WebSocket ws)
      Specified by:
      onOpen in interface WebSocket.Listener
    • onText

      public CompletionStage<?> onText(WebSocket webSocket, CharSequence data, boolean last)
      Specified by:
      onText in interface WebSocket.Listener
    • onClose

      public CompletionStage<?> onClose(WebSocket webSocket, int statusCode, String reason)
      Specified by:
      onClose in interface WebSocket.Listener
    • onError

      public void onError(WebSocket webSocket, Throwable error)
      Specified by:
      onError in interface WebSocket.Listener
    • canSend

      public boolean canSend()
    • canSendRPC

      public boolean canSendRPC()
    • sendRPC

      public CompletableFuture<Boolean> sendRPC(CallData<?> call)
    • sendResponse

      public CompletableFuture<Boolean> sendResponse(@NotNull @NotNull CCEffectResponse response)
      Description copied from interface: CCPlayer
      Sends an effect response to the WebSocket.
      Specified by:
      sendResponse in interface CCPlayer
      Parameters:
      response - effect response
      Returns:
      whether the response could be sent
    • regenerateAuthCode

      @NotNull public @NotNull CompletableFuture<?> regenerateAuthCode()
      Description copied from interface: CCPlayer
      Regenerates the user's auth code. May fail if the user is already authenticated.
      Specified by:
      regenerateAuthCode in interface CCPlayer
      Returns:
      future to complete when the auth code has regenerated
    • sendReport

      public CompletableFuture<Boolean> sendReport(@NotNull @NotNull CCEffectReport @NotNull ... reports)
      Description copied from interface: CCPlayer
      Sends one or more effect reports to the WebSocket.
      Specified by:
      sendReport in interface CCPlayer
      Parameters:
      reports - effect reports
      Returns:
      whether the report could be sent
    • setCustomEffects

      @NotNull public @NotNull CompletableFuture<?> setCustomEffects(@NotNull @NotNull List<CustomEffectsOperation> operations)
      Description copied from interface: CCPlayer
      Attempts to set the specified custom effects. May fail if they have not yet authenticated.
      Specified by:
      setCustomEffects in interface CCPlayer
      Returns:
      future to complete when finished
    • startSession

      @NotNull public @NotNull CompletableFuture<?> startSession(@NotNull @NotNull CCEffectReport @NotNull ... reports)
      Description copied from interface: CCPlayer
      Attempts to start the streamer's session. May fail if they have not yet authenticated; check CCPlayer.getGameSessionId() for outcome.
      Specified by:
      startSession in interface CCPlayer
      Returns:
      future to complete when finished
    • stopSession

      @NotNull public @NotNull CompletableFuture<?> stopSession()
      Description copied from interface: CCPlayer
      Attempts to stop the streamer's session.
      Specified by:
      stopSession in interface CCPlayer
      Returns:
      future to complete when finished
    • setToken

      public boolean setToken(String token)
    • loadToken

      protected boolean loadToken()
    • saveToken

      protected void saveToken()
    • subscribe

      protected void subscribe()
    • getAuthUrl

      @Nullable public @Nullable String getAuthUrl()
      Description copied from interface: CCPlayer
      Gets the URL for the player to sign in with, if available.
      Specified by:
      getAuthUrl in interface CCPlayer
    • clearToken

      public void clearToken()
      Description copied from interface: CCPlayer
      Clears the user's auth token if they have one. Will not automatically re-generate an auth code; see CCPlayer.regenerateAuthCode().
      Specified by:
      clearToken in interface CCPlayer
    • getUuid

      @NotNull public @NotNull UUID getUuid()
      Description copied from interface: CCPlayer
      Gets the unique ID that represents an in-game player.
      Specified by:
      getUuid in interface CCPlayer
      Returns:
      unique ID
    • getAuthCode

      @Nullable public @Nullable String getAuthCode()
      Description copied from interface: CCPlayer
      Gets the pending auth code of this connection.
      Specified by:
      getAuthCode in interface CCPlayer
      Returns:
      auth code
    • getToken

      @Nullable public @Nullable String getToken()
      Description copied from interface: CCPlayer
      Gets the user's token used for making authenticated requests.
      Specified by:
      getToken in interface CCPlayer
      Returns:
      auth token
    • getUserToken

      @Nullable public @Nullable UserToken getUserToken()
      Description copied from interface: CCPlayer
      Gets the user's profile as decoded from their auth token.
      Specified by:
      getUserToken in interface CCPlayer
      Returns:
      user profile
    • getEventManager

      @NotNull public @NotNull EventManager getEventManager()
      Description copied from interface: CCPlayer
      Gets the manager which handles distributing events.
      Specified by:
      getEventManager in interface CCPlayer
    • getGameSessionId

      @Nullable public @Nullable String getGameSessionId()
      Description copied from interface: CCPlayer
      Gets the ID of the player's active game session.
      Specified by:
      getGameSessionId in interface CCPlayer
      Returns:
      gameSessionID or null