feat: add eventemitter support on p2p service and have the handshakedone message emit peerConnected

This commit is contained in:
Derrick Hammer 2023-09-01 19:49:42 -04:00
parent 3cc4c27cf2
commit b34b7a3a01
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 4 additions and 1 deletions

View File

@ -60,4 +60,5 @@ export default async function (
p2p.sendPublicPeersToPeer(p, [peer]); p2p.sendPublicPeersToPeer(p, [peer]);
} }
} }
p2p.emit("peerConnected", peer);
} }

View File

@ -26,8 +26,9 @@ import {
createTransportSocket, createTransportSocket,
} from "#transports/index.js"; } from "#transports/index.js";
import messages from "#messages/index.js"; import messages from "#messages/index.js";
import { EventEmitter } from "events";
export class P2PService { export class P2PService extends EventEmitter {
private logger: Logger; private logger: Logger;
private nodeKeyPair: KeyPairEd25519; private nodeKeyPair: KeyPairEd25519;
private localNodeId?: NodeId; private localNodeId?: NodeId;
@ -39,6 +40,7 @@ export class P2PService {
>; >;
constructor(node: S5Node) { constructor(node: S5Node) {
super();
this._node = node; this._node = node;
this._networkId = node.config.p2p?.network; this._networkId = node.config.p2p?.network;
this.nodeKeyPair = node.config.keyPair; this.nodeKeyPair = node.config.keyPair;