Skip to content
Snippets Groups Projects
Unverified Commit a371fc33 authored by xgui3783's avatar xgui3783 Committed by GitHub
Browse files

Merge pull request #821 from HumanBrainProject/expmt_messaging

expmt: add on load and beforeunload post message
parents 9fc6f60a 2e79f0c3
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ import { LOAD_MESH_TOKEN, ILoadMesh } from "src/atlasViewer/atlasViewer.apiServi
import { ComponentsModule } from "src/components";
import { ConfirmDialogComponent } from "src/components/confirmDialog/confirmDialog.component";
import { AngularMaterialModule } from "src/ui/sharedModules/angularMaterial.module";
import { getRandomHex } from 'common/util'
const IAV_POSTMESSAGE_NAMESPACE = `ebrains:iav:`
......@@ -21,6 +22,7 @@ export class MesssagingModule{
private whiteListedOrigins = new Set()
private pendingRequests: Map<string, Promise<boolean>> = new Map()
private windowName: string
constructor(
private dialog: MatDialog,
......@@ -30,6 +32,27 @@ export class MesssagingModule{
@Optional() @Inject(LOAD_MESH_TOKEN) private loadMesh: (loadMeshParam: ILoadMesh) => void
){
if (window.opener){
this.windowName = window.name
window.opener.postMessage({
id: getRandomHex(),
method: `${IAV_POSTMESSAGE_NAMESPACE}onload`,
param: {
'window.name': this.windowName
}
}, '*')
window.addEventListener('beforeunload', () => {
window.opener.postMessage({
id: getRandomHex(),
method: `${IAV_POSTMESSAGE_NAMESPACE}beforeunload`,
param: {
'window.name': this.windowName
}
}, '*')
})
}
window.addEventListener('message', async ({ data, origin, source }) => {
const { method, id, param } = data
const src = source as Window
......@@ -41,7 +64,7 @@ export class MesssagingModule{
* if ping method, respond pong method
*/
if (strippedMethod === 'ping') {
window.opener.postMessage({
src.postMessage({
id,
result: 'pong',
jsonrpc: '2.0'
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment