import { createMessageListener , FilteringEventListener , sendMessage , WindowLike } from '../protocol/comms' ; import { PostMessageType , verifyAckMessage } from '../protocol/post_messages' ; let listener ; export function respondToHandshake ( window ) { if ( listener ) { window . removeEventListener ( 'message' , listener ) ; } listener = createMessageListener ( PostMessageType . verifyPing , ( data , type , ev ) => { sendMessage ( ev . source , verifyAckMessage ( data ) , ev . origin ) ; } ) ; window . addEventListener ( 'message' , listener ) ; }