@hive-p2p/browser 1.0.95 → 1.0.97

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.
@@ -50,10 +50,10 @@ export class NodeServices {
50
50
  }
51
51
  #startWebSocketServer(domain = 'localhost', port = SERVICE.PORT) {
52
52
  this.wsServer = new TRANSPORTS.WS_SERVER({ port, host: domain });
53
- this.wsServer.on('error', (error) => console.error(`WebSocket error on Node #${this.id}:`, error));
53
+ if (this.verbose > 1) this.wsServer.on('error', (error) => console.warn(`WebSocket error on Node #${this.id}:`, error));
54
54
  this.wsServer.on('connection', (ws) => {
55
55
  ws.on('close', () => { if (remoteId) for (const cb of this.peerStore.callbacks.disconnect) cb(remoteId, 'in'); });
56
- ws.on('error', (error) => console.error(`WebSocket error on Node #${this.id} with peer ${remoteId}:`, error.stack));
56
+ if (this.verbose > 1) ws.on('error', (error) => console.warn(`WebSocket error on Node #${this.id} with peer ${remoteId}:`, error.stack));
57
57
 
58
58
  let remoteId;
59
59
  ws.on('message', (data) => { // When peer proves his id, we can handle data normally
@@ -49,7 +49,7 @@ export class OfferQueue {
49
49
  }
50
50
 
51
51
  export class Topologist {
52
- id; cryptoCodex; gossip; messager; peerStore; bootstraps; offersQueue = new OfferQueue();
52
+ verbose; id; cryptoCodex; gossip; messager; peerStore; bootstraps; offersQueue = new OfferQueue();
53
53
  /** @type {Map<string, boolean>} */ bootstrapsConnectionState = new Map();
54
54
  /** @type {import('./node-services.mjs').NodeServices | undefined} */ services;
55
55
  /** @type {number} */ NEIGHBORS_TARGET;
@@ -67,9 +67,9 @@ export class Topologist {
67
67
  get isPublicNode() { return this.services?.publicUrl ? true : false; }
68
68
 
69
69
  /** @param {string} selfId @param {import('./crypto-codex.mjs').CryptoCodex} cryptoCodex @param {import('./gossip.mjs').Gossip} gossip @param {import('./unicast.mjs').UnicastMessager} messager @param {import('./peer-store.mjs').PeerStore} peerStore @param {string[]} bootstraps */
70
- constructor(selfId, cryptoCodex, gossip, messager, peerStore, bootstraps) {
70
+ constructor(selfId, cryptoCodex, gossip, messager, peerStore, bootstraps, verbose = 1) {
71
71
  this.setNeighborsTarget(DISCOVERY.TARGET_NEIGHBORS_COUNT);
72
- this.id = selfId; this.cryptoCodex = cryptoCodex; this.gossip = gossip; this.messager = messager; this.peerStore = peerStore;
72
+ this.verbose = verbose; this.id = selfId; this.cryptoCodex = cryptoCodex; this.gossip = gossip; this.messager = messager; this.peerStore = peerStore;
73
73
  for (const url of bootstraps) this.bootstrapsConnectionState.set(url, false);
74
74
  this.bootstraps = [...bootstraps].sort(() => Math.random() - 0.5); // shuffle
75
75
  this.nextBootstrapIndex = Math.random() * this.bootstraps.length | 0;
@@ -170,7 +170,7 @@ export class Topologist {
170
170
  #connectToPublicNode(publicUrl = 'localhost:8080') {
171
171
  let remoteId = null;
172
172
  const ws = new TRANSPORTS.WS_CLIENT(this.#getFullWsUrl(publicUrl)); ws.binaryType = 'arraybuffer';
173
- ws.onerror = (error) => console.error(`WebSocket error:`, error.stack);
173
+ if (this.verbose > 1) ws.onerror = (error) => console.warn(`WebSocket error:`, error.stack);
174
174
  ws.onopen = () => {
175
175
  this.bootstrapsConnectionState.set(publicUrl, true);
176
176
  ws.onclose = () => {