@leofcoin/peernet 0.9.10 → 0.9.11
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/dist/browser/peernet.js +654 -651
- package/dist/commonjs/peernet.js +654 -651
- package/dist/module/peernet.js +10 -7
- package/package.json +1 -1
- package/src/peernet.js +15 -12
package/dist/module/peernet.js
CHANGED
|
@@ -263,7 +263,7 @@ class LeofcoinStorage$1 {
|
|
|
263
263
|
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
-
var version = "0.9.
|
|
266
|
+
var version = "0.9.10";
|
|
267
267
|
|
|
268
268
|
var api$1 = {
|
|
269
269
|
version: ({send}) => send({client: '@peernet/api/http', version}),
|
|
@@ -2132,18 +2132,18 @@ class Peernet {
|
|
|
2132
2132
|
this.peerId = id;
|
|
2133
2133
|
|
|
2134
2134
|
pubsub.subscribe('peer:discovered', async (peer) => {
|
|
2135
|
-
this._peerHandler.discover(peer);
|
|
2136
2135
|
peer.on('peernet.data', async (message) => {
|
|
2137
2136
|
const id = message.id;
|
|
2138
2137
|
message = new PeernetMessage(Buffer.from(message.data.data));
|
|
2139
2138
|
const proto = protoFor(message.decoded.data);
|
|
2140
2139
|
await this._protoHandler({id, proto}, peer);
|
|
2141
|
-
const fulldId = this._getPeerId(peer.id);
|
|
2142
|
-
if (fulldId && this._discovered.indexOf(peer.id) === -1) {
|
|
2143
|
-
this._discovered.push(peer.id);
|
|
2144
|
-
pubsub.publish('peer:connected', peer);
|
|
2145
|
-
}
|
|
2146
2140
|
});
|
|
2141
|
+
await this._peerHandler.discover(peer);
|
|
2142
|
+
const fulldId = this._getPeerId(peer.id);
|
|
2143
|
+
if (fulldId && this._discovered.indexOf(peer.id) === -1) {
|
|
2144
|
+
this._discovered.push(peer.id);
|
|
2145
|
+
pubsub.publish('peer:connected', peer);
|
|
2146
|
+
}
|
|
2147
2147
|
});
|
|
2148
2148
|
pubsub.subscribe('peer:disconnected', async (peer) => {
|
|
2149
2149
|
let index = this._discovered.indexOf(peer.id);
|
|
@@ -2176,6 +2176,9 @@ class Peernet {
|
|
|
2176
2176
|
* @type {PeernetClient}
|
|
2177
2177
|
*/
|
|
2178
2178
|
this.client = new PeernetClient({...options, id});
|
|
2179
|
+
if (globalThis.onbeforeunload) {
|
|
2180
|
+
globalThisaddEventListener('beforeunload', async () => this.client.close());
|
|
2181
|
+
}
|
|
2179
2182
|
return this
|
|
2180
2183
|
}
|
|
2181
2184
|
|
package/package.json
CHANGED
package/src/peernet.js
CHANGED
|
@@ -204,19 +204,19 @@ export default class Peernet {
|
|
|
204
204
|
this.peerId = id
|
|
205
205
|
|
|
206
206
|
pubsub.subscribe('peer:discovered', async (peer) => {
|
|
207
|
-
this._peerHandler.discover(peer)
|
|
208
207
|
peer.on('peernet.data', async (message) => {
|
|
209
|
-
const id = message.id
|
|
210
|
-
message = new PeernetMessage(Buffer.from(message.data.data))
|
|
211
|
-
const proto = protoFor(message.decoded.data)
|
|
212
|
-
await this._protoHandler({id, proto}, peer)
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
208
|
+
const id = message.id;
|
|
209
|
+
message = new PeernetMessage(Buffer.from(message.data.data));
|
|
210
|
+
const proto = protoFor(message.decoded.data);
|
|
211
|
+
await this._protoHandler({id, proto}, peer);
|
|
212
|
+
});
|
|
213
|
+
await this._peerHandler.discover(peer);
|
|
214
|
+
const fulldId = this._getPeerId(peer.id);
|
|
215
|
+
if (fulldId && this._discovered.indexOf(peer.id) === -1) {
|
|
216
|
+
this._discovered.push(peer.id);
|
|
217
|
+
pubsub.publish('peer:connected', peer);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
220
|
pubsub.subscribe('peer:disconnected', async (peer) => {
|
|
221
221
|
let index = this._discovered.indexOf(peer.id)
|
|
222
222
|
if (index !== -1) this._discovered.splice(index, 1)
|
|
@@ -248,6 +248,9 @@ export default class Peernet {
|
|
|
248
248
|
* @type {PeernetClient}
|
|
249
249
|
*/
|
|
250
250
|
this.client = new Client({...options, id})
|
|
251
|
+
if (globalThis.onbeforeunload) {
|
|
252
|
+
globalThisaddEventListener('beforeunload', async () => this.client.close());
|
|
253
|
+
}
|
|
251
254
|
return this
|
|
252
255
|
}
|
|
253
256
|
|