From 4999152684635f4ae1c52f023f453584b9c7a2f0 Mon Sep 17 00:00:00 2001 From: Kyrylo Shmidt Date: Thu, 15 Jun 2023 03:55:52 +0200 Subject: [PATCH] Allow to send message to the parent window --- .../src/api/digma/ActionDispatcher.ts | 8 ++-- .../jaeger-ui/src/api/digma/dispatcher.ts | 4 +- packages/jaeger-ui/src/api/digma/index.ts | 46 ++++++++----------- 3 files changed, 25 insertions(+), 33 deletions(-) diff --git a/packages/jaeger-ui/src/api/digma/ActionDispatcher.ts b/packages/jaeger-ui/src/api/digma/ActionDispatcher.ts index b791699aef..5fa4513eed 100644 --- a/packages/jaeger-ui/src/api/digma/ActionDispatcher.ts +++ b/packages/jaeger-ui/src/api/digma/ActionDispatcher.ts @@ -1,10 +1,10 @@ -import { ActionListener } from "./types"; +import { ActionListener } from './types'; export class ActionDispatcher { private actions: { [key: string]: ActionListener[]; }; - + constructor() { this.actions = {}; } @@ -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) { @@ -32,4 +32,4 @@ export class ActionDispatcher { this.actions[type].forEach(fn => fn(data)); } } -} \ No newline at end of file +} diff --git a/packages/jaeger-ui/src/api/digma/dispatcher.ts b/packages/jaeger-ui/src/api/digma/dispatcher.ts index 2941e86bcc..6b3824a156 100644 --- a/packages/jaeger-ui/src/api/digma/dispatcher.ts +++ b/packages/jaeger-ui/src/api/digma/dispatcher.ts @@ -1,3 +1,3 @@ -import { ActionDispatcher } from "./ActionDispatcher"; +import { ActionDispatcher } from './ActionDispatcher'; -export const dispatcher = new ActionDispatcher(); \ No newline at end of file +export const dispatcher = new ActionDispatcher(); diff --git a/packages/jaeger-ui/src/api/digma/index.ts b/packages/jaeger-ui/src/api/digma/index.ts index e392c711e4..40d8bf80d2 100644 --- a/packages/jaeger-ui/src/api/digma/index.ts +++ b/packages/jaeger-ui/src/api/digma/index.ts @@ -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); @@ -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;