From a9bc1e3a73833bfa188258dba7116e24f2aba214 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 6 Apr 2023 09:57:04 -0400 Subject: [PATCH] *emit setup event to allow setup of a socket before triggering the connection event *add a link to the parent swarm in the socket to call emit --- src/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 2063500..1945c63 100644 --- a/src/index.ts +++ b/src/index.ts @@ -165,9 +165,12 @@ export class Socket extends Client { private syncMutex = new Mutex(); - constructor(id: number) { + private swarm: SwarmClient; + + constructor(id: number, swarm: SwarmClient) { super(); this.id = id; + this.swarm = swarm; } private _remotePublicKey?: Uint8Array; @@ -194,6 +197,8 @@ export class Socket extends Client { private async _initSync() { const mux = Protomux.from(this); + this.swarm.emit("setup", this); + let updateDone = defer(); const [update] = this.connectModule(