Skip to content

Commit fcf0d37

Browse files
Merge pull request #23 from digma-ai/fix/iframe
Allow to send messages to the parent window
2 parents 4ddee76 + 4999152 commit fcf0d37

File tree

3 files changed

+25
-33
lines changed

3 files changed

+25
-33
lines changed

packages/jaeger-ui/src/api/digma/ActionDispatcher.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { ActionListener } from "./types";
1+
import { ActionListener } from './types';
22

33
export class ActionDispatcher {
44
private actions: {
55
[key: string]: ActionListener[];
66
};
7-
7+
88
constructor() {
99
this.actions = {};
1010
}
@@ -19,7 +19,7 @@ export class ActionDispatcher {
1919

2020
public removeActionListener(type: string, listener: ActionListener) {
2121
if (this.actions[type]) {
22-
this.actions[type] = this.actions[type].filter((x) => x !== listener);
22+
this.actions[type] = this.actions[type].filter(x => x !== listener);
2323
}
2424

2525
if (this.actions[type].length === 0) {
@@ -32,4 +32,4 @@ export class ActionDispatcher {
3232
this.actions[type].forEach(fn => fn(data));
3333
}
3434
}
35-
}
35+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { ActionDispatcher } from "./ActionDispatcher";
1+
import { ActionDispatcher } from './ActionDispatcher';
22

3-
export const dispatcher = new ActionDispatcher();
3+
export const dispatcher = new ActionDispatcher();

packages/jaeger-ui/src/api/digma/index.ts

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
import { isObject } from "../../utils/ts/typeGuards/isObject";
2-
import { ActionDispatcher } from "./ActionDispatcher";
3-
import { updateState } from "./state";
4-
import { DigmaMessageEvent, IDigmaOutgoingMessageData } from "./types";
1+
import { isObject } from '../../utils/ts/typeGuards/isObject';
2+
import { ActionDispatcher } from './ActionDispatcher';
3+
import { updateState } from './state';
4+
import { DigmaMessageEvent, IDigmaOutgoingMessageData } from './types';
55

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

9-
export const initializeDigmaMessageListener = (
10-
dispatcher: ActionDispatcher
11-
) => {
12-
window.addEventListener("message", e => {
9+
export const initializeDigmaMessageListener = (dispatcher: ActionDispatcher) => {
10+
window.addEventListener('message', e => {
1311
if (isDigmaMessageEvent(e)) {
14-
console.info("Digma message received: ", e);
12+
console.debug('Digma message received: ', e);
1513

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

@@ -20,32 +18,26 @@ export const initializeDigmaMessageListener = (
2018
});
2119
};
2220

23-
export const sendMessage = (
24-
message: IDigmaOutgoingMessageData
25-
): string | undefined => {
26-
console.info("Message to send:", message);
21+
export const sendMessage = (message: IDigmaOutgoingMessageData): string | undefined => {
22+
console.debug('Message to send:', message);
2723

2824
updateState(message.action, message.payload);
2925

3026
if (window.sendMessageToVSCode) {
3127
window.sendMessageToVSCode(message);
32-
console.info("Message has been sent to VS Code: ", message);
33-
}
34-
35-
if (window.cefQuery) {
28+
console.debug('Message has been sent to VS Code: ', message);
29+
} else if (window.cefQuery) {
3630
return window.cefQuery({
3731
request: JSON.stringify(message),
38-
onSuccess (response) {
39-
console.info("cefQuery has been successfully sent: %s", response);
32+
onSuccess(response) {
33+
console.debug('cefQuery has been successfully sent: %s', response);
34+
},
35+
onFailure(errorCode, errorMessage) {
36+
console.error('Failed to send cefQuery: %d, %s', errorCode, errorMessage);
4037
},
41-
onFailure (errorCode, errorMessage) {
42-
console.error(
43-
"Failed to send cefQuery: %d, %s",
44-
errorCode,
45-
errorMessage
46-
);
47-
}
4838
});
39+
} else if (window.parent !== window) {
40+
window.parent.postMessage(message, '*');
4941
}
5042

5143
return undefined;

0 commit comments

Comments
 (0)