Class VTSClientImpl

java.lang.Object
dev.adlin.vts4j.VTSClientImpl
All Implemented Interfaces:
VTSClient

public class VTSClientImpl extends Object implements VTSClient
Robust implementation of the VTSClient interface.

This class acts as a structural Facade, encapsulating network topology, request dispatching, authentication layers, and subscription providers into a unified client entity.

  • Constructor Details

  • Method Details

    • connect

      public VTSClient connect()
      Description copied from interface: VTSClient
      Initiates a non-blocking background connection routine to the remote VTube Studio server.
      Specified by:
      connect in interface VTSClient
      Returns:
      this client instance for fluent method chaining
    • awaitConnect

      public VTSClient awaitConnect()
      Description copied from interface: VTSClient
      Establishes a synchronous connection to the remote server, blocking the calling thread indefinitely until the connection handshake completes or fails.
      Specified by:
      awaitConnect in interface VTSClient
      Returns:
      this client instance for fluent method chaining
    • awaitConnect

      public VTSClient awaitConnect(long timeout, @NonNull TimeUnit timeUnit)
      Description copied from interface: VTSClient
      Establishes a synchronous connection to the remote server, blocking the calling thread up to the specified timeout interval.
      Specified by:
      awaitConnect in interface VTSClient
      Parameters:
      timeout - the maximum duration to wait for a connection handshake
      timeUnit - the time unit of the timeout argument
      Returns:
      this client instance for fluent method chaining
    • disconnect

      public void disconnect()
      Description copied from interface: VTSClient
      Initiates an asynchronous, non-blocking disconnection routine to close the socket session.
      Specified by:
      disconnect in interface VTSClient
    • awaitDisconnect

      public void awaitDisconnect()
      Description copied from interface: VTSClient
      Synchronously tears down the active socket session, blocking the calling thread until the close handshake is acknowledged.
      Specified by:
      awaitDisconnect in interface VTSClient
    • authenticate

      public @NonNull CompletableFuture<String> authenticate(@NonNull PluginMeta pluginMeta)
      Description copied from interface: VTSClient
      Requests a brand new authentication token from VTube Studio for the specified plugin metadata.

      This will trigger a pop-up confirmation window inside the VTube Studio UI for the end-user.

      Specified by:
      authenticate in interface VTSClient
      Parameters:
      pluginMeta - the metadata configuration of the plugin requesting access
      Returns:
      a CompletableFuture that resolves to the newly issued unique authentication token string
    • authenticate

      public void authenticate(@NonNull PluginMeta pluginMeta, @NonNull String authenticationToken)
      Description copied from interface: VTSClient
      Authenticates the plugin session instantly using a previously saved existing authentication token.
      Specified by:
      authenticate in interface VTSClient
      Parameters:
      pluginMeta - the metadata configuration of the plugin
      authenticationToken - the pre-issued token string to authenticate with
    • sendRequest

      public CompletableFuture<Response> sendRequest(@NonNull Request request)
      Description copied from interface: VTSClient
      Serializes and dispatches an asynchronous request packet to the server over the active socket session.
      Specified by:
      sendRequest in interface VTSClient
      Parameters:
      request - the request packet structure to be transmitted
      Returns:
      a CompletableFuture containing the server's asynchronous Response package
    • subscribe

      public CompletableFuture<Response> subscribe(@NonNull Class<? extends Event> eventClass, @NonNull com.google.gson.JsonObject eventConfig)
      Description copied from interface: VTSClient
      Subscribes the current plugin session to a specific system event type using extended configuration arguments.

      Re-subscribing to an already active event type will seamlessly overwrite its previous parameters. For details regarding available event names and payloads, see the VTube Studio Events Guide.

      Specified by:
      subscribe in interface VTSClient
      Parameters:
      eventClass - the class type of the target Event to subscribe to
      eventConfig - custom JSON configuration properties and filters specific to the event type
      Returns:
      a CompletableFuture containing the server response acknowledgment indicating operation status
    • subscribe

      public CompletableFuture<Response> subscribe(@NonNull Class<? extends Event> eventClass)
      Description copied from interface: VTSClient
      Subscribes the current plugin session to a specific system event type using default configurations.
      Specified by:
      subscribe in interface VTSClient
      Parameters:
      eventClass - the class type of the target Event to subscribe to
      Returns:
      a CompletableFuture containing the server response acknowledgment indicating operation status
    • unsubscribe

      public CompletableFuture<Response> unsubscribe(@NonNull Class<? extends Event> eventClass, @Nullable com.google.gson.JsonObject eventConfig)
      Description copied from interface: VTSClient
      Unsubscribes the current plugin session from a specific system event matching the provided configuration filters.
      Specified by:
      unsubscribe in interface VTSClient
      Parameters:
      eventClass - the class type of the target Event to unsubscribe from
      eventConfig - custom JSON configuration parameters to match for removal
      Returns:
      a CompletableFuture containing the server response acknowledgment indicating operation status
    • unsubscribe

      public CompletableFuture<Response> unsubscribe(@NonNull Class<? extends Event> eventClass)
      Description copied from interface: VTSClient
      Unsubscribes the current plugin session from all instances of the specified system event type.
      Specified by:
      unsubscribe in interface VTSClient
      Parameters:
      eventClass - the class type of the target Event to unsubscribe from
      Returns:
      a CompletableFuture containing the server response acknowledgment indicating operation status
    • registerEventListener

      public void registerEventListener(@NonNull Listener listener)
      Description copied from interface: VTSClient
      Registers an event listener object within the client's internal event bus.

      The registered instance will intercept notifications for any system events that have been activated using the subscribe methods.

      Specified by:
      registerEventListener in interface VTSClient
      Parameters:
      listener - an instance of a custom class implementing the marker Listener interface