Package dev.adlin.vts4j
Class VTSClientImpl
java.lang.Object
dev.adlin.vts4j.VTSClientImpl
- All Implemented Interfaces:
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 Summary
ConstructorsModifierConstructorDescriptionprotectedVTSClientImpl(@NonNull NetworkClient networkClient, @NonNull EventHandler eventHandler, @NonNull RequestDispatcher requestDispatcher) -
Method Summary
Modifier and TypeMethodDescription@NonNull CompletableFuture<String> authenticate(@NonNull PluginMeta pluginMeta) Requests a brand new authentication token from VTube Studio for the specified plugin metadata.voidauthenticate(@NonNull PluginMeta pluginMeta, @NonNull String authenticationToken) Authenticates the plugin session instantly using a previously saved existing authentication token.Establishes a synchronous connection to the remote server, blocking the calling thread indefinitely until the connection handshake completes or fails.awaitConnect(long timeout, @NonNull TimeUnit timeUnit) Establishes a synchronous connection to the remote server, blocking the calling thread up to the specified timeout interval.voidSynchronously tears down the active socket session, blocking the calling thread until the close handshake is acknowledged.connect()Initiates a non-blocking background connection routine to the remote VTube Studio server.voidInitiates an asynchronous, non-blocking disconnection routine to close the socket session.voidregisterEventListener(@NonNull Listener listener) Registers an event listener object within the client's internal event bus.sendRequest(@NonNull Request request) Serializes and dispatches an asynchronous request packet to the server over the active socket session.Subscribes the current plugin session to a specific system event type using default configurations.subscribe(@NonNull Class<? extends Event> eventClass, @NonNull com.google.gson.JsonObject eventConfig) Subscribes the current plugin session to a specific system event type using extended configuration arguments.unsubscribe(@NonNull Class<? extends Event> eventClass) Unsubscribes the current plugin session from all instances of the specified system event type.unsubscribe(@NonNull Class<? extends Event> eventClass, @Nullable com.google.gson.JsonObject eventConfig) Unsubscribes the current plugin session from a specific system event matching the provided configuration filters.
-
Constructor Details
-
VTSClientImpl
protected VTSClientImpl(@NonNull NetworkClient networkClient, @NonNull EventHandler eventHandler, @NonNull RequestDispatcher requestDispatcher)
-
-
Method Details
-
connect
Description copied from interface:VTSClientInitiates a non-blocking background connection routine to the remote VTube Studio server. -
awaitConnect
Description copied from interface:VTSClientEstablishes a synchronous connection to the remote server, blocking the calling thread indefinitely until the connection handshake completes or fails.- Specified by:
awaitConnectin interfaceVTSClient- Returns:
- this client instance for fluent method chaining
-
awaitConnect
Description copied from interface:VTSClientEstablishes a synchronous connection to the remote server, blocking the calling thread up to the specified timeout interval.- Specified by:
awaitConnectin interfaceVTSClient- Parameters:
timeout- the maximum duration to wait for a connection handshaketimeUnit- the time unit of the timeout argument- Returns:
- this client instance for fluent method chaining
-
disconnect
public void disconnect()Description copied from interface:VTSClientInitiates an asynchronous, non-blocking disconnection routine to close the socket session.- Specified by:
disconnectin interfaceVTSClient
-
awaitDisconnect
public void awaitDisconnect()Description copied from interface:VTSClientSynchronously tears down the active socket session, blocking the calling thread until the close handshake is acknowledged.- Specified by:
awaitDisconnectin interfaceVTSClient
-
authenticate
Description copied from interface:VTSClientRequests 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:
authenticatein interfaceVTSClient- Parameters:
pluginMeta- the metadata configuration of the plugin requesting access- Returns:
- a
CompletableFuturethat resolves to the newly issued unique authentication token string
-
authenticate
Description copied from interface:VTSClientAuthenticates the plugin session instantly using a previously saved existing authentication token.- Specified by:
authenticatein interfaceVTSClient- Parameters:
pluginMeta- the metadata configuration of the pluginauthenticationToken- the pre-issued token string to authenticate with
-
sendRequest
Description copied from interface:VTSClientSerializes and dispatches an asynchronous request packet to the server over the active socket session.- Specified by:
sendRequestin interfaceVTSClient- Parameters:
request- the request packet structure to be transmitted- Returns:
- a
CompletableFuturecontaining the server's asynchronousResponsepackage
-
subscribe
public CompletableFuture<Response> subscribe(@NonNull Class<? extends Event> eventClass, @NonNull com.google.gson.JsonObject eventConfig) Description copied from interface:VTSClientSubscribes 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:
subscribein interfaceVTSClient- Parameters:
eventClass- the class type of the targetEventto subscribe toeventConfig- custom JSON configuration properties and filters specific to the event type- Returns:
- a
CompletableFuturecontaining the server response acknowledgment indicating operation status
-
subscribe
Description copied from interface:VTSClientSubscribes the current plugin session to a specific system event type using default configurations.- Specified by:
subscribein interfaceVTSClient- Parameters:
eventClass- the class type of the targetEventto subscribe to- Returns:
- a
CompletableFuturecontaining 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:VTSClientUnsubscribes the current plugin session from a specific system event matching the provided configuration filters.- Specified by:
unsubscribein interfaceVTSClient- Parameters:
eventClass- the class type of the targetEventto unsubscribe fromeventConfig- custom JSON configuration parameters to match for removal- Returns:
- a
CompletableFuturecontaining the server response acknowledgment indicating operation status
-
unsubscribe
Description copied from interface:VTSClientUnsubscribes the current plugin session from all instances of the specified system event type.- Specified by:
unsubscribein interfaceVTSClient- Parameters:
eventClass- the class type of the targetEventto unsubscribe from- Returns:
- a
CompletableFuturecontaining the server response acknowledgment indicating operation status
-
registerEventListener
Description copied from interface:VTSClientRegisters 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
subscribemethods.- Specified by:
registerEventListenerin interfaceVTSClient- Parameters:
listener- an instance of a custom class implementing the markerListenerinterface
-