Pass messages to and from Unreal
Setting up a MessageChannel
MessageChannelconst iframe = document.querySelector('iframe') as HTMLIFrameElement
iframe.addEventListener('load', onLoad)
const channel = new MessageChannel() as MessageChannel
function onLoad() {
if (!iframe || !iframe.contentWindow) {
console.error('Iframe not found.')
return
}
// listen for messages on port2
channel.port2.onmessage = onMessage
// send setup channel message to odyssey
iframe.contentWindow.postMessage({ type: 'setupChannel' }, 'https://app.odyssey.stream/', [channel.port1])
}
function onMessage(event: Event) {
// add custom logic to react to messages from Odyssey
console.log('Message received from iframe: ', event.data)
}Last updated