Class: VRSpace

VRSpace()

Main client API class, no external dependencies. Provides send methods to send messages to the server, to be distributed to other clients. Listeners receive remote events.

Constructor

new VRSpace()

Source:

Classes

VRSpace

Members

debug

Debug logging, default false
Source:

me

Representation of own Client, available once connection is established
Source:

responseListener

Listener to response to a command.
Source:

scene

Map containing all objects in the scene
Source:

ws

Underlying websocket
Source:

Methods

(async) _createSharedObject(command, obj, className)

Common code for createSharedObject and createScriptedObject
Parameters:
Name Type Description
command either Add or Share
obj the new VRObject, containing all properties
className optional class name to create, defaults to obj.className if exists, otherwise VRObject
Source:
Returns:
Promise with the created VRObject instance

addConnectionListener()

Add a connection listener that gets notified when connection is activated/broken. Callback is passed boolean argument indicating connection state.
Source:

addDataListener()

Add a data listener that receives everything from the server (JSON string argument)
Source:

addErrorListener()

Add error listener, notified when server sends error notifications. Error listener is passed the string containing the server error message, e.g. java exception.
Source:

addSceneListener()

Add a scene listener that gets notified when the scene is changed. Scene listeners receive SceneEvent argument for each change.
Source:

addWelcomeListener()

Add a Welcome listener, notified when entering a world. The listener receives Welcome object.
Source:

call(message, callback)

Perform a synchronous call.
Parameters:
Name Type Description
message JSON string to send
callback function to execute upon receiving the response
Source:

connect(url)

Connect to the server, attach listeners.
Parameters:
Name Type Description
url optional websocket url, defaults to /vrspace/client on the same server
Source:

createField()

Create a local field of an object existing on the server FIXME Obsolete
Source:

(async) createScriptedObject(obj, callback, className)

Create a shared scripted object. The server determines which scripts are allowed, so this sends different command than createSharedObject.
Parameters:
Name Type Description
obj the new VRObject, containing all properties
callback called when shared object is received
className optional class name to create, defaults to obj.className if exists, otherwise VRObjects
Source:
Returns:
Promise with the created VRObject instance

(async) createSharedObject(obj, className)

Share an object.
Parameters:
Name Type Description
obj the new VRObject, containing all properties
className optional class name to create, defaults to obj.className if exists, otherwise VRObjects
Source:
Returns:
Promise with the created VRObject instance

deleteSharedObject(obj, callback)

Delete a shared object.
Parameters:
Name Type Description
obj to be removed from the server
callback optional, called after removal from the server
Source:

disconnect()

Disconnect, notify connection listeners
Source:

getScene(filter)

Return the current scene, optionally filtered
Parameters:
Name Type Description
filter string to match current members, usually class name, or function that takes VRObject as argument
Source:

newInstance(className)

Factory method
Parameters:
Name Type Description
className shared class name
Source:
Returns:
new shared object instance

receive()

Called when a message is received from the server. JSON message is converted to an object, then depending on object type, handled as one of: message to an object in the scene, add an object message, remove an object, error message, response to a command
Source:

removeSceneListener()

Remove a scene listener.
Source:

removeWelcomeListener(callback)

Remove welcome listener
Parameters:
Name Type Description
callback listener to remove
Source:

sendChanges(obj, changes)

Send changes to an object
Parameters:
Name Type Description
obj VRObject that changes
changes array containing field/value pairs
Source:

sendCommand(command, args)

Send a command to the server
Parameters:
Name Type Description
command to execute
args optional object with command arguments
Source:

sendEvent(obj, changes)

Send changes to an object
Parameters:
Name Type Description
obj VRObject that changes
changes object containing changed fields
Source:

sendMy(field, value)

Send notification of own property changes
Parameters:
Name Type Description
field name of member variable that has changed
value new field value
Source:

sendMyChanges(changes)

Send changes to own avatar
Parameters:
Name Type Description
changes array with field/value pairs
Source:

sendMyEvent(changes)

Send changes to own avatar
Parameters:
Name Type Description
changes object containing changed field(s)
Source:

setToken(name, value)

Set a client token e.g. required to enter a world
Parameters:
Name Type Description
name token name
value token value
Source:

(async) startStreaming()

Experimental. Executes StreamingSession start command on the server that returns session token, the executes callback, passing the token to it
Source:

stopStreaming()

Experimental. Executes StreamingSession stop command on the server. CHECKME Since the server manages streaming sessions anyway, this may not be needed at all.
Source:

stringifyPair(field, value)

Convert a key/value pair to json string. FIXME improperly stringifies objects having properties x, _x, or w. Properties other than x,y,z,w will be ignored. See stringifyVector and stringifyQuaternion. This is essentially workaround for bablyon types, e.g. Vector3, that have _x, _y, _z properties.
Parameters:
Name Type Description
field name of the field
value string, object or number to convert
Source:

stringifyQuaternion(vec)

Convert a quaternion to json string
Parameters:
Name Type Description
vec object having x,y,z,w properties
Source:

stringifyVector(vec)

Convert a vector to json string
Parameters:
Name Type Description
vec object having x,y,z properties
Source: