Class VRSpaceClient

java.lang.Object
org.vrspace.client.VRSpaceClient
All Implemented Interfaces:
Runnable, WebSocket.Listener

public class VRSpaceClient extends Object implements WebSocket.Listener, Runnable
A simple vrspace websocket client.
Author:
joe
  • Field Details

  • Constructor Details

    • VRSpaceClient

      public VRSpaceClient(URI uri, com.fasterxml.jackson.databind.ObjectMapper mapper)
  • Method Details

    • connect

      public CompletableFuture<WebSocket> connect()
    • startSession

      public void startSession()
    • connectAndEnter

      public void connectAndEnter(String world)
    • disconnect

      public void disconnect()
    • run

      public void run()
      Specified by:
      run in interface Runnable
    • connectAndEnterAsync

      public void connectAndEnterAsync(String world, Map<String,String> params)
      Connect, and then set own parameters (e.g. avatar), then enter a world. Does not block until the connection has been made, but returns immediately. Use case - stress testing.
      Parameters:
      world - name of the world to enter
      params - own properties to set before entering the world
    • connectAndEnterSync

      public void connectAndEnterSync(String world, Map<String,String> params)
      Connect, set own parameters (e.g. avatar), then enter a world. Wait for connection and session to be set up, and then return. Typical use case when connecting to a server.
      Parameters:
      world - name of the world to enter
      params - own properties to set before entering the world
    • addEventListener

      public VRSpaceClient addEventListener(Consumer<VREvent> listener)
      Add event listener to receive events from the server (changes to VRObjects)
    • addSceneListener

      public VRSpaceClient addSceneListener(Consumer<SceneChange> listener)
      Add scene listener that receives changes to the scene - Add and Remove commands.
    • addErrorListener

      public VRSpaceClient addErrorListener(Consumer<String> listener)
      Add an error listener that is passed JSON error message received from the server.
    • addMessageListener

      public VRSpaceClient addMessageListener(Consumer<String> listener)
      Add a listener that receives all text messages from the server
    • addWelcomeListener

      public VRSpaceClient addWelcomeListener(Consumer<Welcome> listener)
      Welcome messages are received after connecting and entering a world
    • await

      public void await(CountDownLatch latch)
      Hack, awaits for welcome message
    • getClient

      public Client getClient()
    • enterSync

      public void enterSync(String world)
      Enter a world, and wait for welcome
    • enterAsync

      public void enterAsync(String world)
      Enter a world, do not wait for Welcome response
    • send

      public void send(String arg)
      Send a json string to the server
    • send

      public String send(ClientRequest req)
      Send a request
    • send

      public void send(Command cmd)
      Send a command
    • getErrorCount

      public int getErrorCount()
    • onOpen

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

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

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

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

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