@leofcoin/peernet 1.1.65 → 1.1.67
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/exports/browser/browser-2c73e2ef.js +25 -0
- package/exports/browser/{index-ddb4220d.js → index-1d597e6b.js} +1 -1
- package/exports/browser/{messages-c24213c9.js → messages-67e5efa0.js} +1 -1
- package/exports/browser/{peernet-4149fb9c.js → peernet-55ce42c7.js} +220 -4
- package/exports/browser/peernet.js +1 -1
- package/exports/peernet.js +3 -2
- package/package.json +5 -3
- package/rollup.config.js +35 -41
- package/src/peernet.ts +4 -2
- package/test.js +60 -62
- package/test2.js +8 -4
- package/exports/browser/client-d602421d.js +0 -10751
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var browser$1 = {};
|
|
2
|
+
|
|
3
|
+
browser$1.MediaStream = window.MediaStream;
|
|
4
|
+
browser$1.MediaStreamTrack = window.MediaStreamTrack;
|
|
5
|
+
browser$1.RTCDataChannel = window.RTCDataChannel;
|
|
6
|
+
browser$1.RTCDataChannelEvent = window.RTCDataChannelEvent;
|
|
7
|
+
browser$1.RTCDtlsTransport = window.RTCDtlsTransport;
|
|
8
|
+
browser$1.RTCIceCandidate = window.RTCIceCandidate;
|
|
9
|
+
browser$1.RTCIceTransport = window.RTCIceTransport;
|
|
10
|
+
browser$1.RTCPeerConnection = window.RTCPeerConnection;
|
|
11
|
+
browser$1.RTCPeerConnectionIceEvent = window.RTCPeerConnectionIceEvent;
|
|
12
|
+
browser$1.RTCRtpReceiver = window.RTCRtpReceiver;
|
|
13
|
+
browser$1.RTCRtpSender = window.RTCRtpSender;
|
|
14
|
+
browser$1.RTCRtpTransceiver = window.RTCRtpTransceiver;
|
|
15
|
+
browser$1.RTCSctpTransport = window.RTCSctpTransport;
|
|
16
|
+
browser$1.RTCSessionDescription = window.RTCSessionDescription;
|
|
17
|
+
browser$1.getUserMedia = window.getUserMedia;
|
|
18
|
+
browser$1.mediaDevices = navigator.mediaDevices;
|
|
19
|
+
|
|
20
|
+
var browser = /*#__PURE__*/Object.freeze({
|
|
21
|
+
__proto__: null,
|
|
22
|
+
default: browser$1
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export { browser as b };
|
|
@@ -27088,7 +27088,7 @@ class Identity {
|
|
|
27088
27088
|
this.selectedAccount = new TextDecoder().decode(selected);
|
|
27089
27089
|
}
|
|
27090
27090
|
else {
|
|
27091
|
-
const importee = await import(/* webpackChunkName: "generate-account" */ './index-
|
|
27091
|
+
const importee = await import(/* webpackChunkName: "generate-account" */ './index-1d597e6b.js');
|
|
27092
27092
|
const { identity, accounts } = await importee.default(password, this.network);
|
|
27093
27093
|
await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
|
|
27094
27094
|
await globalThis.walletStore.put('version', String(1));
|
|
@@ -27280,7 +27280,7 @@ class Peernet {
|
|
|
27280
27280
|
this.root = options.root;
|
|
27281
27281
|
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
|
|
27282
27282
|
// FolderMessageResponse
|
|
27283
|
-
} = await import(/* webpackChunkName: "messages" */ './messages-
|
|
27283
|
+
} = await import(/* webpackChunkName: "messages" */ './messages-67e5efa0.js');
|
|
27284
27284
|
/**
|
|
27285
27285
|
* proto Object containing protos
|
|
27286
27286
|
* @type {Object}
|
|
@@ -27371,12 +27371,228 @@ class Peernet {
|
|
|
27371
27371
|
if (this.#starting || this.#started)
|
|
27372
27372
|
return;
|
|
27373
27373
|
this.#starting = true;
|
|
27374
|
-
const importee =
|
|
27374
|
+
const importee = class Client {
|
|
27375
|
+
#peerId;
|
|
27376
|
+
#connections = {};
|
|
27377
|
+
#stars = {};
|
|
27378
|
+
id;
|
|
27379
|
+
networkVersion;
|
|
27380
|
+
starsConfig;
|
|
27381
|
+
socketClient;
|
|
27382
|
+
messageSize = 262144;
|
|
27383
|
+
version;
|
|
27384
|
+
#messagesToHandle = {};
|
|
27385
|
+
get peerId() {
|
|
27386
|
+
return this.#peerId;
|
|
27387
|
+
}
|
|
27388
|
+
get connections() {
|
|
27389
|
+
return { ...this.#connections };
|
|
27390
|
+
}
|
|
27391
|
+
get peers() {
|
|
27392
|
+
return Object.entries(this.#connections);
|
|
27393
|
+
}
|
|
27394
|
+
getPeer(peerId) {
|
|
27395
|
+
return this.#connections[peerId];
|
|
27396
|
+
}
|
|
27397
|
+
constructor(peerId, networkVersion = 'peach', version, stars = ['wss://peach.leofcoin.org']) {
|
|
27398
|
+
this.#peerId = peerId;
|
|
27399
|
+
this.networkVersion = networkVersion;
|
|
27400
|
+
this.version = version;
|
|
27401
|
+
this._init(stars);
|
|
27402
|
+
}
|
|
27403
|
+
async _init(stars = []) {
|
|
27404
|
+
this.starsConfig = stars;
|
|
27405
|
+
// reconnectJob()
|
|
27406
|
+
if (!globalThis.RTCPeerConnection)
|
|
27407
|
+
globalThis.wrtc = (await import('./browser-2c73e2ef.js').then(function (n) { return n.b; })).default;
|
|
27408
|
+
for (const star of stars) {
|
|
27409
|
+
try {
|
|
27410
|
+
const client = new SocketRequestClient(star, this.networkVersion);
|
|
27411
|
+
this.#stars[star] = await client.init();
|
|
27412
|
+
this.setupStarListeners(this.#stars[star]);
|
|
27413
|
+
this.#stars[star].send({
|
|
27414
|
+
url: 'join',
|
|
27415
|
+
params: { version: this.version, peerId: this.peerId }
|
|
27416
|
+
});
|
|
27417
|
+
}
|
|
27418
|
+
catch (e) {
|
|
27419
|
+
if (stars.indexOf(star) === stars.length - 1 && !this.socketClient)
|
|
27420
|
+
throw new Error(`No star available to connect`);
|
|
27421
|
+
}
|
|
27422
|
+
}
|
|
27423
|
+
if (globalThis.navigator) {
|
|
27424
|
+
globalThis.addEventListener('beforeunload', async () => this.close());
|
|
27425
|
+
}
|
|
27426
|
+
else {
|
|
27427
|
+
process.on('SIGINT', async () => {
|
|
27428
|
+
process.stdin.resume();
|
|
27429
|
+
await this.close();
|
|
27430
|
+
process.exit();
|
|
27431
|
+
});
|
|
27432
|
+
}
|
|
27433
|
+
}
|
|
27434
|
+
setupStarListeners(star) {
|
|
27435
|
+
star.pubsub.subscribe('peer:joined', (id) => this.#peerJoined(id, star));
|
|
27436
|
+
star.pubsub.subscribe('peer:left', (id) => this.#peerLeft(id, star));
|
|
27437
|
+
star.pubsub.subscribe('star:joined', this.#starJoined);
|
|
27438
|
+
star.pubsub.subscribe('star:left', this.#starLeft);
|
|
27439
|
+
star.pubsub.subscribe('signal', (message) => this.#inComingSignal(message, star));
|
|
27440
|
+
}
|
|
27441
|
+
#starJoined = (id) => {
|
|
27442
|
+
if (this.#stars[id]) {
|
|
27443
|
+
this.#stars[id].close(0);
|
|
27444
|
+
delete this.#stars[id];
|
|
27445
|
+
}
|
|
27446
|
+
console.log(`star ${id} joined`);
|
|
27447
|
+
};
|
|
27448
|
+
#starLeft = async (id) => {
|
|
27449
|
+
if (this.#stars[id]) {
|
|
27450
|
+
this.#stars[id].close(0);
|
|
27451
|
+
delete this.#stars[id];
|
|
27452
|
+
}
|
|
27453
|
+
if (Object.keys(this.#stars).length === 0) {
|
|
27454
|
+
for (const star of this.starsConfig) {
|
|
27455
|
+
try {
|
|
27456
|
+
const socketClient = await new SocketRequestClient(star, this.networkVersion).init();
|
|
27457
|
+
if (!socketClient?.client?.OPEN)
|
|
27458
|
+
return;
|
|
27459
|
+
this.#stars[star] = socketClient;
|
|
27460
|
+
this.#stars[star].send({
|
|
27461
|
+
url: 'join',
|
|
27462
|
+
params: { peerId: this.peerId, version: this.version }
|
|
27463
|
+
});
|
|
27464
|
+
this.setupStarListeners(socketClient);
|
|
27465
|
+
}
|
|
27466
|
+
catch (e) {
|
|
27467
|
+
if (this.starsConfig.indexOf(star) === this.starsConfig.length - 1)
|
|
27468
|
+
throw new Error(`No star available to connect`);
|
|
27469
|
+
}
|
|
27470
|
+
}
|
|
27471
|
+
}
|
|
27472
|
+
globalThis.debug(`star ${id} left`);
|
|
27473
|
+
};
|
|
27474
|
+
#peerLeft(peer, star) {
|
|
27475
|
+
const id = peer.peerId || peer;
|
|
27476
|
+
if (this.#connections[id]) {
|
|
27477
|
+
this.#connections[id].destroy();
|
|
27478
|
+
delete this.#connections[id];
|
|
27479
|
+
}
|
|
27480
|
+
globalThis.debug(`peer ${id} left`);
|
|
27481
|
+
}
|
|
27482
|
+
#createRTCPeerConnection = (peerId, star, version, initiator = false) => {
|
|
27483
|
+
const peer = new Peer({
|
|
27484
|
+
initiator: initiator,
|
|
27485
|
+
from: this.peerId,
|
|
27486
|
+
to: peerId,
|
|
27487
|
+
version
|
|
27488
|
+
});
|
|
27489
|
+
peer.on('signal', (signal) => this.#peerSignal(peer, signal, star));
|
|
27490
|
+
peer.on('connect', () => this.#peerConnect(peer));
|
|
27491
|
+
peer.on('close', () => this.#peerClose(peer));
|
|
27492
|
+
peer.on('data', (data) => this.#peerData(peer, data));
|
|
27493
|
+
peer.on('error', (error) => this.#peerError(peer, error));
|
|
27494
|
+
this.#connections[peerId] = peer;
|
|
27495
|
+
};
|
|
27496
|
+
#peerJoined = async ({ peerId, version }, star) => {
|
|
27497
|
+
// check if peer rejoined before the previous connection closed
|
|
27498
|
+
if (this.#connections[peerId]) {
|
|
27499
|
+
if (this.#connections[peerId].connected)
|
|
27500
|
+
this.#connections[peerId].destroy();
|
|
27501
|
+
delete this.#connections[peerId];
|
|
27502
|
+
}
|
|
27503
|
+
// RTCPeerConnection
|
|
27504
|
+
this.#createRTCPeerConnection(peerId, star, version, true);
|
|
27505
|
+
globalThis.debug(`peer ${peerId} joined`);
|
|
27506
|
+
};
|
|
27507
|
+
#inComingSignal = async ({ from, signal, channelName, version }, star) => {
|
|
27508
|
+
if (version !== this.version) {
|
|
27509
|
+
console.warn(`${from} joined using the wrong version.\nexpected: ${this.version} but got:${version}`);
|
|
27510
|
+
return;
|
|
27511
|
+
}
|
|
27512
|
+
let peer = this.#connections[from];
|
|
27513
|
+
if (!peer) {
|
|
27514
|
+
this.#createRTCPeerConnection(from, star, version);
|
|
27515
|
+
peer = this.#connections[from];
|
|
27516
|
+
}
|
|
27517
|
+
if (String(peer.channelName) !== String(channelName))
|
|
27518
|
+
console.warn(`channelNames don't match: got ${peer.channelName}, expected: ${channelName}`);
|
|
27519
|
+
peer.signal(signal);
|
|
27520
|
+
};
|
|
27521
|
+
#peerSignal = (peer, signal, star) => {
|
|
27522
|
+
let client = this.#stars[star];
|
|
27523
|
+
if (!client)
|
|
27524
|
+
client = this.#stars[Object.keys(this.#stars)[0]];
|
|
27525
|
+
client.send({
|
|
27526
|
+
url: 'signal',
|
|
27527
|
+
params: {
|
|
27528
|
+
from: this.peerId,
|
|
27529
|
+
to: peer.peerId,
|
|
27530
|
+
channelName: peer.channelName,
|
|
27531
|
+
version: this.version,
|
|
27532
|
+
signal
|
|
27533
|
+
}
|
|
27534
|
+
});
|
|
27535
|
+
};
|
|
27536
|
+
#peerClose = (peer) => {
|
|
27537
|
+
if (this.#connections[peer.peerId]) {
|
|
27538
|
+
this.#connections[peer.peerId].destroy();
|
|
27539
|
+
delete this.#connections[peer.peerId];
|
|
27540
|
+
}
|
|
27541
|
+
globalThis.debug(`closed ${peer.peerId}'s connection`);
|
|
27542
|
+
};
|
|
27543
|
+
#peerConnect = (peer) => {
|
|
27544
|
+
globalThis.debug(`${peer.peerId} connected`);
|
|
27545
|
+
globalThis.pubsub.publish('peer:connected', peer.peerId);
|
|
27546
|
+
};
|
|
27547
|
+
#noticeMessage = (message, id) => {
|
|
27548
|
+
if (globalThis.pubsub.subscribers[id]) {
|
|
27549
|
+
globalThis.pubsub.publish(id, new Uint8Array(message));
|
|
27550
|
+
}
|
|
27551
|
+
else {
|
|
27552
|
+
globalThis.pubsub.publish('peer:data', new Uint8Array(message));
|
|
27553
|
+
}
|
|
27554
|
+
};
|
|
27555
|
+
#peerData = (peer, data) => {
|
|
27556
|
+
const { id, size, chunk } = JSON.parse(new TextDecoder().decode(data));
|
|
27557
|
+
peer.bw.down += size;
|
|
27558
|
+
if (size <= MAX_MESSAGE_SIZE) {
|
|
27559
|
+
this.#noticeMessage(chunk, id);
|
|
27560
|
+
}
|
|
27561
|
+
else {
|
|
27562
|
+
if (!this.#messagesToHandle[id])
|
|
27563
|
+
this.#messagesToHandle[id] = [];
|
|
27564
|
+
this.#messagesToHandle[id] = [
|
|
27565
|
+
...this.#messagesToHandle[id],
|
|
27566
|
+
...Object.values(chunk)
|
|
27567
|
+
];
|
|
27568
|
+
if (this.#messagesToHandle[id].length === Number(size)) {
|
|
27569
|
+
this.#noticeMessage(this.#messagesToHandle[id], id);
|
|
27570
|
+
delete this.#messagesToHandle[id];
|
|
27571
|
+
}
|
|
27572
|
+
}
|
|
27573
|
+
};
|
|
27574
|
+
#peerError = (peer, error) => {
|
|
27575
|
+
console.warn(`Connection error: ${error.message}`);
|
|
27576
|
+
peer.destroy();
|
|
27577
|
+
};
|
|
27578
|
+
async close() {
|
|
27579
|
+
for (const star in this.#stars) {
|
|
27580
|
+
if (this.#stars[star].connectionState() === 'open')
|
|
27581
|
+
await this.#stars[star].send({ url: 'leave', params: this.peerId });
|
|
27582
|
+
}
|
|
27583
|
+
const promises = [
|
|
27584
|
+
Object.values(this.#connections).map((connection) => connection.destroy()),
|
|
27585
|
+
Object.values(this.#stars).map((connection) => connection.close(0))
|
|
27586
|
+
];
|
|
27587
|
+
await Promise.allSettled(promises);
|
|
27588
|
+
}
|
|
27589
|
+
};
|
|
27375
27590
|
/**
|
|
27376
27591
|
* @access public
|
|
27377
27592
|
* @type {PeernetClient}
|
|
27378
27593
|
*/
|
|
27379
|
-
|
|
27594
|
+
console.log(this.stars);
|
|
27595
|
+
this.client = new importee.default(this.id, this.networkVersion, this.version, this.stars);
|
|
27380
27596
|
this.#started = true;
|
|
27381
27597
|
this.#starting = false;
|
|
27382
27598
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { P as default } from './peernet-
|
|
1
|
+
export { P as default } from './peernet-55ce42c7.js';
|
|
2
2
|
import './value-4e80eeeb.js';
|
package/exports/peernet.js
CHANGED
|
@@ -632,12 +632,13 @@ class Peernet {
|
|
|
632
632
|
if (this.#starting || this.#started)
|
|
633
633
|
return;
|
|
634
634
|
this.#starting = true;
|
|
635
|
-
const importee = await import('@netpeer/
|
|
635
|
+
const importee = await import('@netpeer/swarm/client');
|
|
636
636
|
/**
|
|
637
637
|
* @access public
|
|
638
638
|
* @type {PeernetClient}
|
|
639
639
|
*/
|
|
640
|
-
|
|
640
|
+
console.log(this.stars);
|
|
641
|
+
this.client = new importee.default(this.id, this.networkVersion, this.version, this.stars);
|
|
641
642
|
this.#started = true;
|
|
642
643
|
this.#starting = false;
|
|
643
644
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/peernet",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.67",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/peernet.js",
|
|
6
6
|
"exports": {
|
|
@@ -33,9 +33,11 @@
|
|
|
33
33
|
"@leofcoin/generate-account": "^2.0.0",
|
|
34
34
|
"@leofcoin/identity-utils": "^1.0.2",
|
|
35
35
|
"@leofcoin/multi-wallet": "^3.1.4",
|
|
36
|
+
"@leofcoin/p2pt": "^1.7.6",
|
|
36
37
|
"@leofcoin/peernet-swarm": "^1.1.0",
|
|
37
38
|
"@leofcoin/storage": "^3.0.0",
|
|
38
|
-
"@netpeer/p2pt-swarm": "^1.3.
|
|
39
|
+
"@netpeer/p2pt-swarm": "^1.3.5",
|
|
40
|
+
"@netpeer/swarm": "^0.7.2",
|
|
39
41
|
"@types/node": "^18.11.18",
|
|
40
42
|
"@vandeurenglenn/base32": "^1.1.0",
|
|
41
43
|
"@vandeurenglenn/base58": "^1.1.0",
|
|
@@ -47,7 +49,7 @@
|
|
|
47
49
|
"multi-signature": "^1.3.1",
|
|
48
50
|
"qr-scanner": "^1.4.2",
|
|
49
51
|
"qrcode": "^1.5.1",
|
|
50
|
-
"socket-request-client": "^
|
|
52
|
+
"socket-request-client": "^2.0.6",
|
|
51
53
|
"socket-request-server": "^1.5.0"
|
|
52
54
|
},
|
|
53
55
|
"devDependencies": {
|
package/rollup.config.js
CHANGED
|
@@ -1,76 +1,70 @@
|
|
|
1
|
-
import resolve, { nodeResolve } from
|
|
2
|
-
import commonjs from
|
|
3
|
-
import json from
|
|
4
|
-
import wasm from
|
|
5
|
-
import rimraf from
|
|
6
|
-
import typescript from
|
|
7
|
-
import modify from
|
|
1
|
+
import resolve, { nodeResolve } from '@rollup/plugin-node-resolve'
|
|
2
|
+
import commonjs from '@rollup/plugin-commonjs'
|
|
3
|
+
import json from '@rollup/plugin-json'
|
|
4
|
+
import wasm from '@rollup/plugin-wasm'
|
|
5
|
+
import rimraf from 'rimraf'
|
|
6
|
+
import typescript from '@rollup/plugin-typescript'
|
|
7
|
+
import modify from 'rollup-plugin-modify'
|
|
8
8
|
|
|
9
|
-
rimraf.sync(
|
|
9
|
+
rimraf.sync('./exports/**')
|
|
10
10
|
|
|
11
11
|
export default [
|
|
12
12
|
{
|
|
13
|
-
input: [
|
|
14
|
-
"./src/peernet.ts",
|
|
15
|
-
"./node_modules/@leofcoin/storage/exports/browser-store.js",
|
|
16
|
-
],
|
|
13
|
+
input: ['./src/peernet.ts', './node_modules/@leofcoin/storage/exports/browser-store.js'],
|
|
17
14
|
output: {
|
|
18
|
-
format:
|
|
19
|
-
dir:
|
|
15
|
+
format: 'es',
|
|
16
|
+
dir: './exports/browser'
|
|
20
17
|
},
|
|
21
18
|
plugins: [
|
|
22
19
|
json(),
|
|
23
20
|
wasm(),
|
|
24
21
|
modify({
|
|
25
|
-
"@netpeer/
|
|
22
|
+
"await import('@netpeer/swarm/client')": (await import('@netpeer/swarm/browser')).default.toString()
|
|
26
23
|
}),
|
|
27
24
|
resolve({
|
|
28
25
|
browser: true,
|
|
29
26
|
preferBuiltins: false,
|
|
30
|
-
mainFields: [
|
|
27
|
+
mainFields: ['browser', 'module', 'main']
|
|
31
28
|
}),
|
|
32
29
|
commonjs({
|
|
33
|
-
mainFields: [
|
|
30
|
+
mainFields: ['browser', 'module', 'main']
|
|
34
31
|
}),
|
|
35
32
|
|
|
36
|
-
typescript({ compilerOptions: { outDir:
|
|
33
|
+
typescript({ compilerOptions: { outDir: './exports/browser' } })
|
|
37
34
|
],
|
|
38
|
-
external: [
|
|
35
|
+
external: ['./prompts/password.js']
|
|
39
36
|
},
|
|
40
37
|
{
|
|
41
|
-
input: [
|
|
42
|
-
"./src/peernet.ts",
|
|
43
|
-
"./node_modules/@leofcoin/storage/exports/store.js",
|
|
44
|
-
],
|
|
38
|
+
input: ['./src/peernet.ts', './node_modules/@leofcoin/storage/exports/store.js'],
|
|
45
39
|
output: {
|
|
46
|
-
format:
|
|
47
|
-
dir:
|
|
40
|
+
format: 'es',
|
|
41
|
+
dir: './exports'
|
|
48
42
|
},
|
|
49
43
|
plugins: [
|
|
50
44
|
modify({
|
|
51
|
-
|
|
45
|
+
'@netpeer/swarm/client': '@netpeer/swarm/client'
|
|
52
46
|
}),
|
|
53
47
|
typescript({
|
|
54
48
|
compilerOptions: {
|
|
55
|
-
outDir:
|
|
56
|
-
declarationDir:
|
|
57
|
-
}
|
|
58
|
-
})
|
|
49
|
+
outDir: './exports',
|
|
50
|
+
declarationDir: './exports/types'
|
|
51
|
+
}
|
|
52
|
+
})
|
|
59
53
|
],
|
|
60
|
-
external: [
|
|
54
|
+
external: ['./prompts/password.js']
|
|
61
55
|
},
|
|
62
56
|
{
|
|
63
|
-
input: [
|
|
57
|
+
input: ['./src/prompts/password/browser.js'],
|
|
64
58
|
output: {
|
|
65
|
-
format:
|
|
66
|
-
file:
|
|
67
|
-
}
|
|
59
|
+
format: 'es',
|
|
60
|
+
file: './exports/browser/src/prompts/password.js'
|
|
61
|
+
}
|
|
68
62
|
},
|
|
69
63
|
{
|
|
70
|
-
input: [
|
|
64
|
+
input: ['./src/prompts/password/node.js'],
|
|
71
65
|
output: {
|
|
72
|
-
format:
|
|
73
|
-
file:
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
]
|
|
66
|
+
format: 'es',
|
|
67
|
+
file: './exports/src/prompts/password.js'
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
]
|
package/src/peernet.ts
CHANGED
|
@@ -311,12 +311,14 @@ export default class Peernet {
|
|
|
311
311
|
if (this.#starting || this.#started) return
|
|
312
312
|
|
|
313
313
|
this.#starting = true
|
|
314
|
-
const importee = await import('@netpeer/
|
|
314
|
+
const importee = await import('@netpeer/swarm/client')
|
|
315
315
|
/**
|
|
316
316
|
* @access public
|
|
317
317
|
* @type {PeernetClient}
|
|
318
318
|
*/
|
|
319
|
-
|
|
319
|
+
console.log(this.stars)
|
|
320
|
+
|
|
321
|
+
this.client = new importee.default(this.id, this.networkVersion, this.version, this.stars)
|
|
320
322
|
this.#started = true
|
|
321
323
|
this.#starting = false
|
|
322
324
|
}
|
package/test.js
CHANGED
|
@@ -1,64 +1,62 @@
|
|
|
1
1
|
import Client from './exports/peernet.js'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
3
|
+
const client = await new Client({
|
|
4
|
+
network: 'leofcoin:peach',
|
|
5
|
+
networkVersion: 'peach',
|
|
6
|
+
stars: ['wss://star.leofcoin.org']
|
|
7
|
+
})
|
|
8
|
+
console.log(pubsub.subscribers)
|
|
9
|
+
pubsub.subscribe('peer:discovered', (data) => {
|
|
10
|
+
// console.log(data);
|
|
11
|
+
console.log(`discovered: ${Object.keys(peernet.client.discovered).length}`)
|
|
12
|
+
console.log(Object.keys(peernet.client.discovered))
|
|
13
|
+
})
|
|
14
|
+
pubsub.subscribe('peer:connected', (data) => {
|
|
15
|
+
// console.log(data);
|
|
16
|
+
console.log(`connections: ${peernet.connections.length}`)
|
|
17
|
+
})
|
|
18
|
+
pubsub.subscribe('peer:left', (data) => {
|
|
19
|
+
console.log(`connections: ${peernet.connections.length}`)
|
|
20
|
+
console.log(`discovered: ${Object.keys(peernet.client.discovered).length}`)
|
|
21
|
+
// console.log(data);
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
// peernet.addFolder([{
|
|
25
|
+
// path: 'assets/asset.png',
|
|
26
|
+
// content: Buffer.from('png')
|
|
27
|
+
// }, {
|
|
28
|
+
// path: 'index.html',
|
|
29
|
+
// content: Buffer.from('html')
|
|
30
|
+
// }]).then(hash => peernet.ls(hash).then(paths => peernet.cat(paths[0].hash).then(content => console.log(content))))
|
|
31
|
+
|
|
32
|
+
// pubsub.subscribe('peer:connected', async peer => {
|
|
33
|
+
// chainStore.put('localBlock', '00000')
|
|
34
|
+
// const request = await new globalThis.peernet.protos['peernet-request']({
|
|
35
|
+
// request:'lastBlock'
|
|
36
|
+
// })
|
|
37
|
+
// const to = peer.id
|
|
38
|
+
// await peernet.data.put('hello', 'hi')
|
|
39
|
+
// console.log({request});
|
|
40
|
+
// const node = await peernet.prepareMessage(request)
|
|
41
|
+
// console.log({node});
|
|
42
|
+
// let response = await peer.request(node.encoded)
|
|
43
|
+
// console.log({response});
|
|
44
|
+
// const keys = Object.keys(response)
|
|
45
|
+
// const uint8Array = new Uint8Array(keys.length)
|
|
46
|
+
// for (const key of keys) {
|
|
47
|
+
// uint8Array[Number(key)] = response[key]
|
|
48
|
+
// }
|
|
49
|
+
// // const proto = await new globalThis.peernet.protos['peernet-message'](uint8Array)
|
|
50
|
+
// // console.log(proto.decoded.data);
|
|
51
|
+
// response = await new globalThis.peernet.protos['peernet-response'](uint8Array)
|
|
52
|
+
// console.log({response});
|
|
53
|
+
|
|
54
|
+
// const block = new TextDecoder().decode(response.decoded.response)
|
|
55
|
+
// console.log(block);
|
|
56
|
+
// const task = () => setTimeout(() => {
|
|
57
|
+
// console.log(peernet.connections[0]?.connected);
|
|
58
|
+
// console.log(pubsub.subscribers);
|
|
59
|
+
// task()
|
|
60
|
+
// }, 5000);
|
|
61
|
+
// task()
|
|
62
|
+
// })
|
package/test2.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import Client from './exports/peernet.js'
|
|
2
|
+
;(async () => {
|
|
3
|
+
const client = await new Client({
|
|
4
|
+
root: '.peernet/test2',
|
|
5
|
+
network: 'peach',
|
|
6
|
+
networkVersion: 'peach',
|
|
7
|
+
stars: [['wss://star.leofcoin.org']]
|
|
8
|
+
})
|
|
5
9
|
const job = () => client.publish('socket-data', 'hello')
|
|
6
10
|
setTimeout(async () => {
|
|
7
11
|
job()
|