@leofcoin/peernet 1.1.72 → 1.1.73

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.
@@ -1,4 +1,4 @@
1
- import { F as FormatInterface } from './peernet-fa94440c.js';
1
+ import { F as FormatInterface } from './peernet-0298b289.js';
2
2
  import './value-4e80eeeb.js';
3
3
 
4
4
  var proto$b = {
@@ -700,7 +700,7 @@ var _nodeResolve_empty$1 = /*#__PURE__*/Object.freeze({
700
700
  default: _nodeResolve_empty
701
701
  });
702
702
 
703
- var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(_nodeResolve_empty$1);
703
+ var require$$3 = /*@__PURE__*/getAugmentedNamespace(_nodeResolve_empty$1);
704
704
 
705
705
  bn$1.exports;
706
706
 
@@ -759,7 +759,7 @@ bn$1.exports;
759
759
  if (typeof window !== 'undefined' && typeof window.Buffer !== 'undefined') {
760
760
  Buffer = window.Buffer;
761
761
  } else {
762
- Buffer = require$$0$1.Buffer;
762
+ Buffer = require$$3.Buffer;
763
763
  }
764
764
  } catch (e) {
765
765
  }
@@ -13471,7 +13471,7 @@ bn.exports;
13471
13471
  if (typeof window !== 'undefined' && typeof window.Buffer !== 'undefined') {
13472
13472
  Buffer = window.Buffer;
13473
13473
  } else {
13474
- Buffer = require$$0$1.Buffer;
13474
+ Buffer = require$$3.Buffer;
13475
13475
  }
13476
13476
  } catch (e) {
13477
13477
  }
@@ -17115,7 +17115,7 @@ if (typeof self === 'object') {
17115
17115
  } else {
17116
17116
  // Node.js or Web worker with no crypto support
17117
17117
  try {
17118
- var crypto$1 = require$$0$1;
17118
+ var crypto$1 = require$$3;
17119
17119
  if (typeof crypto$1.randomBytes !== 'function')
17120
17120
  throw new Error('Not supported');
17121
17121
 
@@ -27092,7 +27092,7 @@ class Identity {
27092
27092
  this.selectedAccount = new TextDecoder().decode(selected);
27093
27093
  }
27094
27094
  else {
27095
- const importee = await import(/* webpackChunkName: "generate-account" */ './index-687f692b.js');
27095
+ const importee = await import(/* webpackChunkName: "generate-account" */ './index-81687e93.js');
27096
27096
  const { identity, accounts } = await importee.default(password, this.network);
27097
27097
  await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
27098
27098
  await globalThis.walletStore.put('version', String(1));
@@ -27283,7 +27283,7 @@ class Peernet {
27283
27283
  this.root = options.root;
27284
27284
  const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
27285
27285
  // FolderMessageResponse
27286
- } = await import(/* webpackChunkName: "messages" */ './messages-1c117282.js');
27286
+ } = await import(/* webpackChunkName: "messages" */ './messages-cccb78db.js');
27287
27287
  /**
27288
27288
  * proto Object containing protos
27289
27289
  * @type {Object}
@@ -27377,247 +27377,7 @@ class Peernet {
27377
27377
  if (this.#starting || this.#started)
27378
27378
  return;
27379
27379
  this.#starting = true;
27380
- const importee = class Client {
27381
- #peerId;
27382
- #connections = {};
27383
- #stars = {};
27384
- #connectEvent = 'peer:connected';
27385
- id;
27386
- networkVersion;
27387
- starsConfig;
27388
- socketClient;
27389
- messageSize = 262144;
27390
- version;
27391
- #messagesToHandle = {};
27392
- get peerId() {
27393
- return this.#peerId;
27394
- }
27395
- get connections() {
27396
- return { ...this.#connections };
27397
- }
27398
- get peers() {
27399
- return Object.entries(this.#connections);
27400
- }
27401
- getPeer(peerId) {
27402
- return this.#connections[peerId];
27403
- }
27404
- /**
27405
- *
27406
- * @param options {object}
27407
- * @param options.peerId {string}
27408
- * @param options.networkVersion {string}
27409
- * @param options.version {string}
27410
- * @param options.stars {string[]}
27411
- * @param options.connectEvent {string} defaults to peer:connected, can be renamed to handle different protocols, like peer:discovered (setup peer props before fireing the connect event)
27412
- */
27413
- constructor(options) {
27414
- const { peerId, networkVersion, version, connectEvent, stars } = {
27415
- ...defaultOptions,
27416
- ...options
27417
- };
27418
- this.#peerId = peerId;
27419
- this.networkVersion = networkVersion;
27420
- this.version = version;
27421
- this.#connectEvent = connectEvent;
27422
- this.starsConfig = stars;
27423
- this._init();
27424
- }
27425
- async _init() {
27426
- // reconnectJob()
27427
- if (!globalThis.RTCPeerConnection)
27428
- globalThis.wrtc = (await import('./browser-2c73e2ef.js').then(function (n) { return n.b; })).default;
27429
- for (const star of this.starsConfig) {
27430
- try {
27431
- const client = new SocketRequestClient(star, this.networkVersion);
27432
- this.#stars[star] = await client.init();
27433
- this.setupStarListeners(this.#stars[star]);
27434
- this.#stars[star].send({
27435
- url: 'join',
27436
- params: { version: this.version, peerId: this.peerId }
27437
- });
27438
- }
27439
- catch (e) {
27440
- if (this.starsConfig.indexOf(star) === this.starsConfig.length - 1 &&
27441
- !this.socketClient)
27442
- throw new Error(`No star available to connect`);
27443
- }
27444
- }
27445
- if (globalThis.navigator) {
27446
- globalThis.addEventListener('beforeunload', async () => this.close());
27447
- }
27448
- else {
27449
- process.on('SIGINT', async () => {
27450
- process.stdin.resume();
27451
- await this.close();
27452
- process.exit();
27453
- });
27454
- }
27455
- }
27456
- setupStarListeners(star) {
27457
- star.pubsub.subscribe('peer:joined', (id) => this.#peerJoined(id, star));
27458
- star.pubsub.subscribe('peer:left', (id) => this.#peerLeft(id, star));
27459
- star.pubsub.subscribe('star:joined', this.#starJoined);
27460
- star.pubsub.subscribe('star:left', this.#starLeft);
27461
- star.pubsub.subscribe('signal', (message) => this.#inComingSignal(message, star));
27462
- }
27463
- #starJoined = (id) => {
27464
- if (this.#stars[id]) {
27465
- this.#stars[id].close(0);
27466
- delete this.#stars[id];
27467
- }
27468
- console.log(`star ${id} joined`);
27469
- };
27470
- #starLeft = async (id) => {
27471
- if (this.#stars[id]) {
27472
- this.#stars[id].close(0);
27473
- delete this.#stars[id];
27474
- }
27475
- if (Object.keys(this.#stars).length === 0) {
27476
- for (const star of this.starsConfig) {
27477
- try {
27478
- const socketClient = await new SocketRequestClient(star, this.networkVersion).init();
27479
- if (!socketClient?.client?.OPEN)
27480
- return;
27481
- this.#stars[star] = socketClient;
27482
- this.#stars[star].send({
27483
- url: 'join',
27484
- params: { peerId: this.peerId, version: this.version }
27485
- });
27486
- this.setupStarListeners(socketClient);
27487
- }
27488
- catch (e) {
27489
- if (this.starsConfig.indexOf(star) === this.starsConfig.length - 1)
27490
- throw new Error(`No star available to connect`);
27491
- }
27492
- }
27493
- }
27494
- globalThis.debug(`star ${id} left`);
27495
- };
27496
- #peerLeft = (peer, star) => {
27497
- const id = peer.peerId || peer;
27498
- if (this.#connections[id]) {
27499
- this.#connections[id].destroy();
27500
- delete this.#connections[id];
27501
- }
27502
- globalThis.debug(`peer ${id} left`);
27503
- };
27504
- #createRTCPeerConnection = (peerId, star, version, initiator = false) => {
27505
- const peer = new Peer({
27506
- initiator: initiator,
27507
- from: this.peerId,
27508
- to: peerId,
27509
- version
27510
- });
27511
- peer.on('signal', (signal) => this.#peerSignal(peer, signal, star, this.version));
27512
- peer.on('connect', () => this.#peerConnect(peer));
27513
- peer.on('close', () => this.#peerClose(peer));
27514
- peer.on('data', (data) => this.#peerData(peer, data));
27515
- peer.on('error', (error) => this.#peerError(peer, error));
27516
- this.#connections[peerId] = peer;
27517
- };
27518
- #peerJoined = async ({ peerId, version }, star) => {
27519
- // check if peer rejoined before the previous connection closed
27520
- if (this.#connections[peerId]) {
27521
- this.#connections[peerId].destroy();
27522
- delete this.#connections[peerId];
27523
- }
27524
- // RTCPeerConnection
27525
- this.#createRTCPeerConnection(peerId, star, version, true);
27526
- globalThis.debug(`peer ${peerId} joined`);
27527
- };
27528
- #inComingSignal = async ({ from, signal, channelName, version }, star) => {
27529
- if (version !== this.version) {
27530
- console.warn(`${from} joined using the wrong version.\nexpected: ${this.version} but got:${version}`);
27531
- return;
27532
- }
27533
- let peer = this.#connections[from];
27534
- if (!peer) {
27535
- this.#createRTCPeerConnection(from, star, version);
27536
- peer = this.#connections[from];
27537
- }
27538
- if (String(peer.channelName) !== String(channelName))
27539
- console.warn(`channelNames don't match: got ${peer.channelName}, expected: ${channelName}`);
27540
- peer.signal(signal);
27541
- };
27542
- #peerSignal = (peer, signal, star, version) => {
27543
- let client = this.#stars[star];
27544
- if (!client)
27545
- client = this.#stars[Object.keys(this.#stars)[0]];
27546
- client.send({
27547
- url: 'signal',
27548
- params: {
27549
- from: this.peerId,
27550
- to: peer.peerId,
27551
- channelName: peer.channelName,
27552
- version,
27553
- signal
27554
- }
27555
- });
27556
- };
27557
- #peerClose = (peer) => {
27558
- if (this.#connections[peer.peerId]) {
27559
- peer.destroy();
27560
- delete this.#connections[peer.peerId];
27561
- }
27562
- globalThis.debug(`closed ${peer.peerId}'s connection`);
27563
- };
27564
- #peerConnect = (peer) => {
27565
- globalThis.debug(`${peer.peerId} connected`);
27566
- globalThis.pubsub.publishVerbose(this.#connectEvent, peer.peerId);
27567
- };
27568
- #noticeMessage = (message, id, from, peer) => {
27569
- if (globalThis.pubsub.subscribers[id]) {
27570
- globalThis.pubsub.publish(id, {
27571
- data: new Uint8Array(Object.values(message)),
27572
- id,
27573
- from,
27574
- peer
27575
- });
27576
- }
27577
- else {
27578
- globalThis.pubsub.publish('peer:data', {
27579
- data: new Uint8Array(Object.values(message)),
27580
- id,
27581
- from,
27582
- peer
27583
- });
27584
- }
27585
- };
27586
- #peerData = (peer, data) => {
27587
- const { id, size, chunk } = JSON.parse(new TextDecoder().decode(data));
27588
- peer.bw.down += size;
27589
- if (size <= MAX_MESSAGE_SIZE) {
27590
- this.#noticeMessage(chunk, id, peer.peerId, peer);
27591
- }
27592
- else {
27593
- if (!this.#messagesToHandle[id])
27594
- this.#messagesToHandle[id] = [];
27595
- this.#messagesToHandle[id] = [
27596
- ...this.#messagesToHandle[id],
27597
- ...Object.values(chunk)
27598
- ];
27599
- if (this.#messagesToHandle[id].length === Number(size)) {
27600
- this.#noticeMessage(this.#messagesToHandle[id], id, peer.peerId, peer);
27601
- delete this.#messagesToHandle[id];
27602
- }
27603
- }
27604
- };
27605
- #peerError = (peer, error) => {
27606
- console.warn(`Connection error: ${error.message}`);
27607
- peer.destroy();
27608
- };
27609
- async close() {
27610
- for (const star in this.#stars) {
27611
- if (this.#stars[star].connectionState() === 'open')
27612
- await this.#stars[star].send({ url: 'leave', params: this.peerId });
27613
- }
27614
- const promises = [
27615
- Object.values(this.#connections).map((connection) => connection.destroy()),
27616
- Object.values(this.#stars).map((connection) => connection.close(0))
27617
- ];
27618
- return Promise.allSettled(promises);
27619
- }
27620
- };
27380
+ const importee = await import('./client-f193279c.js');
27621
27381
  /**
27622
27382
  * @access public
27623
27383
  * @type {PeernetClient}
@@ -28091,4 +27851,4 @@ class Peernet {
28091
27851
  }
28092
27852
  globalThis.Peernet = Peernet;
28093
27853
 
28094
- export { FormatInterface as F, MultiWallet as M, Peernet as P, base58$1 as b, encrypt as e };
27854
+ export { FormatInterface as F, LittlePubSub as L, MultiWallet as M, Peernet as P, base58$1 as b, commonjsGlobal as c, encrypt as e, getDefaultExportFromCjs as g, inherits_browserExports as i, require$$3 as r };
@@ -1,2 +1,2 @@
1
- export { P as default } from './peernet-fa94440c.js';
1
+ export { P as default } from './peernet-0298b289.js';
2
2
  import './value-4e80eeeb.js';
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@leofcoin/peernet",
3
- "version": "1.1.72",
3
+ "version": "1.1.73",
4
4
  "description": "",
5
- "main": "src/peernet.js",
5
+ "browser": "./exports/browser/peernet.js",
6
6
  "exports": {
7
7
  ".": {
8
8
  "import": "./exports/peernet.js",
@@ -66,7 +66,6 @@
66
66
  "eslint-plugin-unicorn": "^45.0.1",
67
67
  "node-stdlib-browser": "^1.2.0",
68
68
  "rollup": "^3.12.0",
69
- "rollup-plugin-modify": "^3.0.0",
70
69
  "webpack-cli": "^5.0.1"
71
70
  }
72
71
  }
package/rollup.config.js CHANGED
@@ -1,10 +1,9 @@
1
- import resolve, { nodeResolve } from '@rollup/plugin-node-resolve'
1
+ import resolve from '@rollup/plugin-node-resolve'
2
2
  import commonjs from '@rollup/plugin-commonjs'
3
3
  import json from '@rollup/plugin-json'
4
4
  import wasm from '@rollup/plugin-wasm'
5
5
  import rimraf from 'rimraf'
6
6
  import typescript from '@rollup/plugin-typescript'
7
- import modify from 'rollup-plugin-modify'
8
7
 
9
8
  rimraf.sync('./exports/**')
10
9
 
@@ -18,9 +17,6 @@ export default [
18
17
  plugins: [
19
18
  json(),
20
19
  wasm(),
21
- modify({
22
- "await import('@netpeer/swarm/client')": (await import('@netpeer/swarm/browser')).default.toString()
23
- }),
24
20
  resolve({
25
21
  browser: true,
26
22
  preferBuiltins: false,
@@ -41,9 +37,6 @@ export default [
41
37
  dir: './exports'
42
38
  },
43
39
  plugins: [
44
- modify({
45
- '@netpeer/swarm/client': '@netpeer/swarm/client'
46
- }),
47
40
  typescript({
48
41
  compilerOptions: {
49
42
  outDir: './exports',