Skip to content

Commit

Permalink
revert transport layer event emitters to native events
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 committed Dec 20, 2024
1 parent d8ab19c commit 3099c6d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/portalnetwork/src/transports/capacitorUdp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventEmitter } from 'eventemitter3'
import { EventEmitter } from 'events'
import { getSocketAddressOnENR } from '@chainsafe/discv5'
import { decodePacket, encodePacket } from '@chainsafe/discv5/packet'
import { UDP } from '@frontall/capacitor-udp'
Expand All @@ -9,8 +9,8 @@ import type { IPacket } from '@chainsafe/discv5/packet'
import type {
IPMode,
IRemoteInfo,
ITransportEvents,
ITransportService,
TransportEventEmitter,
} from '@chainsafe/discv5/transport'
import type { ENR } from '@chainsafe/enr'
import type { Multiaddr } from '@multiformats/multiaddr'
Expand All @@ -19,7 +19,7 @@ import type { Multiaddr } from '@multiformats/multiaddr'
* This class is responsible for encoding outgoing Packets and decoding incoming Packets over UDP
*/
export class CapacitorUDPTransportService
extends EventEmitter<ITransportEvents>
extends (EventEmitter as { new (): TransportEventEmitter })
implements ITransportService
{
private socket!: {
Expand Down
9 changes: 7 additions & 2 deletions packages/portalnetwork/src/transports/websockets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventEmitter } from 'eventemitter3'
import { EventEmitter } from 'events'
import { getSocketAddressOnENR } from '@chainsafe/discv5'
import { decodePacket, encodePacket } from '@chainsafe/discv5/packet'
import { multiaddr as ma } from '@multiformats/multiaddr'
Expand All @@ -17,18 +17,23 @@ import type { IPacket } from '@chainsafe/discv5/packet'
import type { ENR } from '@chainsafe/enr'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { Debugger } from 'debug'
import type StrictEventEmitter from 'strict-event-emitter-types/types/src'

const log = debug('discv5:transport')

interface WebSocketTransportEvents extends ITransportEvents {
multiAddr: (src: Multiaddr) => void
}

export declare type WSTransportEventEmitter = StrictEventEmitter<
EventEmitter,
WebSocketTransportEvents
>
/**
* This class is responsible for encoding outgoing Packets and decoding incoming Packets over Websockets
*/
export class WebSocketTransportService
extends EventEmitter<WebSocketTransportEvents>
extends (EventEmitter as { new (): WSTransportEventEmitter })
implements ITransportService
{
public multiaddr: Multiaddr
Expand Down

0 comments on commit 3099c6d

Please sign in to comment.