Package org.vrspace.client
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
-
-
Constructor Summary
Constructors Constructor Description VRSpaceClient(URI uri, com.fasterxml.jackson.databind.ObjectMapper mapper)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description VRSpaceClient
addEventListener(Function<VREvent,Void> listener)
Add event listener to receive events from the server; an event is either a Command or change to a VRObjectVRSpaceClient
addMessageListener(Function<String,Void> listener)
Add a listener that receives all text messages from the serverVRSpaceClient
addWelcomeListener(Function<Welcome,Void> listener)
Welcome messages are received after connecting and entering a worldvoid
await()
Hack, awaits for welcome messageCompletableFuture<WebSocket>
connect()
void
connectAndEnter(String world)
void
connectAndEnter(String world, Map<String,String> params)
void
enter(String world)
Enter a worldClient
getClient()
int
getErrorCount()
CompletionStage<?>
onClose(WebSocket webSocket, int statusCode, String reason)
void
onError(WebSocket webSocket, Throwable error)
void
onOpen(WebSocket webSocket)
CompletionStage<?>
onPing(WebSocket webSocket, ByteBuffer message)
CompletionStage<?>
onText(WebSocket webSocket, CharSequence data, boolean last)
void
run()
void
send(String arg)
Send a json string to the servervoid
send(ClientRequest req)
Send a requestvoid
send(Command cmd)
Send a commandvoid
startSession()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.net.http.WebSocket.Listener
onBinary, onPong
-
-
-
-
Field Detail
-
TIMEOUT
public static final long TIMEOUT
- See Also:
- Constant Field Values
-
RETRY
public static final long RETRY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
VRSpaceClient
public VRSpaceClient(URI uri, com.fasterxml.jackson.databind.ObjectMapper mapper)
-
-
Method Detail
-
connect
public CompletableFuture<WebSocket> connect()
-
startSession
public void startSession()
-
connectAndEnter
public void connectAndEnter(String world)
-
addEventListener
public VRSpaceClient addEventListener(Function<VREvent,Void> listener)
Add event listener to receive events from the server; an event is either a Command or change to a VRObject
-
addMessageListener
public VRSpaceClient addMessageListener(Function<String,Void> listener)
Add a listener that receives all text messages from the server
-
addWelcomeListener
public VRSpaceClient addWelcomeListener(Function<Welcome,Void> listener)
Welcome messages are received after connecting and entering a world
-
await
public void await()
Hack, awaits for welcome message
-
getClient
public Client getClient()
-
enter
public void enter(String world)
Enter a world
-
send
public void send(String arg)
Send a json string to the server
-
send
public void 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 interfaceWebSocket.Listener
-
onText
public CompletionStage<?> onText(WebSocket webSocket, CharSequence data, boolean last)
- Specified by:
onText
in interfaceWebSocket.Listener
-
onError
public void onError(WebSocket webSocket, Throwable error)
- Specified by:
onError
in interfaceWebSocket.Listener
-
onPing
public CompletionStage<?> onPing(WebSocket webSocket, ByteBuffer message)
- Specified by:
onPing
in interfaceWebSocket.Listener
-
onClose
public CompletionStage<?> onClose(WebSocket webSocket, int statusCode, String reason)
- Specified by:
onClose
in interfaceWebSocket.Listener
-
-