Classes
Members
autoReconnect
Reconnect automatically, experimental
- Source:
debug
Debug logging, default false
- Source:
me :User
Representation of own Client, available once the connection is established
Type:
- Source:
responseListeners
Listeners to responses to commands, processed one at a time.
- Source:
scene :Map.<string, VRObject>
Map containing all objects in the scene
Type:
- Map.<string, VRObject>
- Source:
url :string
Connection URL, set once connection is established
Type:
- string
- Source:
ws
Underlying websocket
- Source:
Methods
addActivationListener(callback)
Add an activation listener, that gets called when active property of a VRObject changes.
Lister needs to update event model then, i.e. start/stop listening to events from the object.
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
* |
- Source:
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(callback)
Add a scene listener that gets notified when the scene is changed.
Scene listeners receive SceneEvent argument for each change.
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
sceneCallback |
- Source:
addWelcomeListener()
Add a Welcome listener, notified when entering a world.
The listener receives Welcome object.
- Source:
(async) call(message, callback)
Perform a synchronous call, used internally by callCommand etc.
Enqueues callback, and executes it when the response to command arrives.
Successful call chaining depends on server executing them sequentially.
REST API calls are better option for synchronous calls.
Parameters:
| Name | Type | Description |
|---|---|---|
message |
string | JSON string to send |
callback |
* | function to execute upon receiving the response |
- Source:
callAsync(message) → {Promise}
Perfom a synchronous call.
Parameters:
| Name | Type | Description |
|---|---|---|
message |
string | JSON string to send |
- Source:
Returns:
resolves with response from the server
- Type
- Promise
callCommand(command, callback)
Send a command to the server
Parameters:
| Name | Type | Description |
|---|---|---|
command |
string | to execute |
callback |
function that's called with command return value |
- Source:
(async) callCommandAsync(command)
Send a command to the server
Parameters:
| Name | Type | Description |
|---|---|---|
command |
string | to execute |
- Source:
connect(urlopt) → {Promise}
Connect to the server, attach connection listeners and data listeners to the websocket.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
url |
string |
<optional> |
optional websocket url, defaults to /vrspace/client on the same server |
- Source:
Returns:
promise resolved once the connection is successful
- Type
- Promise
createField()
Create a local field of an object existing on the server FIXME Obsolete
- Source:
(async) createSharedObject(obj, classNameopt, temporaryopt) → {Promise.<VRObject>}
Share an object.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
obj |
VRObject | the new VRObject, containing all properties | |
className |
string | undefined |
<optional> |
optional class name to create, defaults to obj.className if exists, otherwise VRObject |
temporary |
boolean |
<optional> |
Create temporary object. Defaults to true for scripts. |
- Source:
Returns:
Promise with the created VRObject instance
- Type
- Promise.<VRObject>
deleteSharedObject(obj, callbackopt)
Delete a shared object.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
obj |
ID | to be removed from the server | |
callback |
* |
<optional> |
optional, called after removal from the server |
- Source:
disconnect()
Disconnect, notify connection listeners
- Source:
enter(world, tokenopt)
Enter a world, optionally with a token (that may be required for private worlds).
The server sends Welcome message, that's supposed to be processed with Welcome listeners.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
world |
string | Name of the world to enter | |
token |
string |
<optional> |
optional token value |
- Source:
enterAsync(world, tokenopt) → {Promise.<Welcome>}
Enter a world, optionally with a token (that may be required for private worlds).
The servers sends back Welcome response message, that is resolved in Promise.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
world |
string | Name of the world to enter | |
token |
string |
<optional> |
optional token value |
- Source:
Returns:
promise with the welcome message
- Type
- Promise.<Welcome>
getScene(filter) → {Map.<string, VRObject>}
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:
Returns:
scene
- Type
- Map.<string, VRObject>
handleActivate(activate)
Handle Activate message: update the object and call listeners.
Parameters:
| Name | Type | Description |
|---|---|---|
activate |
Activate |
- 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:
removeActivationListener()
Remove an activation listener.
- Source:
removeByID(id)
Remove object from the scene and notify listeners
Parameters:
| Name | Type | Description |
|---|---|---|
id |
ID |
- 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:
removeObject(objectId)
Remove object, used internally
Parameters:
| Name | Type | Description |
|---|---|---|
objectId |
object | object taken from Remove command, e.g. {User:123} |
- 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 |
string | to execute |
args |
Object | optional object with command arguments |
- Source:
sendEvent(obj, changes)
Send changes to an object
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
ID | VRObject that changes |
changes |
Object | object containing changed fields |
- Source:
sendMy(field, value)
Send notification of own property changes
Parameters:
| Name | Type | Description |
|---|---|---|
field |
string | 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 | object containing changed fields |
- Source:
(async) sessionStart() → {Promise}
Start the session: sends Session command to the server
- Source:
Returns:
resolves when server responds
- Type
- Promise
setToken(name, value)
Set a client token e.g. required to enter a world
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | token name |
value |
string | 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: