Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/jaeger-ui/src/api/digma/ActionDispatcher.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ActionListener } from "./types";
import { ActionListener } from './types';

export class ActionDispatcher {
private actions: {
[key: string]: ActionListener[];
};

constructor() {
this.actions = {};
}
Expand All @@ -19,7 +19,7 @@ export class ActionDispatcher {

public removeActionListener(type: string, listener: ActionListener) {
if (this.actions[type]) {
this.actions[type] = this.actions[type].filter((x) => x !== listener);
this.actions[type] = this.actions[type].filter(x => x !== listener);
}

if (this.actions[type].length === 0) {
Expand All @@ -32,4 +32,4 @@ export class ActionDispatcher {
this.actions[type].forEach(fn => fn(data));
}
}
}
}
4 changes: 2 additions & 2 deletions packages/jaeger-ui/src/api/digma/dispatcher.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { ActionDispatcher } from "./ActionDispatcher";
import { ActionDispatcher } from './ActionDispatcher';

export const dispatcher = new ActionDispatcher();
export const dispatcher = new ActionDispatcher();
46 changes: 19 additions & 27 deletions packages/jaeger-ui/src/api/digma/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { isObject } from "../../utils/ts/typeGuards/isObject";
import { ActionDispatcher } from "./ActionDispatcher";
import { updateState } from "./state";
import { DigmaMessageEvent, IDigmaOutgoingMessageData } from "./types";
import { isObject } from '../../utils/ts/typeGuards/isObject';
import { ActionDispatcher } from './ActionDispatcher';
import { updateState } from './state';
import { DigmaMessageEvent, IDigmaOutgoingMessageData } from './types';

const isDigmaMessageEvent = (e: MessageEvent): e is DigmaMessageEvent =>
isObject(e.data) && e.data.type === "digma";
isObject(e.data) && e.data.type === 'digma';

export const initializeDigmaMessageListener = (
dispatcher: ActionDispatcher
) => {
window.addEventListener("message", e => {
export const initializeDigmaMessageListener = (dispatcher: ActionDispatcher) => {
window.addEventListener('message', e => {
if (isDigmaMessageEvent(e)) {
console.info("Digma message received: ", e);
console.debug('Digma message received: ', e);

updateState(e.data.action, e.data.payload);

Expand All @@ -20,32 +18,26 @@ export const initializeDigmaMessageListener = (
});
};

export const sendMessage = (
message: IDigmaOutgoingMessageData
): string | undefined => {
console.info("Message to send:", message);
export const sendMessage = (message: IDigmaOutgoingMessageData): string | undefined => {
console.debug('Message to send:', message);

updateState(message.action, message.payload);

if (window.sendMessageToVSCode) {
window.sendMessageToVSCode(message);
console.info("Message has been sent to VS Code: ", message);
}

if (window.cefQuery) {
console.debug('Message has been sent to VS Code: ', message);
} else if (window.cefQuery) {
return window.cefQuery({
request: JSON.stringify(message),
onSuccess (response) {
console.info("cefQuery has been successfully sent: %s", response);
onSuccess(response) {
console.debug('cefQuery has been successfully sent: %s', response);
},
onFailure(errorCode, errorMessage) {
console.error('Failed to send cefQuery: %d, %s', errorCode, errorMessage);
},
onFailure (errorCode, errorMessage) {
console.error(
"Failed to send cefQuery: %d, %s",
errorCode,
errorMessage
);
}
});
} else if (window.parent !== window) {
window.parent.postMessage(message, '*');
}

return undefined;
Expand Down