@zerodensity/realityhub-api 1.18.0 → 1.20.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.
- package/package.json +3 -9
- package/src/index.js +6 -4
- package/src/lib/BrokerBase.js +5 -5
- package/src/lib/BrokerClient.js +23 -11
- package/src/lib/BrokerError.js +2 -1
- package/src/lib/RawRequest.js +3 -1
- package/src/lib/consoleLogger.js +1 -1
- package/src/lib/onceMultiple.js +1 -1
- package/src/index.cjs +0 -17
package/package.json
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zerodensity/realityhub-api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.0",
|
|
4
4
|
"description": "RealityHub API Javascript Implementation",
|
|
5
|
-
"type": "module",
|
|
6
5
|
"main": "src/index.js",
|
|
7
|
-
"exports": {
|
|
8
|
-
".": {
|
|
9
|
-
"import": "./src/index.js",
|
|
10
|
-
"require": "./src/index.cjs"
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
6
|
"repository": {
|
|
14
7
|
"type": "git",
|
|
15
8
|
"url": "git+ssh://git@github.com/zerodensity/realityhub-api.git"
|
|
@@ -37,6 +30,7 @@
|
|
|
37
30
|
},
|
|
38
31
|
"homepage": "https://github.com/zerodensity/realityhub-api#readme",
|
|
39
32
|
"dependencies": {
|
|
40
|
-
"uuid": "^11.0.3"
|
|
33
|
+
"uuid": "^11.0.3",
|
|
34
|
+
"ws": "^8.18.0"
|
|
41
35
|
}
|
|
42
36
|
}
|
package/src/index.js
CHANGED
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
// You should have received a copy of the GNU General Public License
|
|
15
15
|
// along with realityhub-api. If not, see <https://www.gnu.org/licenses/>.
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
module.exports = {
|
|
18
|
+
BrokerBase: require('./lib/BrokerBase'),
|
|
19
|
+
BrokerClient: require('./lib/BrokerClient'),
|
|
20
|
+
BrokerError: require('./lib/BrokerError'),
|
|
21
|
+
RawRequest: require('./lib/RawRequest'),
|
|
22
|
+
};
|
package/src/lib/BrokerBase.js
CHANGED
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
// You should have received a copy of the GNU General Public License
|
|
15
15
|
// along with realityhub-api. If not, see <https://www.gnu.org/licenses/>.
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const { v4: uuid } = require('uuid');
|
|
18
|
+
const EventEmitter = require('events');
|
|
19
|
+
const BrokerError = require('./BrokerError.js');
|
|
20
|
+
const onceMultiple = require('./onceMultiple.js');
|
|
21
21
|
|
|
22
22
|
const DEFAULT_MAX_WS_PACKET_SIZE = 50 /*MB*/ * 1024 * 1024;
|
|
23
23
|
|
|
@@ -28,7 +28,7 @@ const DEFAULT_MAX_WS_PACKET_SIZE = 50 /*MB*/ * 1024 * 1024;
|
|
|
28
28
|
* @param {number} [params.maxPacketSize] Maximum websocket packet size
|
|
29
29
|
* @param {Logger} [params.logger] Logger instance
|
|
30
30
|
*/
|
|
31
|
-
|
|
31
|
+
module.exports = class BrokerBase extends EventEmitter {
|
|
32
32
|
constructor(params) {
|
|
33
33
|
super();
|
|
34
34
|
this.moduleName = params.moduleName;
|
package/src/lib/BrokerClient.js
CHANGED
|
@@ -14,14 +14,24 @@
|
|
|
14
14
|
// You should have received a copy of the GNU General Public License
|
|
15
15
|
// along with realityhub-api. If not, see <https://www.gnu.org/licenses/>.
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
const { v4: uuid } = require('uuid');
|
|
18
|
+
const BrokerBase = require('./BrokerBase.js');
|
|
19
|
+
const BrokerError = require('./BrokerError.js');
|
|
20
|
+
const RawRequest = require('./RawRequest.js');
|
|
21
|
+
const consoleLogger = require('./consoleLogger.js');
|
|
22
|
+
const onceMultiple = require('./onceMultiple.js');
|
|
23
|
+
|
|
24
|
+
let ws;
|
|
25
|
+
|
|
26
|
+
const runningInBrowser = typeof window !== 'undefined';
|
|
27
|
+
|
|
28
|
+
if (runningInBrowser) {
|
|
29
|
+
ws = WebSocket;
|
|
30
|
+
} else {
|
|
31
|
+
ws = require('ws');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = class BrokerClient extends BrokerBase {
|
|
25
35
|
/**
|
|
26
36
|
* BrokerClient constructor
|
|
27
37
|
* @param {object} params Parameters
|
|
@@ -127,10 +137,10 @@ export class BrokerClient extends BrokerBase {
|
|
|
127
137
|
if (typeof process !== "undefined" && process.versions != null && process.versions.node != null) {
|
|
128
138
|
const NODE_TLS_REJECT_UNAUTHORIZED = process.env.NODE_TLS_REJECT_UNAUTHORIZED;
|
|
129
139
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
|
|
130
|
-
this.socket = new
|
|
140
|
+
this.socket = new ws(`${webSocketURL}?module=true`);
|
|
131
141
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = NODE_TLS_REJECT_UNAUTHORIZED;
|
|
132
142
|
} else {
|
|
133
|
-
this.socket = new
|
|
143
|
+
this.socket = new ws(webSocketURL);
|
|
134
144
|
}
|
|
135
145
|
|
|
136
146
|
this.addSocketListeners();
|
|
@@ -431,7 +441,7 @@ export class BrokerClient extends BrokerBase {
|
|
|
431
441
|
},
|
|
432
442
|
);
|
|
433
443
|
|
|
434
|
-
if (socket.readyState !==
|
|
444
|
+
if (socket.readyState !== ws.OPEN) {
|
|
435
445
|
try {
|
|
436
446
|
await onceMultiple(this, ['connect'], webSocketMessage.timeout || this.messageTimeout);
|
|
437
447
|
} catch (ex) {
|
|
@@ -556,6 +566,8 @@ export class BrokerClient extends BrokerBase {
|
|
|
556
566
|
duplicate.onClose();
|
|
557
567
|
}
|
|
558
568
|
}
|
|
569
|
+
} else {
|
|
570
|
+
this.emit('reconnectfailure');
|
|
559
571
|
}
|
|
560
572
|
|
|
561
573
|
setTimeout(() => this.connect(this.connectOptions), 1000);
|
package/src/lib/BrokerError.js
CHANGED
|
@@ -14,4 +14,5 @@
|
|
|
14
14
|
// You should have received a copy of the GNU General Public License
|
|
15
15
|
// along with realityhub-api. If not, see <https://www.gnu.org/licenses/>.
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
class BrokerError extends Error { }
|
|
18
|
+
module.exports = BrokerError;
|
package/src/lib/RawRequest.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// You should have received a copy of the GNU General Public License
|
|
15
15
|
// along with realityhub-api. If not, see <https://www.gnu.org/licenses/>.
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
class RawRequest {
|
|
18
18
|
setCallback(callback) {
|
|
19
19
|
if (typeof callback !== 'function') {
|
|
20
20
|
throw new Error('callback must be a function.');
|
|
@@ -37,3 +37,5 @@ export class RawRequest {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
+
|
|
41
|
+
module.exports = RawRequest;
|
package/src/lib/consoleLogger.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// You should have received a copy of the GNU General Public License
|
|
15
15
|
// along with realityhub-api. If not, see <https://www.gnu.org/licenses/>.
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
module.exports = function consoleLogger(moduleName, options = { silent: false }) {
|
|
18
18
|
const { silent } = options;
|
|
19
19
|
|
|
20
20
|
return ['log', 'info', 'warn', 'error', 'trace', 'debug'].reduce((o, item) => {
|
package/src/lib/onceMultiple.js
CHANGED
|
@@ -22,7 +22,7 @@ class TimeoutError extends Error {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
module.exports = function onceMultiple(target, eventNames, timeout = null) {
|
|
26
26
|
return new Promise((resolve, reject) => {
|
|
27
27
|
let timer;
|
|
28
28
|
let handler;
|
package/src/index.cjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2019-2025 Zero Density Inc.
|
|
2
|
-
//
|
|
3
|
-
// This file is part of realityhub-api.
|
|
4
|
-
//
|
|
5
|
-
// realityhub-api is free software: you can redistribute it and/or modify
|
|
6
|
-
// it under the terms of the GNU General Public License version 2, as published by
|
|
7
|
-
// the Free Software Foundation.
|
|
8
|
-
//
|
|
9
|
-
// realityhub-api is distributed in the hope that it will be useful,
|
|
10
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
-
// GNU General Public License for more details.
|
|
13
|
-
//
|
|
14
|
-
// You should have received a copy of the GNU General Public License
|
|
15
|
-
// along with realityhub-api. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
-
|
|
17
|
-
module.exports = require('./index.js');
|