Skip to content

Commit

Permalink
Disconnect websocket from FireFly when WS from EVMConnect is disconne…
Browse files Browse the repository at this point in the history
…cted

- This is to allow FireFly to resend which event streams we care about

Signed-off-by: Enrique Lacal <[email protected]>
  • Loading branch information
EnriqueL8 committed Apr 23, 2024
1 parent 2ec0fa0 commit 2762a2f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/event-stream/event-stream.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class EventStreamSocket {
private password: string,
private handleEvents: (events: EventBatch) => void,
private handleReceipt: (receipt: EventStreamReply) => void,
private handleClose: () => void,
) {
this.init();
}
Expand All @@ -77,6 +78,7 @@ export class EventStreamSocket {
this.logger.log('Event stream websocket closed');
} else {
this.disconnectDetected = true;
this.handleClose()
this.logger.error(
`Event stream websocket disconnected, attempting to reconnect in ${RECONNECT_TIME}ms`,
);
Expand Down Expand Up @@ -357,6 +359,7 @@ export class EventStreamService {
namespace: string,
handleEvents: (events: EventBatch) => void,
handleReceipt: (receipt: EventStreamReply) => void,
handleClose: () => void,
) {
const name = eventStreamName(topic, namespace);
await this.createOrUpdateStream(newContext(), name, topic);
Expand All @@ -369,6 +372,7 @@ export class EventStreamService {
this.password,
handleEvents,
handleReceipt,
handleClose
);
}
}
6 changes: 6 additions & 0 deletions src/eventstream-proxy/eventstream-proxy.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ export abstract class EventStreamProxyBase extends WebSocketEventsBase {
receipt => {
this.broadcast('receipt', <EventStreamReply>receipt);
},
() => {
// When the connection is closed to EVMConnect
// Close the connection to FireFly as well
// FireFly will resend on connection the start event for the eventstreams we need to listen to
client.close()
}
);
this.namespaceEventStreamSocket.set(namespace, eventStreamSocket);
}
Expand Down

0 comments on commit 2762a2f

Please sign in to comment.