webpeerjs 0.1.0 → 0.1.1
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 +7 -2
- package/dist/esm/webpeerjs.js +79 -1999
- package/dist/umd/webpeerjs.js +47 -50793
- package/package.json +4 -3
- package/src/config.js +1 -0
- package/src/webpeerjs.js +14 -8
- package/dist/esm/webpeerjs.d.ts +0 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webpeerjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Simple peer-to-peer with IPFS",
|
|
5
5
|
"main": "./dist/umd/webpeerjs.js",
|
|
6
6
|
"module": "./src/webpeerjs.js",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"removedir": "node -e \"var fs = require('fs'); try{process.argv.slice(1).map((fpath) => fs.rmdirSync(fpath, { recursive: true }))}catch(err){console.log(`Dist not found`)}; process.exit(0);\"",
|
|
25
25
|
"build-all": "tsc -p config/tsconfig-rollup.json && rollup -c temp/config/rollup.config.build.js && echo {\"type\": \"commonjs\"}>dist\\umd\\package.json && echo {\"type\": \"module\"}>dist\\esm\\package.json",
|
|
26
26
|
"build-types": "tsc -p config/tsconfig-esm.json",
|
|
27
|
-
"build": "npm run removedir dist temp && npm run build-all
|
|
28
|
-
"test": "
|
|
27
|
+
"build": "npm run removedir dist temp && npm run build-all",
|
|
28
|
+
"test": "cd test && cd project && npm start"
|
|
29
29
|
},
|
|
30
30
|
"repository": {
|
|
31
31
|
"type": "git",
|
|
@@ -70,6 +70,7 @@
|
|
|
70
70
|
"@eslint/js": "^9.4.0",
|
|
71
71
|
"@rollup/plugin-commonjs": "^25.0.8",
|
|
72
72
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
73
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
73
74
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
74
75
|
"eslint": "^9.4.0",
|
|
75
76
|
"globals": "^15.3.0",
|
package/src/config.js
CHANGED
package/src/webpeerjs.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//! WebpeerJS -- https://github.com/nuzulul/webpeerjs
|
|
1
2
|
import * as config from './config'
|
|
2
3
|
import {
|
|
3
4
|
mkErr,
|
|
@@ -327,13 +328,18 @@ class webpeerjs{
|
|
|
327
328
|
}
|
|
328
329
|
|
|
329
330
|
if(rooms){
|
|
330
|
-
for(const room of
|
|
331
|
-
|
|
332
|
-
if(
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
331
|
+
for(const room of rooms){
|
|
332
|
+
|
|
333
|
+
if(this.#rooms[room]){
|
|
334
|
+
|
|
335
|
+
//update room members
|
|
336
|
+
if(!this.#rooms[room].members.includes(id)){
|
|
337
|
+
if(this.#connectedPeers.has(id)){
|
|
338
|
+
this.#rooms[room].members.push(id)
|
|
339
|
+
this.#rooms[room].onMembers(this.#rooms[room].members)
|
|
340
|
+
}
|
|
336
341
|
}
|
|
342
|
+
|
|
337
343
|
}
|
|
338
344
|
}
|
|
339
345
|
}
|
|
@@ -1072,7 +1078,7 @@ class webpeerjs{
|
|
|
1072
1078
|
//announce and ping via pupsub peer discovery
|
|
1073
1079
|
async #announce(){
|
|
1074
1080
|
const topics = config.CONFIG_PUPSUB_PEER_DATA
|
|
1075
|
-
const data = JSON.stringify({prefix:config.CONFIG_PREFIX,signal:'announce',id:this.#libp2p.peerId.toString(),address:this.address,rooms:this.#rooms})
|
|
1081
|
+
const data = JSON.stringify({prefix:config.CONFIG_PREFIX,signal:'announce',id:this.#libp2p.peerId.toString(),address:this.address,rooms:Object.keys(this.#rooms)})
|
|
1076
1082
|
const peer = {
|
|
1077
1083
|
publicKey: this.#libp2p.peerId.publicKey,
|
|
1078
1084
|
addrs: [uint8ArrayFromString(data)],
|
|
@@ -1084,7 +1090,7 @@ class webpeerjs{
|
|
|
1084
1090
|
}
|
|
1085
1091
|
async #ping(){
|
|
1086
1092
|
const topics = config.CONFIG_PUPSUB_PEER_DATA
|
|
1087
|
-
const data = JSON.stringify({prefix:config.CONFIG_PREFIX,signal:'ping',id:this.#libp2p.peerId.toString(),address:this.address,rooms:this.#rooms})
|
|
1093
|
+
const data = JSON.stringify({prefix:config.CONFIG_PREFIX,signal:'ping',id:this.#libp2p.peerId.toString(),address:this.address,rooms:Object.keys(this.#rooms)})
|
|
1088
1094
|
const peer = {
|
|
1089
1095
|
publicKey: this.#libp2p.peerId.publicKey,
|
|
1090
1096
|
addrs: [uint8ArrayFromString(data)],
|
package/dist/esm/webpeerjs.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export class webpeerjs {
|
|
2
|
-
static createWebpeer(): Promise<webpeerjs>;
|
|
3
|
-
constructor(libp2p: any, dbstore: any, onMetrics: any);
|
|
4
|
-
id: any;
|
|
5
|
-
status: string;
|
|
6
|
-
IPFS: {
|
|
7
|
-
libp2p: any;
|
|
8
|
-
discoveredPeers: Map<any, any>;
|
|
9
|
-
};
|
|
10
|
-
address: any[];
|
|
11
|
-
peers: any[];
|
|
12
|
-
onConnect: (f: any) => any;
|
|
13
|
-
onDisconnect: (f: any) => any;
|
|
14
|
-
joinRoom: (room: any) => any[];
|
|
15
|
-
dial(addr: any): void;
|
|
16
|
-
#private;
|
|
17
|
-
}
|