-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use single event emitter for all events (#274)
- Loading branch information
1 parent
8d2cc2f
commit ea814b2
Showing
27 changed files
with
335 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Lifecycle, scoped } from 'tsyringe' | ||
import { EventEmitter as NativeEventEmitter } from 'events' | ||
import { BaseEvent } from './Events' | ||
|
||
@scoped(Lifecycle.ContainerScoped) | ||
export class EventEmitter { | ||
private eventEmitter = new NativeEventEmitter() | ||
|
||
public emit<T extends BaseEvent>(data: T) { | ||
this.eventEmitter.emit(data.type, data) | ||
} | ||
|
||
public on<T extends BaseEvent>(event: T['type'], listener: (data: T) => void | Promise<void>) { | ||
this.eventEmitter.on(event, listener) | ||
} | ||
|
||
public off<T extends BaseEvent>(event: T['type'], listener: (data: T) => void | Promise<void>) { | ||
this.eventEmitter.off(event, listener) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export enum AgentEventTypes { | ||
AgentMessageReceived = 'AgentMessageReceived', | ||
} | ||
|
||
export interface BaseEvent { | ||
type: string | ||
payload: Record<string, unknown> | ||
} | ||
|
||
export interface AgentMessageReceivedEvent extends BaseEvent { | ||
type: typeof AgentEventTypes.AgentMessageReceived | ||
payload: { | ||
message: unknown | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { Verkey } from 'indy-sdk' | ||
import { BaseEvent } from '../../agent/Events' | ||
import { BasicMessage } from './messages' | ||
|
||
export enum BasicMessageEventTypes { | ||
BasicMessageReceived = 'BasicMessageReceived', | ||
} | ||
|
||
export interface BasicMessageReceivedEvent extends BaseEvent { | ||
type: typeof BasicMessageEventTypes.BasicMessageReceived | ||
payload: { | ||
message: BasicMessage | ||
verkey: Verkey | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './messages' | ||
export * from './services' | ||
export * from './repository' | ||
export * from './BasicMessageEvents' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { BaseEvent } from '../../agent/Events' | ||
import { ConnectionRecord } from './repository/ConnectionRecord' | ||
import { ConnectionState } from './models/ConnectionState' | ||
|
||
export enum ConnectionEventTypes { | ||
ConnectionStateChanged = 'ConnectionStateChanged', | ||
} | ||
|
||
export interface ConnectionStateChangedEvent extends BaseEvent { | ||
type: typeof ConnectionEventTypes.ConnectionStateChanged | ||
payload: { | ||
connectionRecord: ConnectionRecord | ||
previousState: ConnectionState | null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.