webpeerjs 0.0.7 → 0.0.8
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/README.md +34 -24
- package/dist/esm/webpeerjs.d.ts +1 -1
- package/dist/esm/webpeerjs.js +37 -44
- package/dist/umd/webpeerjs.js +37 -44
- package/package.json +1 -1
- package/src/config.js +7 -6
- package/src/webpeerjs.js +30 -38
package/README.md
CHANGED
|
@@ -3,9 +3,28 @@
|
|
|
3
3
|
|
|
4
4
|
WebpeerJS enables browser to browser connectivity without a central server.
|
|
5
5
|
|
|
6
|
-
[Demo](https://nuzulul.github.io/webpeerjs/demo/)
|
|
6
|
+
[Live Demo](https://nuzulul.github.io/webpeerjs/demo/)
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
* ✅ Decentralized Network
|
|
11
|
+
* ✅ Broadcast Message
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
NPM :
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
npm i webpeerjs
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
CDN :
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
<script src="https://cdn.jsdelivr.net/npm/webpeerjs@0.0/dist/umd/webpeerjs.min.js"></script>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
9
28
|
|
|
10
29
|
```
|
|
11
30
|
import { webpeerjs } from 'webpeerjs'
|
|
@@ -16,7 +35,7 @@ void async function main() {
|
|
|
16
35
|
|
|
17
36
|
console.log(`My node id : ${node.id}`)
|
|
18
37
|
|
|
19
|
-
const [
|
|
38
|
+
const [broadcast,listen,members] = node.joinRoom('myroom')
|
|
20
39
|
|
|
21
40
|
listen((message,id) => {
|
|
22
41
|
console.log(`Message from ${id} : ${message}`)
|
|
@@ -24,35 +43,26 @@ void async function main() {
|
|
|
24
43
|
|
|
25
44
|
members((data) => {
|
|
26
45
|
console.log(`Members : ${data}`)
|
|
27
|
-
|
|
46
|
+
broadcast('hello')
|
|
28
47
|
})
|
|
29
48
|
|
|
30
49
|
}()
|
|
31
50
|
```
|
|
32
51
|
|
|
33
|
-
## Install
|
|
34
|
-
|
|
35
|
-
NPM :
|
|
36
|
-
|
|
37
|
-
```
|
|
38
|
-
npm i webpeerjs
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
CDN :
|
|
42
|
-
|
|
43
|
-
```
|
|
44
|
-
<script src="https://cdn.jsdelivr.net/npm/webpeerjs@0.0/dist/umd/webpeerjs.min.js"></script>
|
|
45
|
-
```
|
|
46
|
-
|
|
47
52
|
## API
|
|
48
53
|
|
|
49
|
-
- `createWebpeer()` Create a new
|
|
50
|
-
- `id` The unique ID of the
|
|
51
|
-
- `joinRoom()` Adding
|
|
54
|
+
- `createWebpeer()` Create a new node.
|
|
55
|
+
- `id` The unique ID of the node as an identity in the global network.
|
|
56
|
+
- `joinRoom()` Adding the node to the room, returns an array of three functions (Broadcaster, onListenMessage, onMembersUpdate).
|
|
52
57
|
- `peers` Get all connected peers.
|
|
58
|
+
- `status` Get the node status, returns `connected` or `unconnected`.
|
|
59
|
+
|
|
60
|
+
## Related
|
|
53
61
|
|
|
54
|
-
|
|
62
|
+
- [simple-peer](https://github.com/feross/simple-peer) - Simple WebRTC video, voice, and data channels.
|
|
63
|
+
- [peerjs](https://github.com/peers/peerjs) - Simple peer-to-peer with WebRTC.
|
|
64
|
+
- [trystero](https://github.com/dmotz/trystero) - Build instant multiplayer webapps, no server required.
|
|
55
65
|
|
|
56
|
-
|
|
66
|
+
## Maintainers
|
|
57
67
|
|
|
58
|
-
|
|
68
|
+
[Nuzulul Zulkarnain](https://github.com/nuzulul)
|
package/dist/esm/webpeerjs.d.ts
CHANGED
package/dist/esm/webpeerjs.js
CHANGED
|
@@ -30,10 +30,7 @@ const CONFIG_PEER_DISCOVERY_WEBPEERJS= prefix$1+'-peer-discovery';
|
|
|
30
30
|
const CONFIG_PUBSUB_PEER_DISCOVERY = [CONFIG_PEER_DISCOVERY_GLOBAL, CONFIG_PEER_DISCOVERY_UNIVERSAL_CONNECTIVITY, CONFIG_PEER_DISCOVERY_WEBPEERJS];
|
|
31
31
|
const CONFIG_DELEGATED_API = 'https://delegated-ipfs.dev';
|
|
32
32
|
|
|
33
|
-
const
|
|
34
|
-
];
|
|
35
|
-
|
|
36
|
-
const CONFIG_KNOWN_BOOTSTRAP_PEERS_IDS = [
|
|
33
|
+
const CONFIG_KNOWN_BOOTSTRAP_PUBLIC_IDS = [
|
|
37
34
|
'QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN',
|
|
38
35
|
'QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb',
|
|
39
36
|
'QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt',
|
|
@@ -45,12 +42,16 @@ const CONFIG_KNOWN_BOOTSTRAP_PEERS_IDS = [
|
|
|
45
42
|
'12D3KooWS79EhkPU7ESUwgG4vyHHzW9FDNZLoWVth9b5N5NSrvaj',
|
|
46
43
|
'12D3KooWBbkCD5MpJhMc1mfPAVGEyVkQnyxPKGS7AHwDqQM2JUsk',
|
|
47
44
|
'12D3KooWKLdecs31Zmo2pLBjR9HY2vWo3VwM4eBm21Czeucbe6FL',
|
|
48
|
-
'12D3KooWBdF3g6vSJFRPoZQo7BNnkNzaWb59gpyaVzsgtNTVeu8H'
|
|
49
|
-
'12D3KooWFhXabKDwALpzqMbto94sB7rvmZ6M28hs9Y9xSopDKwQr'
|
|
45
|
+
'12D3KooWBdF3g6vSJFRPoZQo7BNnkNzaWb59gpyaVzsgtNTVeu8H'
|
|
50
46
|
];
|
|
51
47
|
|
|
52
48
|
const CONFIG_KNOWN_BOOTSTRAP_HYBRID_IDS = [
|
|
53
49
|
'12D3KooWFhXabKDwALpzqMbto94sB7rvmZ6M28hs9Y9xSopDKwQr'
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
const CONFIG_KNOWN_BOOTSTRAP_PEERS_IDS = CONFIG_KNOWN_BOOTSTRAP_PUBLIC_IDS.concat(CONFIG_KNOWN_BOOTSTRAP_HYBRID_IDS);
|
|
53
|
+
|
|
54
|
+
const CONFIG_KNOWN_BOOTSTRAP_PEERS_ADDRS = [
|
|
54
55
|
];
|
|
55
56
|
|
|
56
57
|
/* eslint-disable import/export */
|
|
@@ -368,6 +369,8 @@ class webpeerjs{
|
|
|
368
369
|
this.status = (function(libp2p) {
|
|
369
370
|
return libp2p.status
|
|
370
371
|
})(this.#libp2p);
|
|
372
|
+
|
|
373
|
+
this.status = 'unconnected';
|
|
371
374
|
|
|
372
375
|
this.IPFS = (function(libp2p,discoveredPeers) {
|
|
373
376
|
const obj = {libp2p,discoveredPeers};
|
|
@@ -423,11 +426,7 @@ class webpeerjs{
|
|
|
423
426
|
const now = new Date().getTime();
|
|
424
427
|
const metadata = {addrs:address,last:now};
|
|
425
428
|
this.#connectedPeers.set(id,metadata);
|
|
426
|
-
this.#
|
|
427
|
-
for(const peer of this.#connectedPeers){
|
|
428
|
-
const item = {id:peer[0],address:peer[1].addrs};
|
|
429
|
-
this.#connectedPeersArr.push(item);
|
|
430
|
-
}
|
|
429
|
+
this.#updatePeers();
|
|
431
430
|
}
|
|
432
431
|
|
|
433
432
|
}
|
|
@@ -468,11 +467,7 @@ class webpeerjs{
|
|
|
468
467
|
const now = new Date().getTime();
|
|
469
468
|
const metadata = {addrs:address,last:now};
|
|
470
469
|
this.#connectedPeers.set(senderPeerId,metadata);
|
|
471
|
-
this.#
|
|
472
|
-
for(const peer of this.#connectedPeers){
|
|
473
|
-
const item = {id:peer[0],address:peer[1].addrs};
|
|
474
|
-
this.#connectedPeersArr.push(item);
|
|
475
|
-
}
|
|
470
|
+
this.#updatePeers();
|
|
476
471
|
}
|
|
477
472
|
|
|
478
473
|
//dial if not connected
|
|
@@ -536,11 +531,7 @@ class webpeerjs{
|
|
|
536
531
|
const metadata = {addrs:address,last:now};
|
|
537
532
|
this.#connectedPeers.set(id,metadata);
|
|
538
533
|
this.#webPeersAddrs.set(id,address);
|
|
539
|
-
this.#
|
|
540
|
-
for(const peer of this.#connectedPeers){
|
|
541
|
-
const item = {id:peer[0],address:peer[1].addrs};
|
|
542
|
-
this.#connectedPeersArr.push(item);
|
|
543
|
-
}
|
|
534
|
+
this.#updatePeers();
|
|
544
535
|
}
|
|
545
536
|
|
|
546
537
|
|
|
@@ -586,17 +577,6 @@ class webpeerjs{
|
|
|
586
577
|
if(signal == 'ping'){
|
|
587
578
|
//console.log('rooms',rooms)
|
|
588
579
|
}
|
|
589
|
-
|
|
590
|
-
//update connected webpeers
|
|
591
|
-
/*const now = new Date().getTime()
|
|
592
|
-
const metadata = {addrs:address,last:now}
|
|
593
|
-
this.#connectedPeers.set(id,metadata)
|
|
594
|
-
this.#webPeersAddrs.set(id,address)
|
|
595
|
-
this.#connectedPeersArr.length = 0
|
|
596
|
-
for(const peer of this.#connectedPeers){
|
|
597
|
-
const item = {id:peer[0],address:peer[1].addrs}
|
|
598
|
-
this.#connectedPeersArr.push(item)
|
|
599
|
-
}*/
|
|
600
580
|
|
|
601
581
|
}
|
|
602
582
|
}
|
|
@@ -761,11 +741,7 @@ class webpeerjs{
|
|
|
761
741
|
const now = new Date().getTime();
|
|
762
742
|
const metadata = {addrs:address,last:now};
|
|
763
743
|
this.#connectedPeers.set(id,metadata);
|
|
764
|
-
this.#
|
|
765
|
-
for(const peer of this.#connectedPeers){
|
|
766
|
-
const item = {id:peer[0],address:peer[1].addrs};
|
|
767
|
-
this.#connectedPeersArr.push(item);
|
|
768
|
-
}
|
|
744
|
+
this.#updatePeers();
|
|
769
745
|
}
|
|
770
746
|
|
|
771
747
|
}
|
|
@@ -860,6 +836,20 @@ class webpeerjs{
|
|
|
860
836
|
/*
|
|
861
837
|
PRIVATE FUNCTION
|
|
862
838
|
*/
|
|
839
|
+
|
|
840
|
+
#updatePeers(){
|
|
841
|
+
this.#connectedPeersArr.length = 0;
|
|
842
|
+
for(const peer of this.#connectedPeers){
|
|
843
|
+
const item = {id:peer[0],address:peer[1].addrs};
|
|
844
|
+
this.#connectedPeersArr.push(item);
|
|
845
|
+
}
|
|
846
|
+
if(this.#connectedPeers.size > 0){
|
|
847
|
+
this.status = 'connected';
|
|
848
|
+
}
|
|
849
|
+
else {
|
|
850
|
+
this.status = 'unconnected';
|
|
851
|
+
}
|
|
852
|
+
}
|
|
863
853
|
|
|
864
854
|
async #registerProtocol(){
|
|
865
855
|
const handler = ({ connection, stream, protocol }) => {
|
|
@@ -921,6 +911,7 @@ class webpeerjs{
|
|
|
921
911
|
//check the last seen in web peer
|
|
922
912
|
#trackLastSeen(){
|
|
923
913
|
const timeout = 25*1000;
|
|
914
|
+
const forcetimeout = 60*1000;
|
|
924
915
|
const now = new Date().getTime();
|
|
925
916
|
|
|
926
917
|
//if webpeer last seen grather then timeout send onDisconnect
|
|
@@ -928,13 +919,10 @@ class webpeerjs{
|
|
|
928
919
|
const id = peer[0];
|
|
929
920
|
const last = peer[1].last;
|
|
930
921
|
const time = now-last;
|
|
931
|
-
if(time>timeout){
|
|
922
|
+
if((time>timeout && !this.#isConnected(id))||(time>forcetimeout)){
|
|
923
|
+
|
|
932
924
|
this.#connectedPeers.delete(id);
|
|
933
|
-
this.#
|
|
934
|
-
for(const peer of this.#connectedPeers){
|
|
935
|
-
const item = {id:peer[0],address:peer[1].addrs};
|
|
936
|
-
this.#connectedPeersArr.push(item);
|
|
937
|
-
}
|
|
925
|
+
this.#updatePeers();
|
|
938
926
|
this.#onDisconnectFn(id);
|
|
939
927
|
|
|
940
928
|
//remove id from room member
|
|
@@ -946,6 +934,7 @@ class webpeerjs{
|
|
|
946
934
|
this.#rooms[room].onMembers(this.#rooms[room].members);
|
|
947
935
|
}
|
|
948
936
|
}
|
|
937
|
+
|
|
949
938
|
}
|
|
950
939
|
}
|
|
951
940
|
}
|
|
@@ -1390,8 +1379,12 @@ class webpeerjs{
|
|
|
1390
1379
|
}
|
|
1391
1380
|
|
|
1392
1381
|
async #dialUpdateSavedKnownID(){
|
|
1382
|
+
let firsttime = true;
|
|
1393
1383
|
for(const target of CONFIG_KNOWN_BOOTSTRAP_PEERS_IDS){
|
|
1394
|
-
if(
|
|
1384
|
+
if(this.#dbstoreData.has(target)){
|
|
1385
|
+
firsttime = false;
|
|
1386
|
+
}
|
|
1387
|
+
if(!this.#connections.has(target) && this.#isDialEnabled && (this.#dbstoreData.has(target) || firsttime)){
|
|
1395
1388
|
//console.log('#dialUpdateSavedKnownID()',target)
|
|
1396
1389
|
const api = CONFIG_DELEGATED_API;
|
|
1397
1390
|
const delegatedClient = createDelegatedRoutingV1HttpApiClient(api);
|
package/dist/umd/webpeerjs.js
CHANGED
|
@@ -17,10 +17,7 @@
|
|
|
17
17
|
const CONFIG_PUBSUB_PEER_DISCOVERY = [CONFIG_PEER_DISCOVERY_GLOBAL, CONFIG_PEER_DISCOVERY_UNIVERSAL_CONNECTIVITY, CONFIG_PEER_DISCOVERY_WEBPEERJS];
|
|
18
18
|
const CONFIG_DELEGATED_API = 'https://delegated-ipfs.dev';
|
|
19
19
|
|
|
20
|
-
const
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
const CONFIG_KNOWN_BOOTSTRAP_PEERS_IDS = [
|
|
20
|
+
const CONFIG_KNOWN_BOOTSTRAP_PUBLIC_IDS = [
|
|
24
21
|
'QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN',
|
|
25
22
|
'QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb',
|
|
26
23
|
'QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt',
|
|
@@ -32,12 +29,16 @@
|
|
|
32
29
|
'12D3KooWS79EhkPU7ESUwgG4vyHHzW9FDNZLoWVth9b5N5NSrvaj',
|
|
33
30
|
'12D3KooWBbkCD5MpJhMc1mfPAVGEyVkQnyxPKGS7AHwDqQM2JUsk',
|
|
34
31
|
'12D3KooWKLdecs31Zmo2pLBjR9HY2vWo3VwM4eBm21Czeucbe6FL',
|
|
35
|
-
'12D3KooWBdF3g6vSJFRPoZQo7BNnkNzaWb59gpyaVzsgtNTVeu8H'
|
|
36
|
-
'12D3KooWFhXabKDwALpzqMbto94sB7rvmZ6M28hs9Y9xSopDKwQr'
|
|
32
|
+
'12D3KooWBdF3g6vSJFRPoZQo7BNnkNzaWb59gpyaVzsgtNTVeu8H'
|
|
37
33
|
];
|
|
38
34
|
|
|
39
35
|
const CONFIG_KNOWN_BOOTSTRAP_HYBRID_IDS = [
|
|
40
36
|
'12D3KooWFhXabKDwALpzqMbto94sB7rvmZ6M28hs9Y9xSopDKwQr'
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
const CONFIG_KNOWN_BOOTSTRAP_PEERS_IDS = CONFIG_KNOWN_BOOTSTRAP_PUBLIC_IDS.concat(CONFIG_KNOWN_BOOTSTRAP_HYBRID_IDS);
|
|
40
|
+
|
|
41
|
+
const CONFIG_KNOWN_BOOTSTRAP_PEERS_ADDRS = [
|
|
41
42
|
];
|
|
42
43
|
|
|
43
44
|
/**
|
|
@@ -46153,6 +46154,8 @@
|
|
|
46153
46154
|
this.status = (function(libp2p) {
|
|
46154
46155
|
return libp2p.status
|
|
46155
46156
|
})(this.#libp2p);
|
|
46157
|
+
|
|
46158
|
+
this.status = 'unconnected';
|
|
46156
46159
|
|
|
46157
46160
|
this.IPFS = (function(libp2p,discoveredPeers) {
|
|
46158
46161
|
const obj = {libp2p,discoveredPeers};
|
|
@@ -46208,11 +46211,7 @@
|
|
|
46208
46211
|
const now = new Date().getTime();
|
|
46209
46212
|
const metadata = {addrs:address,last:now};
|
|
46210
46213
|
this.#connectedPeers.set(id,metadata);
|
|
46211
|
-
this.#
|
|
46212
|
-
for(const peer of this.#connectedPeers){
|
|
46213
|
-
const item = {id:peer[0],address:peer[1].addrs};
|
|
46214
|
-
this.#connectedPeersArr.push(item);
|
|
46215
|
-
}
|
|
46214
|
+
this.#updatePeers();
|
|
46216
46215
|
}
|
|
46217
46216
|
|
|
46218
46217
|
}
|
|
@@ -46253,11 +46252,7 @@
|
|
|
46253
46252
|
const now = new Date().getTime();
|
|
46254
46253
|
const metadata = {addrs:address,last:now};
|
|
46255
46254
|
this.#connectedPeers.set(senderPeerId,metadata);
|
|
46256
|
-
this.#
|
|
46257
|
-
for(const peer of this.#connectedPeers){
|
|
46258
|
-
const item = {id:peer[0],address:peer[1].addrs};
|
|
46259
|
-
this.#connectedPeersArr.push(item);
|
|
46260
|
-
}
|
|
46255
|
+
this.#updatePeers();
|
|
46261
46256
|
}
|
|
46262
46257
|
|
|
46263
46258
|
//dial if not connected
|
|
@@ -46321,11 +46316,7 @@
|
|
|
46321
46316
|
const metadata = {addrs:address,last:now};
|
|
46322
46317
|
this.#connectedPeers.set(id,metadata);
|
|
46323
46318
|
this.#webPeersAddrs.set(id,address);
|
|
46324
|
-
this.#
|
|
46325
|
-
for(const peer of this.#connectedPeers){
|
|
46326
|
-
const item = {id:peer[0],address:peer[1].addrs};
|
|
46327
|
-
this.#connectedPeersArr.push(item);
|
|
46328
|
-
}
|
|
46319
|
+
this.#updatePeers();
|
|
46329
46320
|
}
|
|
46330
46321
|
|
|
46331
46322
|
|
|
@@ -46371,17 +46362,6 @@
|
|
|
46371
46362
|
if(signal == 'ping'){
|
|
46372
46363
|
//console.log('rooms',rooms)
|
|
46373
46364
|
}
|
|
46374
|
-
|
|
46375
|
-
//update connected webpeers
|
|
46376
|
-
/*const now = new Date().getTime()
|
|
46377
|
-
const metadata = {addrs:address,last:now}
|
|
46378
|
-
this.#connectedPeers.set(id,metadata)
|
|
46379
|
-
this.#webPeersAddrs.set(id,address)
|
|
46380
|
-
this.#connectedPeersArr.length = 0
|
|
46381
|
-
for(const peer of this.#connectedPeers){
|
|
46382
|
-
const item = {id:peer[0],address:peer[1].addrs}
|
|
46383
|
-
this.#connectedPeersArr.push(item)
|
|
46384
|
-
}*/
|
|
46385
46365
|
|
|
46386
46366
|
}
|
|
46387
46367
|
}
|
|
@@ -46546,11 +46526,7 @@
|
|
|
46546
46526
|
const now = new Date().getTime();
|
|
46547
46527
|
const metadata = {addrs:address,last:now};
|
|
46548
46528
|
this.#connectedPeers.set(id,metadata);
|
|
46549
|
-
this.#
|
|
46550
|
-
for(const peer of this.#connectedPeers){
|
|
46551
|
-
const item = {id:peer[0],address:peer[1].addrs};
|
|
46552
|
-
this.#connectedPeersArr.push(item);
|
|
46553
|
-
}
|
|
46529
|
+
this.#updatePeers();
|
|
46554
46530
|
}
|
|
46555
46531
|
|
|
46556
46532
|
}
|
|
@@ -46645,6 +46621,20 @@
|
|
|
46645
46621
|
/*
|
|
46646
46622
|
PRIVATE FUNCTION
|
|
46647
46623
|
*/
|
|
46624
|
+
|
|
46625
|
+
#updatePeers(){
|
|
46626
|
+
this.#connectedPeersArr.length = 0;
|
|
46627
|
+
for(const peer of this.#connectedPeers){
|
|
46628
|
+
const item = {id:peer[0],address:peer[1].addrs};
|
|
46629
|
+
this.#connectedPeersArr.push(item);
|
|
46630
|
+
}
|
|
46631
|
+
if(this.#connectedPeers.size > 0){
|
|
46632
|
+
this.status = 'connected';
|
|
46633
|
+
}
|
|
46634
|
+
else {
|
|
46635
|
+
this.status = 'unconnected';
|
|
46636
|
+
}
|
|
46637
|
+
}
|
|
46648
46638
|
|
|
46649
46639
|
async #registerProtocol(){
|
|
46650
46640
|
const handler = ({ connection, stream, protocol }) => {
|
|
@@ -46706,6 +46696,7 @@
|
|
|
46706
46696
|
//check the last seen in web peer
|
|
46707
46697
|
#trackLastSeen(){
|
|
46708
46698
|
const timeout = 25*1000;
|
|
46699
|
+
const forcetimeout = 60*1000;
|
|
46709
46700
|
const now = new Date().getTime();
|
|
46710
46701
|
|
|
46711
46702
|
//if webpeer last seen grather then timeout send onDisconnect
|
|
@@ -46713,13 +46704,10 @@
|
|
|
46713
46704
|
const id = peer[0];
|
|
46714
46705
|
const last = peer[1].last;
|
|
46715
46706
|
const time = now-last;
|
|
46716
|
-
if(time>timeout){
|
|
46707
|
+
if((time>timeout && !this.#isConnected(id))||(time>forcetimeout)){
|
|
46708
|
+
|
|
46717
46709
|
this.#connectedPeers.delete(id);
|
|
46718
|
-
this.#
|
|
46719
|
-
for(const peer of this.#connectedPeers){
|
|
46720
|
-
const item = {id:peer[0],address:peer[1].addrs};
|
|
46721
|
-
this.#connectedPeersArr.push(item);
|
|
46722
|
-
}
|
|
46710
|
+
this.#updatePeers();
|
|
46723
46711
|
this.#onDisconnectFn(id);
|
|
46724
46712
|
|
|
46725
46713
|
//remove id from room member
|
|
@@ -46731,6 +46719,7 @@
|
|
|
46731
46719
|
this.#rooms[room].onMembers(this.#rooms[room].members);
|
|
46732
46720
|
}
|
|
46733
46721
|
}
|
|
46722
|
+
|
|
46734
46723
|
}
|
|
46735
46724
|
}
|
|
46736
46725
|
}
|
|
@@ -47175,8 +47164,12 @@
|
|
|
47175
47164
|
}
|
|
47176
47165
|
|
|
47177
47166
|
async #dialUpdateSavedKnownID(){
|
|
47167
|
+
let firsttime = true;
|
|
47178
47168
|
for(const target of CONFIG_KNOWN_BOOTSTRAP_PEERS_IDS){
|
|
47179
|
-
if(
|
|
47169
|
+
if(this.#dbstoreData.has(target)){
|
|
47170
|
+
firsttime = false;
|
|
47171
|
+
}
|
|
47172
|
+
if(!this.#connections.has(target) && this.#isDialEnabled && (this.#dbstoreData.has(target) || firsttime)){
|
|
47180
47173
|
//console.log('#dialUpdateSavedKnownID()',target)
|
|
47181
47174
|
const api = CONFIG_DELEGATED_API;
|
|
47182
47175
|
const delegatedClient = createDelegatedRoutingV1HttpApiClient(api);
|
package/package.json
CHANGED
package/src/config.js
CHANGED
|
@@ -17,10 +17,7 @@ export const CONFIG_DNS_RESOLVER = 'https://dns.google/resolve'
|
|
|
17
17
|
export const CONFIG_KNOWN_BOOTSTRAP_DNS = '_dnsaddr.bootstrap.libp2p.io'
|
|
18
18
|
export const CONFIG_JOIN_ROOM_VERSION = 1
|
|
19
19
|
|
|
20
|
-
export const
|
|
21
|
-
]
|
|
22
|
-
|
|
23
|
-
export const CONFIG_KNOWN_BOOTSTRAP_PEERS_IDS = [
|
|
20
|
+
export const CONFIG_KNOWN_BOOTSTRAP_PUBLIC_IDS = [
|
|
24
21
|
'QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN',
|
|
25
22
|
'QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb',
|
|
26
23
|
'QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt',
|
|
@@ -32,10 +29,14 @@ export const CONFIG_KNOWN_BOOTSTRAP_PEERS_IDS = [
|
|
|
32
29
|
'12D3KooWS79EhkPU7ESUwgG4vyHHzW9FDNZLoWVth9b5N5NSrvaj',
|
|
33
30
|
'12D3KooWBbkCD5MpJhMc1mfPAVGEyVkQnyxPKGS7AHwDqQM2JUsk',
|
|
34
31
|
'12D3KooWKLdecs31Zmo2pLBjR9HY2vWo3VwM4eBm21Czeucbe6FL',
|
|
35
|
-
'12D3KooWBdF3g6vSJFRPoZQo7BNnkNzaWb59gpyaVzsgtNTVeu8H'
|
|
36
|
-
'12D3KooWFhXabKDwALpzqMbto94sB7rvmZ6M28hs9Y9xSopDKwQr'
|
|
32
|
+
'12D3KooWBdF3g6vSJFRPoZQo7BNnkNzaWb59gpyaVzsgtNTVeu8H'
|
|
37
33
|
]
|
|
38
34
|
|
|
39
35
|
export const CONFIG_KNOWN_BOOTSTRAP_HYBRID_IDS = [
|
|
40
36
|
'12D3KooWFhXabKDwALpzqMbto94sB7rvmZ6M28hs9Y9xSopDKwQr'
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
export const CONFIG_KNOWN_BOOTSTRAP_PEERS_IDS = CONFIG_KNOWN_BOOTSTRAP_PUBLIC_IDS.concat(CONFIG_KNOWN_BOOTSTRAP_HYBRID_IDS)
|
|
40
|
+
|
|
41
|
+
export const CONFIG_KNOWN_BOOTSTRAP_PEERS_ADDRS = [
|
|
41
42
|
]
|
package/src/webpeerjs.js
CHANGED
|
@@ -120,6 +120,8 @@ class webpeerjs{
|
|
|
120
120
|
this.status = (function(libp2p) {
|
|
121
121
|
return libp2p.status
|
|
122
122
|
})(this.#libp2p);
|
|
123
|
+
|
|
124
|
+
this.status = 'unconnected'
|
|
123
125
|
|
|
124
126
|
this.IPFS = (function(libp2p,discoveredPeers) {
|
|
125
127
|
const obj = {libp2p,discoveredPeers}
|
|
@@ -175,11 +177,7 @@ class webpeerjs{
|
|
|
175
177
|
const now = new Date().getTime()
|
|
176
178
|
const metadata = {addrs:address,last:now}
|
|
177
179
|
this.#connectedPeers.set(id,metadata)
|
|
178
|
-
this.#
|
|
179
|
-
for(const peer of this.#connectedPeers){
|
|
180
|
-
const item = {id:peer[0],address:peer[1].addrs}
|
|
181
|
-
this.#connectedPeersArr.push(item)
|
|
182
|
-
}
|
|
180
|
+
this.#updatePeers()
|
|
183
181
|
}
|
|
184
182
|
|
|
185
183
|
}
|
|
@@ -220,11 +218,7 @@ class webpeerjs{
|
|
|
220
218
|
const now = new Date().getTime()
|
|
221
219
|
const metadata = {addrs:address,last:now}
|
|
222
220
|
this.#connectedPeers.set(senderPeerId,metadata)
|
|
223
|
-
this.#
|
|
224
|
-
for(const peer of this.#connectedPeers){
|
|
225
|
-
const item = {id:peer[0],address:peer[1].addrs}
|
|
226
|
-
this.#connectedPeersArr.push(item)
|
|
227
|
-
}
|
|
221
|
+
this.#updatePeers()
|
|
228
222
|
}
|
|
229
223
|
|
|
230
224
|
//dial if not connected
|
|
@@ -288,11 +282,7 @@ class webpeerjs{
|
|
|
288
282
|
const metadata = {addrs:address,last:now}
|
|
289
283
|
this.#connectedPeers.set(id,metadata)
|
|
290
284
|
this.#webPeersAddrs.set(id,address)
|
|
291
|
-
this.#
|
|
292
|
-
for(const peer of this.#connectedPeers){
|
|
293
|
-
const item = {id:peer[0],address:peer[1].addrs}
|
|
294
|
-
this.#connectedPeersArr.push(item)
|
|
295
|
-
}
|
|
285
|
+
this.#updatePeers()
|
|
296
286
|
}
|
|
297
287
|
|
|
298
288
|
|
|
@@ -338,17 +328,6 @@ class webpeerjs{
|
|
|
338
328
|
if(signal == 'ping'){
|
|
339
329
|
//console.log('rooms',rooms)
|
|
340
330
|
}
|
|
341
|
-
|
|
342
|
-
//update connected webpeers
|
|
343
|
-
/*const now = new Date().getTime()
|
|
344
|
-
const metadata = {addrs:address,last:now}
|
|
345
|
-
this.#connectedPeers.set(id,metadata)
|
|
346
|
-
this.#webPeersAddrs.set(id,address)
|
|
347
|
-
this.#connectedPeersArr.length = 0
|
|
348
|
-
for(const peer of this.#connectedPeers){
|
|
349
|
-
const item = {id:peer[0],address:peer[1].addrs}
|
|
350
|
-
this.#connectedPeersArr.push(item)
|
|
351
|
-
}*/
|
|
352
331
|
|
|
353
332
|
}
|
|
354
333
|
}
|
|
@@ -521,11 +500,7 @@ class webpeerjs{
|
|
|
521
500
|
const now = new Date().getTime()
|
|
522
501
|
const metadata = {addrs:address,last:now}
|
|
523
502
|
this.#connectedPeers.set(id,metadata)
|
|
524
|
-
this.#
|
|
525
|
-
for(const peer of this.#connectedPeers){
|
|
526
|
-
const item = {id:peer[0],address:peer[1].addrs}
|
|
527
|
-
this.#connectedPeersArr.push(item)
|
|
528
|
-
}
|
|
503
|
+
this.#updatePeers()
|
|
529
504
|
}
|
|
530
505
|
|
|
531
506
|
}
|
|
@@ -620,6 +595,20 @@ class webpeerjs{
|
|
|
620
595
|
/*
|
|
621
596
|
PRIVATE FUNCTION
|
|
622
597
|
*/
|
|
598
|
+
|
|
599
|
+
#updatePeers(){
|
|
600
|
+
this.#connectedPeersArr.length = 0
|
|
601
|
+
for(const peer of this.#connectedPeers){
|
|
602
|
+
const item = {id:peer[0],address:peer[1].addrs}
|
|
603
|
+
this.#connectedPeersArr.push(item)
|
|
604
|
+
}
|
|
605
|
+
if(this.#connectedPeers.size > 0){
|
|
606
|
+
this.status = 'connected'
|
|
607
|
+
}
|
|
608
|
+
else{
|
|
609
|
+
this.status = 'unconnected'
|
|
610
|
+
}
|
|
611
|
+
}
|
|
623
612
|
|
|
624
613
|
async #registerProtocol(){
|
|
625
614
|
const handler = ({ connection, stream, protocol }) => {
|
|
@@ -681,6 +670,7 @@ class webpeerjs{
|
|
|
681
670
|
//check the last seen in web peer
|
|
682
671
|
#trackLastSeen(){
|
|
683
672
|
const timeout = 25*1000
|
|
673
|
+
const forcetimeout = 60*1000
|
|
684
674
|
const now = new Date().getTime()
|
|
685
675
|
|
|
686
676
|
//if webpeer last seen grather then timeout send onDisconnect
|
|
@@ -688,13 +678,10 @@ class webpeerjs{
|
|
|
688
678
|
const id = peer[0]
|
|
689
679
|
const last = peer[1].last
|
|
690
680
|
const time = now-last
|
|
691
|
-
if(time>timeout){
|
|
681
|
+
if((time>timeout && !this.#isConnected(id))||(time>forcetimeout)){
|
|
682
|
+
|
|
692
683
|
this.#connectedPeers.delete(id)
|
|
693
|
-
this.#
|
|
694
|
-
for(const peer of this.#connectedPeers){
|
|
695
|
-
const item = {id:peer[0],address:peer[1].addrs}
|
|
696
|
-
this.#connectedPeersArr.push(item)
|
|
697
|
-
}
|
|
684
|
+
this.#updatePeers()
|
|
698
685
|
this.#onDisconnectFn(id)
|
|
699
686
|
|
|
700
687
|
//remove id from room member
|
|
@@ -706,6 +693,7 @@ class webpeerjs{
|
|
|
706
693
|
this.#rooms[room].onMembers(this.#rooms[room].members)
|
|
707
694
|
}
|
|
708
695
|
}
|
|
696
|
+
|
|
709
697
|
}
|
|
710
698
|
}
|
|
711
699
|
}
|
|
@@ -1154,8 +1142,12 @@ class webpeerjs{
|
|
|
1154
1142
|
}
|
|
1155
1143
|
|
|
1156
1144
|
async #dialUpdateSavedKnownID(){
|
|
1145
|
+
let firsttime = true
|
|
1157
1146
|
for(const target of config.CONFIG_KNOWN_BOOTSTRAP_PEERS_IDS){
|
|
1158
|
-
if(
|
|
1147
|
+
if(this.#dbstoreData.has(target)){
|
|
1148
|
+
firsttime = false
|
|
1149
|
+
}
|
|
1150
|
+
if(!this.#connections.has(target) && this.#isDialEnabled && (this.#dbstoreData.has(target) || firsttime)){
|
|
1159
1151
|
//console.log('#dialUpdateSavedKnownID()',target)
|
|
1160
1152
|
const api = config.CONFIG_DELEGATED_API
|
|
1161
1153
|
const delegatedClient = createDelegatedRoutingV1HttpApiClient(api)
|