@leofcoin/peernet 0.9.11 → 0.10.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.
@@ -16,10 +16,17 @@ import MultiWallet from '@leofcoin/multi-wallet';
16
16
  class PeernetPeer {
17
17
  constructor(id, connection) {
18
18
  this._events = {};
19
+ this.bw = {
20
+ up: 0,
21
+ down: 0,
22
+ };
19
23
  this.id = id;
20
24
  this.connection = connection;
21
25
 
22
- this.connection.on('data', (message) => pubsub.publish('peernet.data', JSON.parse(message.toString())));
26
+ this.connection.on('data', (message) => {
27
+ this.bw.down += message.length;
28
+ pubsub.publish('peernet.data', JSON.parse(message.toString()));
29
+ });
23
30
  }
24
31
 
25
32
  request(data) {
@@ -45,6 +52,8 @@ class PeernetPeer {
45
52
 
46
53
  write(data) {
47
54
  if (!Buffer.isBuffer(data)) data = Buffer.from(data);
55
+
56
+ this.bw.up += data.length;
48
57
  this.connection.write(data);
49
58
  }
50
59
 
@@ -263,7 +272,7 @@ class LeofcoinStorage$1 {
263
272
 
264
273
  }
265
274
 
266
- var version = "0.9.10";
275
+ var version = "0.10.0";
267
276
 
268
277
  var api$1 = {
269
278
  version: ({send}) => send({client: '@peernet/api/http', version}),
@@ -2177,7 +2186,7 @@ class Peernet {
2177
2186
  */
2178
2187
  this.client = new PeernetClient({...options, id});
2179
2188
  if (globalThis.onbeforeunload) {
2180
- globalThisaddEventListener('beforeunload', async () => this.client.close());
2189
+ globalThis.addEventListener('beforeunload', async () => this.client.close());
2181
2190
  }
2182
2191
  return this
2183
2192
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/peernet",
3
- "version": "0.9.11",
3
+ "version": "0.10.1",
4
4
  "description": "",
5
5
  "main": "dist/commonjs/peernet.js",
6
6
  "module": "dist/module/peernet.js",
package/src/peer.js CHANGED
@@ -1,10 +1,17 @@
1
1
  export default class PeernetPeer {
2
2
  constructor(id, connection) {
3
3
  this._events = {}
4
+ this.bw = {
5
+ up: 0,
6
+ down: 0,
7
+ }
4
8
  this.id = id
5
9
  this.connection = connection
6
10
 
7
- this.connection.on('data', (message) => pubsub.publish('peernet.data', JSON.parse(message.toString())))
11
+ this.connection.on('data', (message) => {
12
+ this.bw.down += message.length
13
+ pubsub.publish('peernet.data', JSON.parse(message.toString()))
14
+ })
8
15
  }
9
16
 
10
17
  request(data) {
@@ -30,6 +37,8 @@ export default class PeernetPeer {
30
37
 
31
38
  write(data) {
32
39
  if (!Buffer.isBuffer(data)) data = Buffer.from(data)
40
+
41
+ this.bw.up += data.length
33
42
  this.connection.write(data)
34
43
  }
35
44
 
package/src/peernet.js CHANGED
@@ -249,7 +249,7 @@ export default class Peernet {
249
249
  */
250
250
  this.client = new Client({...options, id})
251
251
  if (globalThis.onbeforeunload) {
252
- globalThisaddEventListener('beforeunload', async () => this.client.close());
252
+ globalThis.addEventListener('beforeunload', async () => this.client.close());
253
253
  }
254
254
  return this
255
255
  }