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:

addGroupListener(callback)

Add a group listener, notified when entering a world. The listener receives Welcome object.
Parameters:
Name Type Description
callback function
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:

callCommand(command, callback)

Send a command to the server
Parameters:
Name Type Description
command to execute
callback function that's called with command return value
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:

handleAdd(add)

Handle Add message: add every object to the scene, and notify listeners. Calls addObject.
Parameters:
Name Type Description
add Add Add command containing addedd objects
Source:

handleError(error)

Handle server error: log the error, and notify error listeners.
Parameters:
Name Type Description
error object object containing error message received from the server
Source:

handleEvent(message)

Handle event of a shared VRObject: find the object in the scene, apply changes, notify listeners.
Parameters:
Name Type Description
message VREvent containing object id and changes
Source:

handleGroupEvent(event)

Handle a group event, simply forward the event to all groupListeners.
Parameters:
Name Type Description
event GroupEvent
Source:

handleRemove(remove)

Handle Remove message: remove every object from the scene, and notify listeners. Calls removeObject.
Parameters:
Name Type Description
remove Remove Remove command containing list of object IDs to remove
Source:

handleResponse(response)

Handle response to command: if responseListener is installed, execute it with the message, ignore otherwise.
Parameters:
Name Type Description
response object object containing response to the command, can be anything, depending on the command.
Source:

handleWelcome(welcome)

Handle Welcome message: create own user object, and notify welcome listeners. Adds all permanent objects to the scene.
Parameters:
Name Type Description
welcome Welcome the Welcome message.
Source:

newInstance(className)

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

receive(message)

Called when a message is received from the server. JSON message is converted to an object, then depending on object type, forwarded to one of this.messageHandlers.
Parameters:
Name Type Description
message String text message from the server over the websocket
Source:

removeErrorListener(callback)

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

removeGroupListener(callback)

Remove group listener
Parameters:
Name Type Description
callback listener to remove
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: