Skip to content

Commit

Permalink
Event related fixes (#159)
Browse files Browse the repository at this point in the history
* Add events() method to CredentialsModule
* Add events for createInvitation & receiveInvitation
  • Loading branch information
karimStekelenburg authored Jan 13, 2021
1 parent 269a6fc commit 026beb9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/lib/modules/CredentialsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import logger from '../logger';
import { CredentialOfferMessage } from '../protocols/credentials/messages/CredentialOfferMessage';
import { JsonEncoder } from '../utils/JsonEncoder';
import { JsonTransformer } from '../utils/JsonTransformer';
import { EventEmitter } from 'events';

export class CredentialsModule {
private connectionService: ConnectionService;
Expand Down Expand Up @@ -73,4 +74,8 @@ export class CredentialsModule {
public async find(id: string) {
return this.credentialService.find(id);
}

public events(): EventEmitter {
return this.credentialService;
}
}
15 changes: 14 additions & 1 deletion src/lib/protocols/connections/ConnectionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ class ConnectionService extends EventEmitter {
});

connectionRecord.invitation = invitation;
this.connectionRepository.update(connectionRecord);

await this.connectionRepository.update(connectionRecord);

this.emit(EventType.StateChanged, {
connection: connectionRecord,
prevState: null,
});

return connectionRecord;
}
Expand Down Expand Up @@ -100,6 +106,13 @@ class ConnectionService extends EventEmitter {
},
});

await this.connectionRepository.update(connectionRecord);

this.emit(EventType.StateChanged, {
connection: connectionRecord,
prevState: null,
});

return connectionRecord;
}

Expand Down

0 comments on commit 026beb9

Please sign in to comment.