@zerodensity/realityhub-api 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
name: Publish Package to NPM (tag next)
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
|
|
6
|
+
jobs:
|
|
7
|
+
publish-npm:
|
|
8
|
+
name: Publish Job
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v4
|
|
12
|
+
- uses: actions/setup-node@v4
|
|
13
|
+
with:
|
|
14
|
+
node-version: '20'
|
|
15
|
+
registry-url: https://registry.npmjs.org/
|
|
16
|
+
- run: npm ci
|
|
17
|
+
- run: npm publish --tag next
|
|
18
|
+
env:
|
|
19
|
+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
|
@@ -10,12 +10,13 @@ jobs:
|
|
|
10
10
|
name: Publish Job
|
|
11
11
|
runs-on: ubuntu-latest
|
|
12
12
|
steps:
|
|
13
|
-
- uses: actions/checkout@
|
|
14
|
-
- uses: actions/setup-node@
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
- uses: actions/setup-node@v4
|
|
15
15
|
with:
|
|
16
|
-
node-version:
|
|
16
|
+
node-version: '20'
|
|
17
17
|
registry-url: https://registry.npmjs.org/
|
|
18
18
|
- run: npm ci
|
|
19
19
|
- run: npm publish
|
|
20
|
+
- run: npm publish --tag latest
|
|
20
21
|
env:
|
|
21
22
|
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
package/README.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
A helper module to connect third-party modules to RealityHub.
|
|
4
4
|
|
|
5
|
+
## Support Requests
|
|
6
|
+
|
|
7
|
+
This repository is for distribution only. For support please visit: [Zero Density Support](https://support.zerodensity.io).
|
|
8
|
+
|
|
5
9
|
## Installation
|
|
6
10
|
|
|
7
11
|
```bash
|
|
@@ -28,14 +32,6 @@ BrokerClient.initModule({
|
|
|
28
32
|
host: '127.0.0.1',
|
|
29
33
|
port: 3000,
|
|
30
34
|
},
|
|
31
|
-
// optional error handler
|
|
32
|
-
// brokerClient will log the error if not provided
|
|
33
|
-
onError: (error, brokerClient) => {
|
|
34
|
-
// you may destroy the instance (and retry calling initModule() later)
|
|
35
|
-
// brokerClient.destroy();
|
|
36
|
-
// it will try to recover otherwise
|
|
37
|
-
console.error(error.message);
|
|
38
|
-
}
|
|
39
35
|
}).then((brokerClient) => {
|
|
40
36
|
// brokerClient is connected to RealityHub and ready to use
|
|
41
37
|
});
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zerodensity/realityhub-api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "RealityHub API Javascript Implementation",
|
|
5
5
|
"main": "src/index.js",
|
|
6
|
+
"scripts": {},
|
|
6
7
|
"repository": {
|
|
7
8
|
"type": "git",
|
|
8
9
|
"url": "git+ssh://git@github.com/zerodensity/realityhub-api.git"
|
package/src/lib/BrokerBase.js
CHANGED
|
@@ -19,12 +19,20 @@ const EventEmitter = require('events');
|
|
|
19
19
|
const BrokerError = require('./BrokerError.js');
|
|
20
20
|
const onceMultiple = require('./onceMultiple.js');
|
|
21
21
|
|
|
22
|
-
const DEFAULT_MAX_WS_PACKET_SIZE =
|
|
22
|
+
const DEFAULT_MAX_WS_PACKET_SIZE = 20 /*MB*/ * 1024 * 1024;
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* BrokerBase constructor
|
|
26
|
+
* @param {object} params Parameters
|
|
27
|
+
* @param {string} [params.moduleName] Module name
|
|
28
|
+
* @param {number} [params.maxPacketSize] Maximum websocket packet size
|
|
29
|
+
* @param {Logger} [params.logger] Logger instance
|
|
30
|
+
*/
|
|
24
31
|
module.exports = class BrokerBase extends EventEmitter {
|
|
25
32
|
constructor(params) {
|
|
26
33
|
super();
|
|
27
34
|
this.moduleName = params.moduleName;
|
|
35
|
+
this.maxPacketSize = params.maxPacketSize || DEFAULT_MAX_WS_PACKET_SIZE;
|
|
28
36
|
|
|
29
37
|
this.logger = params.logger;
|
|
30
38
|
|
|
@@ -34,7 +42,6 @@ module.exports = class BrokerBase extends EventEmitter {
|
|
|
34
42
|
this.messageTimeout = 2000;
|
|
35
43
|
|
|
36
44
|
this.overridenTimeout = NaN; // NaN = use the implementation
|
|
37
|
-
this.destroyed = false;
|
|
38
45
|
|
|
39
46
|
try {
|
|
40
47
|
if (typeof window != 'undefined' && typeof localStorage != 'undefined') {
|
|
@@ -53,18 +60,16 @@ module.exports = class BrokerBase extends EventEmitter {
|
|
|
53
60
|
|
|
54
61
|
try {
|
|
55
62
|
if (typeof window != 'undefined' && typeof localStorage != 'undefined') {
|
|
56
|
-
maxPacketSizeRead
|
|
63
|
+
maxPacketSizeRead ||= Number(localStorage.getItem('MAX_WS_PACKET_SIZE'));
|
|
57
64
|
} else if (process && process.env) {
|
|
58
|
-
maxPacketSizeRead
|
|
65
|
+
maxPacketSizeRead ||= Number(process.env.MAX_WS_PACKET_SIZE);
|
|
59
66
|
}
|
|
60
|
-
|
|
61
|
-
maxPacketSizeRead = Math.max(maxPacketSizeRead, 1024000);
|
|
62
67
|
} catch (ex) {
|
|
63
68
|
const logger = this.logger || console;
|
|
64
69
|
logger.error(`Cannot read maxPacketSize from either localStorage or env, defaulting to ${maxPacketSizeRead}`)
|
|
65
70
|
}
|
|
66
71
|
|
|
67
|
-
this.maxPacketSize = maxPacketSizeRead
|
|
72
|
+
this.maxPacketSize = Math.max(this.maxPacketSize, maxPacketSizeRead);
|
|
68
73
|
|
|
69
74
|
if(this.maxPacketSize !== DEFAULT_MAX_WS_PACKET_SIZE) {
|
|
70
75
|
const logger = this.logger || console;
|
|
@@ -74,10 +79,6 @@ module.exports = class BrokerBase extends EventEmitter {
|
|
|
74
79
|
this.initProxy();
|
|
75
80
|
}
|
|
76
81
|
|
|
77
|
-
get errorEmittingEnabled() {
|
|
78
|
-
return this.listeners('error').length > 0;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
82
|
getMethodProxy(vendorName, moduleName, options) {
|
|
82
83
|
options = {
|
|
83
84
|
timeout: 2000,
|
|
@@ -435,11 +436,6 @@ module.exports = class BrokerBase extends EventEmitter {
|
|
|
435
436
|
try {
|
|
436
437
|
responseMessage = await onceMultiple(this, [`response::${message.id}`], this.overridenTimeout || message.timeout || this.messageTimeout);
|
|
437
438
|
} catch (ex) {
|
|
438
|
-
if (this.errorEmittingEnabled) {
|
|
439
|
-
this.emit('error', ex);
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
439
|
const logger = this.logger || console;
|
|
444
440
|
logger.debug(`${this.moduleName} failed to send message ${message.type} to ${message.targetModuleName || ''}`);
|
|
445
441
|
return;
|
|
@@ -493,11 +489,6 @@ module.exports = class BrokerBase extends EventEmitter {
|
|
|
493
489
|
excludedClients: options.excludedClients || [],
|
|
494
490
|
})
|
|
495
491
|
.catch((err) => {
|
|
496
|
-
if (this.errorEmittingEnabled) {
|
|
497
|
-
this.emit('error', err);
|
|
498
|
-
return;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
492
|
console.error(`Couldn't emit ${fullyQualifiedName}`);
|
|
502
493
|
|
|
503
494
|
if (err.code !== 'TIMEOUT') {
|
|
@@ -508,6 +499,5 @@ module.exports = class BrokerBase extends EventEmitter {
|
|
|
508
499
|
|
|
509
500
|
destroy() {
|
|
510
501
|
this.removeAllListeners();
|
|
511
|
-
this.destroyed = true;
|
|
512
502
|
}
|
|
513
503
|
}
|
package/src/lib/BrokerClient.js
CHANGED
|
@@ -36,6 +36,8 @@ module.exports = class BrokerClient extends BrokerBase {
|
|
|
36
36
|
* BrokerClient constructor
|
|
37
37
|
* @param {object} params Parameters
|
|
38
38
|
* @param {string} params.webSocketURL WebSocket URL
|
|
39
|
+
* @param {string} [params.moduleName] Module name
|
|
40
|
+
* @param {number} [params.maxPacketSize] Maximum websocket packet size
|
|
39
41
|
* @param {Logger} [params.logger] Logger instance
|
|
40
42
|
* @param {boolean} [params.isDuplicate] [Private property, used internally]
|
|
41
43
|
* @param {boolean} [params.parent] [Private property, used internally]
|
|
@@ -89,14 +91,11 @@ module.exports = class BrokerClient extends BrokerBase {
|
|
|
89
91
|
* @returns {Promise}
|
|
90
92
|
*/
|
|
91
93
|
getConnectPromise() {
|
|
92
|
-
return new Promise((resolve
|
|
94
|
+
return new Promise((resolve) => {
|
|
93
95
|
const looper = setInterval(() => {
|
|
94
96
|
if (this.connected) {
|
|
95
97
|
clearInterval(looper);
|
|
96
98
|
resolve();
|
|
97
|
-
} else if (this.destroyed) {
|
|
98
|
-
clearInterval(looper);
|
|
99
|
-
reject(new Error('BrokerClient is destroyed'));
|
|
100
99
|
}
|
|
101
100
|
}, 0);
|
|
102
101
|
});
|
|
@@ -213,11 +212,6 @@ module.exports = class BrokerClient extends BrokerBase {
|
|
|
213
212
|
try {
|
|
214
213
|
await this.handleMessage(event.data, this.socket);
|
|
215
214
|
} catch (ex) {
|
|
216
|
-
if (this.errorEmittingEnabled) {
|
|
217
|
-
this.emit('error', ex);
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
215
|
console.trace(ex);
|
|
222
216
|
}
|
|
223
217
|
}
|
|
@@ -257,11 +251,7 @@ module.exports = class BrokerClient extends BrokerBase {
|
|
|
257
251
|
try {
|
|
258
252
|
entry.eventHandler(...message.data);
|
|
259
253
|
} catch (ex) {
|
|
260
|
-
|
|
261
|
-
this.emit('error', ex);
|
|
262
|
-
} else {
|
|
263
|
-
this.logger.warn(ex);
|
|
264
|
-
}
|
|
254
|
+
this.logger.warn(ex);
|
|
265
255
|
} finally {
|
|
266
256
|
if (entry.once) {
|
|
267
257
|
this.unsubscribeFromAPIEvent(subscribedEvent, entry.eventHandler);
|
|
@@ -411,11 +401,6 @@ module.exports = class BrokerClient extends BrokerBase {
|
|
|
411
401
|
}
|
|
412
402
|
}
|
|
413
403
|
} catch (ex) {
|
|
414
|
-
if (this.errorEmittingEnabled) {
|
|
415
|
-
this.emit('error', ex);
|
|
416
|
-
return;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
404
|
if (ex.code === 'TIMEOUT') {
|
|
420
405
|
console.warn('Message timed out.');
|
|
421
406
|
console.log(message);
|
|
@@ -530,11 +515,6 @@ module.exports = class BrokerClient extends BrokerBase {
|
|
|
530
515
|
}
|
|
531
516
|
}
|
|
532
517
|
} catch (ex) {
|
|
533
|
-
if (this.errorEmittingEnabled) {
|
|
534
|
-
this.emit('error', ex);
|
|
535
|
-
return;
|
|
536
|
-
}
|
|
537
|
-
|
|
538
518
|
console.trace(ex.message);
|
|
539
519
|
}
|
|
540
520
|
}
|
|
@@ -549,11 +529,7 @@ module.exports = class BrokerClient extends BrokerBase {
|
|
|
549
529
|
}
|
|
550
530
|
|
|
551
531
|
if (!this.isDuplicate) {
|
|
552
|
-
|
|
553
|
-
this.emit('error', err);
|
|
554
|
-
} else {
|
|
555
|
-
this.logger.trace(err);
|
|
556
|
-
}
|
|
532
|
+
this.logger.trace(err);
|
|
557
533
|
}
|
|
558
534
|
|
|
559
535
|
if (!this.isDuplicate) {
|
|
@@ -622,11 +598,6 @@ module.exports = class BrokerClient extends BrokerBase {
|
|
|
622
598
|
|
|
623
599
|
return Promise.all(promises);
|
|
624
600
|
} catch (ex) {
|
|
625
|
-
if (this.errorEmittingEnabled) {
|
|
626
|
-
this.emit('error', ex);
|
|
627
|
-
return;
|
|
628
|
-
}
|
|
629
|
-
|
|
630
601
|
console.trace(ex.message);
|
|
631
602
|
}
|
|
632
603
|
}
|
|
@@ -668,11 +639,6 @@ module.exports = class BrokerClient extends BrokerBase {
|
|
|
668
639
|
super.destroy();
|
|
669
640
|
}
|
|
670
641
|
} catch (ex) {
|
|
671
|
-
if (this.errorEmittingEnabled) {
|
|
672
|
-
this.emit('error', ex);
|
|
673
|
-
return;
|
|
674
|
-
}
|
|
675
|
-
|
|
676
642
|
console.trace(ex.message);
|
|
677
643
|
}
|
|
678
644
|
}
|
|
@@ -709,12 +675,6 @@ module.exports = class BrokerClient extends BrokerBase {
|
|
|
709
675
|
return this.registerHandlersToRemote(remote);
|
|
710
676
|
}
|
|
711
677
|
|
|
712
|
-
/**
|
|
713
|
-
* @typedef {function} ErrorCallback
|
|
714
|
-
* @param {Error} error
|
|
715
|
-
* @param {BrokerClient} brokerClient
|
|
716
|
-
/
|
|
717
|
-
|
|
718
678
|
/**
|
|
719
679
|
* Third-party modules can use this method to initialize a BrokerClient
|
|
720
680
|
* and register themselves to RealityHub.
|
|
@@ -733,19 +693,12 @@ module.exports = class BrokerClient extends BrokerBase {
|
|
|
733
693
|
* @param {{ host: string, port: number }} params.hub RealityHub connection parameters
|
|
734
694
|
* @param {string} params.hub.host RealityHub hostname or IP address
|
|
735
695
|
* @param {string} params.hub.port RealityHub port
|
|
736
|
-
* @param {ErrorCallback} [params.onError] Error handler callback, BrokerClient will catch the errors if not specified
|
|
737
696
|
* @returns {Promise<BrokerClient, Error>} A BrokerClient instance.
|
|
738
697
|
*/
|
|
739
698
|
static async initModule(params) {
|
|
740
|
-
const { moduleName, serverURL, hub, webSocketURL = '/core', clientModuleName, menuTitle
|
|
699
|
+
const { moduleName, serverURL, hub, webSocketURL = '/core', clientModuleName, menuTitle } = params;
|
|
741
700
|
const hubClient = new BrokerClient({ moduleName, webSocketURL });
|
|
742
701
|
|
|
743
|
-
if (typeof onError === 'function') {
|
|
744
|
-
hubClient.on('error', (error) => {
|
|
745
|
-
onError(error, hubClient);
|
|
746
|
-
});
|
|
747
|
-
}
|
|
748
|
-
|
|
749
702
|
hubClient.connect(hub);
|
|
750
703
|
await hubClient.getConnectPromise();
|
|
751
704
|
if (!serverURL) return hubClient;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
name: Publish Package to Github Packages
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
workflow_dispatch:
|
|
5
|
-
|
|
6
|
-
jobs:
|
|
7
|
-
publish-gpr:
|
|
8
|
-
name: Publish Job
|
|
9
|
-
runs-on: ubuntu-latest
|
|
10
|
-
steps:
|
|
11
|
-
- uses: actions/checkout@v2
|
|
12
|
-
- uses: actions/setup-node@v1
|
|
13
|
-
with:
|
|
14
|
-
node-version: 14
|
|
15
|
-
registry-url: https://npm.pkg.github.com/
|
|
16
|
-
- run: npm ci
|
|
17
|
-
- run: npm publish
|
|
18
|
-
env:
|
|
19
|
-
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
|