new OpenSpaceApi(socket)
Construct an instance of the OpenSpace API.
Parameters:
| Name | Type | Description |
|---|---|---|
socket |
Object | An instance of Socket or WebSocket. The socket should not be connected prior to calling this constructor. |
Methods
(async) authenticate(secret)
Authenticate this client.
This must be done if the client is not whitelisted in openspace.cfg.
Parameters:
| Name | Type | Description |
|---|---|---|
secret |
string | The secret used to authenticate with OpenSpace. |
connect()
Connect to OpenSpace.
disconnect()
Disconnect from OpenSpace.
(async) executeLuaFunction(function, getReturnValue) → {*}
Execute a lua function from the OpenSpace library
Parameters:
| Name | Type | Description |
|---|---|---|
function |
string | The lua function to execute (for example `openspace.addSceneGraphNode`). |
getReturnValue |
string | Specified whether the return value should be collected. |
Returns:
The return value of the script, if `getReturnValue` is true, otherwise undefined.
- Type
- *
(async) executeLuaScript(script, getReturnValue) → {*}
Execute a lua script
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
script |
string | The lua script to execute. | |
getReturnValue |
string | true | Specified whether the return value should be collected. |
Returns:
The return value of the script, if `getReturnValue` is true, otherwise undefined.
- Type
- *
(async) getDocumentation(type) → {Object}
Get a property
Parameters:
| Name | Type | Description |
|---|---|---|
type |
string | The type of documentation to get. For available types, check documentationtopic.cpp in OpenSpace's server module. |
Returns:
An object representing the requested documentation.
- Type
- Object
(async) getProperty(property) → {*}
Get a property
Parameters:
| Name | Type | Description |
|---|---|---|
property |
string | The URI of the property to set. |
Returns:
The value of the property.
- Type
- *
(async) library() → {Object}
Get an object representing the OpenSpace lua library.
Returns:
The lua library, mapped to async JavaScript functions.
- Type
- Object
onConnect(callback)
Set connect callback.
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
function | The function to execute when connection is established. |
onDisconnect(callback)
Set disconnect callback.
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
function | The function to execute when socket is disconnected. |
setProperty(property, value)
Set a property
Parameters:
| Name | Type | Description |
|---|---|---|
property |
string | The URI of the property to set. |
value |
* | The value to set the property to. |
startTopic(type) → {Topic}
Initialize a new channel of communication
Parameters:
| Name | Type | Description |
|---|---|---|
type |
string | A string specifying the type of topic to construct. See OpenSpace's server module for available topic types. |
Returns:
- An object representing the topic.
- Type
- Topic
subscribeToProperty(property) → {Topic}
Subscribe to a property
Parameters:
| Name | Type | Description |
|---|---|---|
property |
string | The URI of the property. |
Returns:
A topic object to represent the subscription topic.
When cancelled, this object will unsubscribe to the property.
- Type
- Topic