Skip to content

Commit

Permalink
fix(repeater): deploy repeater on every connection
Browse files Browse the repository at this point in the history
  • Loading branch information
lsndr committed Aug 31, 2023
1 parent 8ac97af commit 526ed51
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/Repeater/DefaultRepeaterServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ export class DefaultRepeaterServer implements RepeaterServer {
logger.debug('Event bus connected to %s', this.options.uri);
}

public connected(handler: () => void | Promise<void>): void {
this.socket.on('connect', () =>
this.processEventHandler('connect', undefined, handler)
);
}

public requestReceived(
handler: (
event: RepeaterServerRequestEvent
Expand Down
2 changes: 2 additions & 0 deletions src/Repeater/RepeaterServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ export interface RepeaterServer {

reconnectionSucceeded(handler: () => void | Promise<void>): void;

connected(handler: () => void | Promise<void>): void;

errorOccurred(
handler: (event: RepeaterServerErrorEvent) => void | Promise<void>
): void;
Expand Down
19 changes: 10 additions & 9 deletions src/Repeater/ServerRepeaterLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { delay, inject, injectable } from 'tsyringe';
export class ServerRepeaterLauncher implements RepeaterLauncher {
private static SERVICE_NAME = 'bright-repeater';
private repeaterStarted: boolean = false;
private repeaterId: string | undefined;

constructor(
@inject(RuntimeDetector) private readonly runtimeDetector: RuntimeDetector,
Expand Down Expand Up @@ -91,17 +92,9 @@ export class ServerRepeaterLauncher implements RepeaterLauncher {

logger.log('Starting the Repeater (%s)...', this.info.version);

this.repeaterId = repeaterId;
this.repeaterServer.connect(repeaterId);

this.subscribeToEvents();

await this.repeaterServer.deploy(
{
repeaterId
},
this.getRuntime()
);

this.repeaterStarted = true;

logger.log(`The Repeater (%s) started`, this.info.version);
Expand All @@ -121,6 +114,14 @@ export class ServerRepeaterLauncher implements RepeaterLauncher {
}

private subscribeToEvents() {
this.repeaterServer.connected(async () => {
await this.repeaterServer.deploy(
{
repeaterId: this.repeaterId
},
this.getRuntime()
);
});
this.repeaterServer.errorOccurred(({ message }) => {
logger.error(message);
});
Expand Down

0 comments on commit 526ed51

Please sign in to comment.