*Add peer-open and peer-remove events

This commit is contained in:
Derrick Hammer 2022-11-15 14:24:41 -05:00
parent 9c7dc7dad8
commit 8d57c62994
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 9 additions and 1 deletions

2
dist/index.d.ts.map vendored
View File

@ -1 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAoBlC,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,YAAY;IAC9C,OAAO,CAAC,EAAE,CAAS;IACnB,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,GAAG,CAAM;IACjB,OAAO,CAAC,KAAK,CAAM;gBAEP,EACI,OAAkB,EAClB,GAAS,EACT,aAAiB,EACjB,EAA2B,EAC3B,KAAY,EACf;;;;;;KAAK;IAkBlB,OAAO,CAAC,aAAa;IAwBrB,OAAO,CAAC,SAAS;IAmCjB,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,SAAW;CActC"}
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAoBlC,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,YAAY;IAC9C,OAAO,CAAC,EAAE,CAAS;IACnB,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,GAAG,CAAM;IACjB,OAAO,CAAC,KAAK,CAAM;gBAEP,EACI,OAAkB,EAClB,GAAS,EACT,aAAiB,EACjB,EAA2B,EAC3B,KAAY,EACf;;;;;;KAAK;IAkBlB,OAAO,CAAC,aAAa;IAwBrB,OAAO,CAAC,SAAS;IA2CjB,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,SAAW;CActC"}

View File

@ -77,9 +77,17 @@ export default class DHTFlood extends EventEmitter {
const mux = Protomux.from(peer);
let chan: any;
const self = this;
if (!mux.opened({protocol: PROTOCOL})) {
chan = mux.createChannel({
protocol: PROTOCOL,
async onopen() {
self.emit('peer-open', peer)
},
async ondestroy() {
self.emit('peer-remove', peer)
},
});
peer[FLOOD_SYMBOL] = chan;
}