fix(sdk,client): add listener to current frame window
arcad/edge/pipeline/head This commit looks good Details

This commit is contained in:
wpetit 2023-04-13 12:07:52 +02:00
parent de330c0042
commit dc93c585eb
3 changed files with 17 additions and 14 deletions

View File

@ -3960,25 +3960,26 @@ var Edge = (() => {
reject(new Error("Edge auth token request timed out !")); reject(new Error("Edge auth token request timed out !"));
}, timeout); }, timeout);
const listener = (evt) => { const listener = (evt) => {
const message = evt.data; const message2 = evt.data;
if (!message || !message.type || !message.data) { if (!message2 || !message2.type || !message2.data) {
return; return;
} }
if (message.type !== EdgeAuthTokenResponse) { if (message2.type !== EdgeAuthTokenResponse) {
return; return;
} }
window.parent.removeEventListener("message", listener); window.removeEventListener("message", listener);
clearTimeout(timeoutId); clearTimeout(timeoutId);
if (timedOut) if (timedOut)
return; return;
if (!message.data || !message.data.token) { if (!message2.data || !message2.data.token) {
reject("Unexpected auth token request response !"); reject("Unexpected auth token request response !");
return; return;
} }
resolve(message.data.token); resolve(message2.data.token);
}; };
window.parent.addEventListener("message", listener); window.addEventListener("message", listener);
window.parent.postMessage({ type: EdgeAuthTokenRequest }, "*"); const message = { type: EdgeAuthTokenRequest };
window.parent.postMessage(message, "*");
}); });
} }
_handleEdgeAuthTokenRequest(evt) { _handleEdgeAuthTokenRequest(evt) {

File diff suppressed because one or more lines are too long

View File

@ -143,7 +143,7 @@ export class Client extends EventTarget {
return; return;
} }
window.parent.removeEventListener('message', listener); window.removeEventListener('message', listener);
clearTimeout(timeoutId); clearTimeout(timeoutId);
if (timedOut) return; if (timedOut) return;
@ -156,8 +156,10 @@ export class Client extends EventTarget {
resolve(message.data.token); resolve(message.data.token);
} }
window.parent.addEventListener('message', listener); window.addEventListener('message', listener);
window.parent.postMessage({ type: EdgeAuthTokenRequest }, '*');
const message = { type: EdgeAuthTokenRequest };
window.parent.postMessage(message, '*');
}) })
} }