webpeerjs 0.0.2 → 0.0.3

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 +1 @@
1
- {"type": "commonjs","types": "webpeerjs.d.ts"}
1
+ {"type": "commonjs"}
@@ -43220,6 +43220,7 @@
43220
43220
  const json = JSON.parse(msg);
43221
43221
  const prefix = json.prefix;
43222
43222
  const room = json.room;
43223
+ const rooms = json.rooms;
43223
43224
  const message = json.message;
43224
43225
  const signal = json.signal;
43225
43226
  const id = json.id;
@@ -43253,7 +43254,9 @@
43253
43254
  if(this.#rooms[room]){
43254
43255
 
43255
43256
  //inbound message
43256
- this.#rooms[room].onMessage(message,id);
43257
+ if(message){
43258
+ this.#rooms[room].onMessage(message,id);
43259
+ }
43257
43260
 
43258
43261
  //update room members
43259
43262
  if(!this.#rooms[room].members.includes(id)){
@@ -43263,15 +43266,26 @@
43263
43266
  }
43264
43267
  }
43265
43268
 
43269
+ if(rooms){
43270
+ for(const room of Object.keys(this.#rooms)){
43271
+ //update room members
43272
+ if(!this.#rooms[room].members.includes(id)){
43273
+ this.#rooms[room].members.push(id);
43274
+ this.#rooms[room].onMembers(this.#rooms[room].members);
43275
+ }
43276
+ }
43277
+ }
43278
+
43266
43279
  if(signal){
43267
43280
 
43268
43281
  //repply announce with ping
43269
43282
  if(signal == 'announce'){
43270
- setTimeout(()=>{this.#ping();},1000);
43283
+ setTimeout(()=>{this.#ping('yes');},1000);
43284
+ //console.log('rooms',rooms)
43271
43285
  }
43272
43286
 
43273
43287
  if(signal == 'ping'){
43274
- //do nothing
43288
+ //console.log('rooms',rooms)
43275
43289
  }
43276
43290
 
43277
43291
  //update connected webpeers
@@ -43590,7 +43604,7 @@
43590
43604
  //announce and ping via pupsub peer discovery
43591
43605
  async #announce(){
43592
43606
  const topics = CONFIG_PUBSUB_PEER_DISCOVERY;
43593
- const data = JSON.stringify({prefix:CONFIG_PREFIX,signal:'announce',id:this.#libp2p.peerId.toString(),address:this.address});
43607
+ const data = JSON.stringify({prefix:CONFIG_PREFIX,signal:'announce',id:this.#libp2p.peerId.toString(),address:this.address,rooms:this.#rooms});
43594
43608
  const peer = {
43595
43609
  publicKey: this.#libp2p.peerId.publicKey,
43596
43610
  addrs: [uint8ArrayFromString(data)],
@@ -43602,7 +43616,7 @@
43602
43616
  }
43603
43617
  async #ping(){
43604
43618
  const topics = CONFIG_PUBSUB_PEER_DISCOVERY;
43605
- const data = JSON.stringify({prefix:CONFIG_PREFIX,signal:'ping',id:this.#libp2p.peerId.toString(),address:this.address});
43619
+ const data = JSON.stringify({prefix:CONFIG_PREFIX,signal:'ping',id:this.#libp2p.peerId.toString(),address:this.address,rooms:this.#rooms});
43606
43620
  const peer = {
43607
43621
  publicKey: this.#libp2p.peerId.publicKey,
43608
43622
  addrs: [uint8ArrayFromString(data)],
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "webpeerjs",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Simple peer-to-peer with IPFS",
5
5
  "main": "./dist/umd/webpeerjs.js",
6
- "module": "./dist/esm/webpeerjs.js",
6
+ "module": "./src/webpeerjs.js",
7
7
  "imports": {
8
- "#/pubsub-peer-discovery/*.js": "@libp2p/pubsub-peer-discovery/dist/src/*.js"
8
+ "#/pubsub-peer-discovery/*.js": "./node_modules/@libp2p/pubsub-peer-discovery/dist/src/*.js"
9
9
  },
10
10
  "exports": {
11
11
  ".": {
12
- "import": "./dist/esm/webpeerjs.js",
12
+ "import": "./src/webpeerjs.js",
13
13
  "require": "./dist/umd/webpeerjs.js"
14
14
  }
15
15
  },
@@ -25,7 +25,7 @@
25
25
  "eslint:fix": "eslint ./src --fix",
26
26
 
27
27
  "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);\"",
28
- "build-all": "tsc -p config/tsconfig-rollup.json && rollup -c temp/config/rollup.config.build.js && echo {\"type\": \"commonjs\",\"types\": \"webpeerjs.d.ts\"}>dist\\umd\\package.json && echo {\"type\": \"module\",\"types\": \"webpeerjs.d.ts\"}>dist\\esm\\package.json",
28
+ "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",
29
29
  "build-types": "tsc -p config/tsconfig-esm.json",
30
30
  "build": "npm run removedir dist temp && npm run build-all && npm run build-types",
31
31
 
@@ -0,0 +1,22 @@
1
+ export const CONFIG_PREFIX: "webpeerjs";
2
+ export const CONFIG_BLOCKSTORE_PATH: string;
3
+ export const CONFIG_DATASTORE_PATH: string;
4
+ export const CONFIG_DBSTORE_PATH: string;
5
+ export const CONFIG_MAX_CONNECTIONS: 50;
6
+ export const CONFIG_MIN_CONNECTIONS: 0;
7
+ export const CONFIG_DISCOVER_RELAYS: 2;
8
+ export const CONFIG_PEER_DISCOVERY_UNIVERSAL_CONNECTIVITY: "universal-connectivity-browser-peer-discovery";
9
+ export const CONFIG_PUBSUB_PEER_DISCOVERY: string[];
10
+ export const CONFIG_PUPSUB_TOPIC: string;
11
+ export const CONFIG_DELEGATED_API: "https://delegated-ipfs.dev";
12
+ export const CONFIG_DNS_RESOLVER: "https://dns.google/resolve";
13
+ export const CONFIG_KNOWN_BOOTSTRAP_DNS: "_dnsaddr.bootstrap.libp2p.io";
14
+ export const CONFIG_JOIN_ROOM_VERSION: 1;
15
+ export const CONFIG_KNOWN_BOOTSTRAP_PEERS_ADDRS: {
16
+ Peers: {
17
+ Addrs: string[];
18
+ ID: string;
19
+ Schema: string;
20
+ }[];
21
+ }[];
22
+ export const CONFIG_KNOWN_BOOTSTRAP_PEER_IDS: string[];
@@ -0,0 +1 @@
1
+ {"type": "module"}
package/src/utils.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export function uint8ArrayToString(uint8Array: any): string;
2
+ export function uint8ArrayFromString(string: any): Uint8Array;
3
+ export function first(farr: any): Promise<any>;
4
+ export function msgIdFnStrictNoSign(msg: any): Promise<Uint8Array>;
5
+ export function metrics(data: any): boolean | undefined;
6
+ export function mkErr(msg: any): Error;
7
+ import { Key } from 'interface-datastore';
8
+ export { PBPeer, Key };
package/src/webpeerjs.js CHANGED
@@ -217,6 +217,7 @@ class webpeerjs{
217
217
  const json = JSON.parse(msg)
218
218
  const prefix = json.prefix
219
219
  const room = json.room
220
+ const rooms = json.rooms
220
221
  const message = json.message
221
222
  const signal = json.signal
222
223
  const id = json.id
@@ -250,7 +251,9 @@ class webpeerjs{
250
251
  if(this.#rooms[room]){
251
252
 
252
253
  //inbound message
253
- this.#rooms[room].onMessage(message,id)
254
+ if(message){
255
+ this.#rooms[room].onMessage(message,id)
256
+ }
254
257
 
255
258
  //update room members
256
259
  if(!this.#rooms[room].members.includes(id)){
@@ -260,15 +263,26 @@ class webpeerjs{
260
263
  }
261
264
  }
262
265
 
266
+ if(rooms){
267
+ for(const room of Object.keys(this.#rooms)){
268
+ //update room members
269
+ if(!this.#rooms[room].members.includes(id)){
270
+ this.#rooms[room].members.push(id)
271
+ this.#rooms[room].onMembers(this.#rooms[room].members)
272
+ }
273
+ }
274
+ }
275
+
263
276
  if(signal){
264
277
 
265
278
  //repply announce with ping
266
279
  if(signal == 'announce'){
267
- setTimeout(()=>{this.#ping()},1000)
280
+ setTimeout(()=>{this.#ping('yes')},1000)
281
+ //console.log('rooms',rooms)
268
282
  }
269
283
 
270
284
  if(signal == 'ping'){
271
- //do nothing
285
+ //console.log('rooms',rooms)
272
286
  }
273
287
 
274
288
  //update connected webpeers
@@ -593,7 +607,7 @@ class webpeerjs{
593
607
  //announce and ping via pupsub peer discovery
594
608
  async #announce(){
595
609
  const topics = config.CONFIG_PUBSUB_PEER_DISCOVERY
596
- const data = JSON.stringify({prefix:config.CONFIG_PREFIX,signal:'announce',id:this.#libp2p.peerId.toString(),address:this.address})
610
+ const data = JSON.stringify({prefix:config.CONFIG_PREFIX,signal:'announce',id:this.#libp2p.peerId.toString(),address:this.address,rooms:this.#rooms})
597
611
  const peer = {
598
612
  publicKey: this.#libp2p.peerId.publicKey,
599
613
  addrs: [uint8ArrayFromString(data)],
@@ -605,7 +619,7 @@ class webpeerjs{
605
619
  }
606
620
  async #ping(){
607
621
  const topics = config.CONFIG_PUBSUB_PEER_DISCOVERY
608
- const data = JSON.stringify({prefix:config.CONFIG_PREFIX,signal:'ping',id:this.#libp2p.peerId.toString(),address:this.address})
622
+ const data = JSON.stringify({prefix:config.CONFIG_PREFIX,signal:'ping',id:this.#libp2p.peerId.toString(),address:this.address,rooms:this.#rooms})
609
623
  const peer = {
610
624
  publicKey: this.#libp2p.peerId.publicKey,
611
625
  addrs: [uint8ArrayFromString(data)],
File without changes