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
+3 -3
View File
@@ -16,15 +16,15 @@ export class DefaultSignalService implements SignalService {
// @public (undocumented)
export type SignalPayload = {
recipients: string[] | null;
receivers: string[] | string | null;
channel: string;
message: JsonObject;
};
// @public (undocumented)
export type SignalService = {
export interface SignalService {
publish(signal: SignalPayload): Promise<void>;
};
}
// @public (undocumented)
export const signalService: ServiceRef<SignalService, 'plugin'>;
@@ -37,11 +37,11 @@ export class DefaultSignalService implements SignalService {
* @param message - message to publish
*/
async publish(signal: SignalPayload) {
const { recipients, channel, message } = signal;
const { receivers, channel, message } = signal;
await this.eventBroker?.publish({
topic: 'signals',
eventPayload: {
recipients,
receivers,
message,
channel,
},
+2 -2
View File
@@ -16,9 +16,9 @@
import { SignalPayload } from './types';
/** @public */
export type SignalService = {
export interface SignalService {
/**
* Publishes a message to user refs to specific topic
*/
publish(signal: SignalPayload): Promise<void>;
};
}
+1 -1
View File
@@ -25,7 +25,7 @@ export type SignalServiceOptions = {
/** @public */
export type SignalPayload = {
recipients: string[] | null;
receivers: string[] | string | null;
channel: string;
message: JsonObject;
};