From 8d57c62994ae2617701a00c035c80f3a247ef923 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 15 Nov 2022 14:24:41 -0500 Subject: [PATCH] *Add peer-open and peer-remove events --- dist/index.d.ts.map | 2 +- src/index.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/dist/index.d.ts.map b/dist/index.d.ts.map index db417bb..57cc548 100644 --- a/dist/index.d.ts.map +++ b/dist/index.d.ts.map @@ -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"} \ No newline at end of file +{"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"} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 714e1c3..580e558 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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; }