@zerodensity/realityhub-api 1.16.0 → 1.19.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 +10 -3
- package/src/index.cjs +17 -0
- package/src/index.js +4 -6
- package/src/lib/BrokerBase.js +5 -5
- package/src/lib/BrokerClient.js +11 -21
- package/src/lib/BrokerError.js +1 -2
- package/src/lib/RawRequest.js +1 -3
- package/src/lib/consoleLogger.js +1 -1
- package/src/lib/onceMultiple.js +1 -1
package/package.json
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zerodensity/realityhub-api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"description": "RealityHub API Javascript Implementation",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "src/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
"./package.json": "./package.json",
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./src/index.js",
|
|
11
|
+
"require": "./src/index.cjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
6
14
|
"repository": {
|
|
7
15
|
"type": "git",
|
|
8
16
|
"url": "git+ssh://git@github.com/zerodensity/realityhub-api.git"
|
|
@@ -30,7 +38,6 @@
|
|
|
30
38
|
},
|
|
31
39
|
"homepage": "https://github.com/zerodensity/realityhub-api#readme",
|
|
32
40
|
"dependencies": {
|
|
33
|
-
"uuid": "^11.0.3"
|
|
34
|
-
"ws": "^8.18.0"
|
|
41
|
+
"uuid": "^11.0.3"
|
|
35
42
|
}
|
|
36
43
|
}
|
package/src/index.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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');
|
package/src/index.js
CHANGED
|
@@ -14,9 +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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
RawRequest: require('./lib/RawRequest'),
|
|
22
|
-
};
|
|
17
|
+
export { BrokerBase } from './lib/BrokerBase.js';
|
|
18
|
+
export { BrokerClient } from './lib/BrokerClient.js';
|
|
19
|
+
export { BrokerError } from './lib/BrokerError.js';
|
|
20
|
+
export { RawRequest } from './lib/RawRequest.js';
|
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
|
+
import { v4 as uuid } from 'uuid';
|
|
18
|
+
import { EventEmitter } from 'events';
|
|
19
|
+
import { BrokerError } from './BrokerError.js';
|
|
20
|
+
import { onceMultiple } from './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
|
+
export class BrokerBase extends EventEmitter {
|
|
32
32
|
constructor(params) {
|
|
33
33
|
super();
|
|
34
34
|
this.moduleName = params.moduleName;
|
package/src/lib/BrokerClient.js
CHANGED
|
@@ -14,24 +14,14 @@
|
|
|
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
|
-
|
|
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 {
|
|
17
|
+
import { v4 as uuid } from 'uuid';
|
|
18
|
+
import { BrokerBase } from './BrokerBase.js';
|
|
19
|
+
import { BrokerError } from './BrokerError.js';
|
|
20
|
+
import { RawRequest } from './RawRequest.js';
|
|
21
|
+
import { consoleLogger } from './consoleLogger.js';
|
|
22
|
+
import { onceMultiple } from './onceMultiple.js';
|
|
23
|
+
|
|
24
|
+
export class BrokerClient extends BrokerBase {
|
|
35
25
|
/**
|
|
36
26
|
* BrokerClient constructor
|
|
37
27
|
* @param {object} params Parameters
|
|
@@ -137,10 +127,10 @@ module.exports = class BrokerClient extends BrokerBase {
|
|
|
137
127
|
if (typeof process !== "undefined" && process.versions != null && process.versions.node != null) {
|
|
138
128
|
const NODE_TLS_REJECT_UNAUTHORIZED = process.env.NODE_TLS_REJECT_UNAUTHORIZED;
|
|
139
129
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
|
|
140
|
-
this.socket = new
|
|
130
|
+
this.socket = new WebSocket(webSocketURL);
|
|
141
131
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = NODE_TLS_REJECT_UNAUTHORIZED;
|
|
142
132
|
} else {
|
|
143
|
-
this.socket = new
|
|
133
|
+
this.socket = new WebSocket(webSocketURL);
|
|
144
134
|
}
|
|
145
135
|
|
|
146
136
|
this.addSocketListeners();
|
|
@@ -441,7 +431,7 @@ module.exports = class BrokerClient extends BrokerBase {
|
|
|
441
431
|
},
|
|
442
432
|
);
|
|
443
433
|
|
|
444
|
-
if (socket.readyState !==
|
|
434
|
+
if (socket.readyState !== WebSocket.OPEN) {
|
|
445
435
|
try {
|
|
446
436
|
await onceMultiple(this, ['connect'], webSocketMessage.timeout || this.messageTimeout);
|
|
447
437
|
} catch (ex) {
|
package/src/lib/BrokerError.js
CHANGED
|
@@ -14,5 +14,4 @@
|
|
|
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
|
-
class BrokerError extends Error { }
|
|
18
|
-
module.exports = BrokerError;
|
|
17
|
+
export class BrokerError extends Error { }
|
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
|
-
class RawRequest {
|
|
17
|
+
export class RawRequest {
|
|
18
18
|
setCallback(callback) {
|
|
19
19
|
if (typeof callback !== 'function') {
|
|
20
20
|
throw new Error('callback must be a function.');
|
|
@@ -37,5 +37,3 @@ 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
|
+
export 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
|
+
export function onceMultiple(target, eventNames, timeout = null) {
|
|
26
26
|
return new Promise((resolve, reject) => {
|
|
27
27
|
let timer;
|
|
28
28
|
let handler;
|