chore: restore signals changes to master
Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
@@ -22,9 +22,9 @@ export type SignalPayload = {
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
export interface SignalService {
|
||||
export type SignalService = {
|
||||
publish(signal: SignalPayload): Promise<void>;
|
||||
}
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
export const signalService: ServiceRef<SignalService, 'plugin'>;
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
import { SignalPayload } from './types';
|
||||
|
||||
/** @public */
|
||||
export interface SignalService {
|
||||
export type SignalService = {
|
||||
/**
|
||||
* Publishes a message to user refs to specific topic
|
||||
*/
|
||||
publish(signal: SignalPayload): Promise<void>;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -7,23 +7,18 @@ import { ApiRef } from '@backstage/core-plugin-api';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
|
||||
// @public (undocumented)
|
||||
export interface SignalApi {
|
||||
// (undocumented)
|
||||
export type SignalApi = {
|
||||
subscribe(
|
||||
channel: string,
|
||||
onMessage: (message: JsonObject) => void,
|
||||
): SignalSubscriber;
|
||||
}
|
||||
): {
|
||||
unsubscribe: () => void;
|
||||
};
|
||||
};
|
||||
|
||||
// @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;
|
||||
|
||||
@@ -22,14 +22,9 @@ export const signalApiRef = createApiRef<SignalApi>({
|
||||
});
|
||||
|
||||
/** @public */
|
||||
export interface SignalSubscriber {
|
||||
unsubscribe(): void;
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export interface SignalApi {
|
||||
export type SignalApi = {
|
||||
subscribe(
|
||||
channel: string,
|
||||
onMessage: (message: JsonObject) => void,
|
||||
): SignalSubscriber;
|
||||
}
|
||||
): { unsubscribe: () => void };
|
||||
};
|
||||
|
||||
@@ -146,6 +146,20 @@ export class SignalClient implements SignalApi {
|
||||
url.protocol = url.protocol === 'http:' ? 'ws:' : 'wss:';
|
||||
this.ws = new WebSocket(url.toString(), token);
|
||||
|
||||
this.ws.onmessage = (data: MessageEvent) => {
|
||||
this.handleMessage(data);
|
||||
};
|
||||
|
||||
this.ws.onerror = () => {
|
||||
this.reconnect();
|
||||
};
|
||||
|
||||
this.ws.onclose = (ev: CloseEvent) => {
|
||||
if (ev.code !== WS_CLOSE_NORMAL && ev.code !== WS_CLOSE_GOING_AWAY) {
|
||||
this.reconnect();
|
||||
}
|
||||
};
|
||||
|
||||
// Wait until connection is open
|
||||
let connectSleep = 0;
|
||||
while (
|
||||
@@ -160,20 +174,6 @@ export class SignalClient implements SignalApi {
|
||||
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
||||
throw new Error('Connect timeout');
|
||||
}
|
||||
|
||||
this.ws.onmessage = (data: MessageEvent) => {
|
||||
this.handleMessage(data);
|
||||
};
|
||||
|
||||
this.ws.onerror = () => {
|
||||
this.reconnect();
|
||||
};
|
||||
|
||||
this.ws.onclose = (ev: CloseEvent) => {
|
||||
if (ev.code !== WS_CLOSE_NORMAL && ev.code !== WS_CLOSE_GOING_AWAY) {
|
||||
this.reconnect();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private handleMessage(data: MessageEvent) {
|
||||
|
||||
Reference in New Issue
Block a user