*Track socks to reuse objects as we are storing state on them
This commit is contained in:
parent
ab78add294
commit
c869488951
10
src/index.ts
10
src/index.ts
|
@ -17,6 +17,7 @@ export class SwarmClient extends Client {
|
||||||
private _ready?: Promise<void>;
|
private _ready?: Promise<void>;
|
||||||
|
|
||||||
private _topics: Set<Uint8Array> = new Set<Uint8Array>();
|
private _topics: Set<Uint8Array> = new Set<Uint8Array>();
|
||||||
|
private _sockets: Map<number, Socket> = new Map<number, Socket>();
|
||||||
|
|
||||||
get dht() {
|
get dht() {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
@ -90,7 +91,14 @@ export class SwarmClient extends Client {
|
||||||
"listenConnections",
|
"listenConnections",
|
||||||
{ swarm: this.swarm },
|
{ swarm: this.swarm },
|
||||||
async (socketId: any) => {
|
async (socketId: any) => {
|
||||||
this.emit("connection", await createSocket(socketId));
|
const socket =
|
||||||
|
this._sockets.get(socketId) ?? (await createSocket(socketId));
|
||||||
|
|
||||||
|
socket.on("close", () => {
|
||||||
|
this._sockets.delete(socketId);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.emit("connection", socket);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue