Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/npm-publish-next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
node-version: '22'
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm ci --ignore-scripts
- run: npm run build
- run: npm publish --tag next
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
- name: Create Git Tag
run: |
VERSION=$(node -p "require('./package.json').version")
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git tag v$VERSION
git push origin v$VERSION
12 changes: 10 additions & 2 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
node-version: '22'
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm ci --ignore-scripts
- run: npm run build
- run: npm publish
- name: Create Git Tag
run: |
VERSION=$(node -p "require('./package.json').version")
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git tag v$VERSION
git push origin v$VERSION
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
.npmrc

.DS_Store
dist/
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ignore-scripts=true
18 changes: 18 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"bracketSameLine": false,
"arrowParens": "always",
"jsxSingleQuote": false,
"printWidth": 128,
"quoteProps": "as-needed",
"bracketSpacing": true,
"svelteSortOrder": "options-scripts-styles-markup",
"svelteStrictMode": false,
"svelteAllowShorthand": true,
"svelteIndentScriptAndStyle": true,
"htmlWhitespaceSensitivity": "ignore"
}
133 changes: 72 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A helper module to connect third-party modules to RealityHub.

## Support Requests
## Support Requests

This repository is for distribution only. For support please visit: [Zero Density Support](https://support.zerodensity.io).

Expand All @@ -21,7 +21,7 @@ The client can be bundled for browsers with a bundling tool (e.g. rollup).
### Connecting to Hub

```js
const { BrokerClient } = require('@zerodensity/realityhub-api');
import { BrokerClient } from '@zerodensity/realityhub-api';

BrokerClient.initModule({
menuTitle: '<menu title>',
Expand All @@ -40,7 +40,8 @@ BrokerClient.initModule({
### Listing Reality 5 (API v1.2+) engines

```js
brokerClient.api.hub.reality5_1_2_world.listEngines()
brokerClient.api.hub.reality5_1_2_world
.listEngines()
.then((engines) => {
console.log(engines);

Expand All @@ -65,28 +66,29 @@ brokerClient.api.hub.reality5_1_2_world.listEngines()
### Listing the nodes running on an Reality 5 engine (API v1.2+)

```js
brokerClient.api.hub.reality5_1_2_world.getNodes(79 /* id of the engine */)
brokerClient.api.hub.reality5_1_2_world
.getNodes(79 /* id of the engine */)
.then((nodes) => {
console.log(nodes);

/**
* {
* ...
* // The keys are the NodePath
* Cyclorama: {
* ...
* Functions: {
* // The keys are the FunctionPath
* 'Cyclorama/AddProjection': {...},
* 'Cyclorama/ClearProjection': {...},
* }
* ...
* }
* ...
* }
*/

// NOTE: For backward compatiblity, the NodePath and FunctionPath omit the leading '/'.
* {
* ...
* // The keys are the NodePath
* Cyclorama: {
* ...
* Functions: {
* // The keys are the FunctionPath
* 'Cyclorama/AddProjection': {...},
* 'Cyclorama/ClearProjection': {...},
* }
* ...
* }
* ...
* }
*/

// NOTE: For backward compatiblity, the NodePath and FunctionPath omit the leading '/'.
})
.catch((ex) => console.trace(ex));
```
Expand All @@ -103,11 +105,16 @@ of engine IDs. If `engineIds` is not supplied then the function will be called o
* @param {string} params.NodePath
* @param {string} params.PropertyPath
* @param {number} [engineIds] - optional, default is all engines
*/
brokerClient.api.hub.reality5_1_2_world.callNodeFunction({
NodePath: '/Cyclorama',
FunctionPath: '/Cyclorama/AddProjection',
}, [/* engine id = */ 79]).catch((ex) => console.trace(ex));
*/
brokerClient.api.hub.reality5_1_2_world
.callNodeFunction(
{
NodePath: '/Cyclorama',
FunctionPath: '/Cyclorama/AddProjection',
},
[/* engine id = */ 79]
)
.catch((ex) => console.trace(ex));
```

### Setting a Node's Property Value
Expand Down Expand Up @@ -136,32 +143,35 @@ brokerClient.api.hub.reality5_1_2_world.setNodeProperty({
You can use `interpolate(params[, engineIds])` to interpolate a node's property value. `engineIds` is an array of engine IDs. If `engineIds` not supplied then all of the engines will receive the same interpolate command.

```js
brokerClient.api.hub.reality5_1_2_world.interpolate({
NodePath: '/Add_f32',
PropertyPath: 'X',
StartValue: 5.0, // optional, default is the current value
EndValue: 10.0,
Duration: 2000, // in milliseconds, optional, default is 0
Delay: 2000, // in milliseconds, optional, default is 0

/** @type {'Jump' | 'Linear' | 'EaseIn' | 'EaseOut' | 'EaseInOut'} */
InterpType: 'EaseIn', // optional, default is 'Jump'
}, [/* engine id = */ 79]).catch((ex) => console.trace(ex));
brokerClient.api.hub.reality5_1_2_world
.interpolate(
{
NodePath: '/Add_f32',
PropertyPath: 'X',
StartValue: 5.0, // optional, default is the current value
EndValue: 10.0,
Duration: 2000, // in milliseconds, optional, default is 0
Delay: 2000, // in milliseconds, optional, default is 0

/** @type {'Jump' | 'Linear' | 'EaseIn' | 'EaseOut' | 'EaseInOut'} */
InterpType: 'EaseIn', // optional, default is 'Jump'
},
[/* engine id = */ 79]
)
.catch((ex) => console.trace(ex));
```

### Getting a Node's Property Value

You can use `getNodeProperty(params[, engineIds])` to get a node's property value. `engineIds` is an array of engine IDs. If `engineIds` not supplied then all of the engines will be queried. That is why this method returns an array of promises.

```js
brokerClient.api.hub.reality5_1_2_world.getNodeProperty(
{ NodePath: '/Add_f32', PropertyPath: 'X', },
[/* engine id = */ 79]
)
.then((results) => {
console.log(results[0].Value);
})
.catch((ex) => console.trace(ex));
brokerClient.api.hub.reality5_1_2_world
.getNodeProperty({ NodePath: '/Add_f32', PropertyPath: 'X' }, [/* engine id = */ 79])
.then((results) => {
console.log(results[0].Value);
})
.catch((ex) => console.trace(ex));
```

### Registering Your Own Methods to RealityHub
Expand Down Expand Up @@ -194,28 +204,29 @@ function longTask(taskDuration) {
}

// Let's register these as our API methods
brokerClient.api.exampleCompany.exampleModule.registerAPIHandlers({
addNumbers,
multiplyNumbers,
performSlowTask: longTask,
}).catch((ex) => console.trace(ex));
brokerClient.api.exampleCompany.exampleModule
.registerAPIHandlers({
addNumbers,
multiplyNumbers,
performSlowTask: longTask,
})
.catch((ex) => console.trace(ex));
```

```js
// client.js
brokerClient.api.exampleCompany.exampleModule.addNumbers(3, 5)
.then((result) => {
console.log('The result of addNumbers() is', result);
});
brokerClient.api.exampleCompany.exampleModule.addNumbers(3, 5).then((result) => {
console.log('The result of addNumbers() is', result);
});

brokerClient.api.exampleCompany.exampleModule.performAsyncMultiplication(3, 5)
.then((result) => {
console.log('The result of performAsyncMultiplication() is', result);
});
brokerClient.api.exampleCompany.exampleModule.performAsyncMultiplication(3, 5).then((result) => {
console.log('The result of performAsyncMultiplication() is', result);
});

// Default timeout for API requests is 2 seconds. We need to specify a longer timeout for our slow async task.
const timeout = 10 * 1000; // 10 seconds
brokerClient.api.exampleCompany.exampleModule.callTimeout(timeout)
brokerClient.api.exampleCompany.exampleModule
.callTimeout(timeout)
.slowAsyncTask(5)
.then((result) => console.log('Slow async task returned:', result));
```
Expand All @@ -229,7 +240,7 @@ brokerClient.api.exampleCompany.exampleModule.callTimeout(timeout)
setInterval(() => {
// A random number between 0 and 1000.
const randomNumber = Math.round(Math.random() * 1000);
brokerClient.api.exampleCompany.exampleModule.emit('randomnumber', randomNumber);
brokerClient.api.exampleCompany.exampleModule.emit('randomnumber', randomNumber);
}, 1000);
```

Expand All @@ -238,7 +249,7 @@ setInterval(() => {

brokerClient.api.exampleCompany.exampleModule.on('randomnumber', (randomNumber) => {
console.log('Received a random number from the server', randomNumber);
});
});
```

### Questions and Feedback
Expand Down
Loading