fix: signal disconnect loop on server start

this fixes the disconnect loop when the server has just started by
waiting for the connection to open before subsribing to events.

also includes other improvements:
- rename types to interfaces
- allow to input single receiver for signal
- use discovery api to check for upgrade path instead hard coded one

Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
Heikki Hellgren
2024-01-26 09:31:06 +02:00
parent 9a8d556661
commit 447d21045b
17 changed files with 89 additions and 46 deletions
+10 -5
View File
@@ -7,18 +7,23 @@ import { ApiRef } from '@backstage/core-plugin-api';
import { JsonObject } from '@backstage/types';
// @public (undocumented)
export type SignalApi = {
export interface SignalApi {
// (undocumented)
subscribe(
channel: string,
onMessage: (message: JsonObject) => void,
): {
unsubscribe: () => void;
};
};
): SignalSubscriber;
}
// @public (undocumented)
export const signalApiRef: ApiRef<SignalApi>;
// @public (undocumented)
export interface SignalSubscriber {
// (undocumented)
unsubscribe(): void;
}
// @public (undocumented)
export const useSignal: (channel: string) => {
lastSignal: JsonObject | null;
+8 -3
View File
@@ -22,9 +22,14 @@ export const signalApiRef = createApiRef<SignalApi>({
});
/** @public */
export type SignalApi = {
export interface SignalSubscriber {
unsubscribe(): void;
}
/** @public */
export interface SignalApi {
subscribe(
channel: string,
onMessage: (message: JsonObject) => void,
): { unsubscribe: () => void };
};
): SignalSubscriber;
}