@zerodensity/realityhub-api 1.19.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 CHANGED
@@ -1,16 +1,8 @@
1
1
  {
2
2
  "name": "@zerodensity/realityhub-api",
3
- "version": "1.19.0",
3
+ "version": "1.20.0",
4
4
  "description": "RealityHub API Javascript Implementation",
5
- "type": "module",
6
5
  "main": "src/index.js",
7
- "exports": {
8
- "./package.json": "./package.json",
9
- ".": {
10
- "import": "./src/index.js",
11
- "require": "./src/index.cjs"
12
- }
13
- },
14
6
  "repository": {
15
7
  "type": "git",
16
8
  "url": "git+ssh://git@github.com/zerodensity/realityhub-api.git"
@@ -38,6 +30,7 @@
38
30
  },
39
31
  "homepage": "https://github.com/zerodensity/realityhub-api#readme",
40
32
  "dependencies": {
41
- "uuid": "^11.0.3"
33
+ "uuid": "^11.0.3",
34
+ "ws": "^8.18.0"
42
35
  }
43
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
- 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';
17
+ module.exports = {
18
+ BrokerBase: require('./lib/BrokerBase'),
19
+ BrokerClient: require('./lib/BrokerClient'),
20
+ BrokerError: require('./lib/BrokerError'),
21
+ RawRequest: require('./lib/RawRequest'),
22
+ };
@@ -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
- import { v4 as uuid } from 'uuid';
18
- import { EventEmitter } from 'events';
19
- import { BrokerError } from './BrokerError.js';
20
- import { onceMultiple } from './onceMultiple.js';
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
- export class BrokerBase extends EventEmitter {
31
+ module.exports = class BrokerBase extends EventEmitter {
32
32
  constructor(params) {
33
33
  super();
34
34
  this.moduleName = params.moduleName;
@@ -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
- 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 {
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 WebSocket(webSocketURL);
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 WebSocket(webSocketURL);
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 !== WebSocket.OPEN) {
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);
@@ -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
- export class BrokerError extends Error { }
17
+ class BrokerError extends Error { }
18
+ module.exports = BrokerError;
@@ -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
- export class RawRequest {
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;
@@ -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
- export function consoleLogger(moduleName, options = { silent: false }) {
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) => {
@@ -22,7 +22,7 @@ class TimeoutError extends Error {
22
22
  }
23
23
  }
24
24
 
25
- export function onceMultiple(target, eventNames, timeout = null) {
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');