Skip to content

Commit

Permalink
feat: Sisyfos running in iFrame. Use frameElement instead of checking…
Browse files Browse the repository at this point in the history
… parent.
  • Loading branch information
olzzons-mac authored and olzzons-mac committed Feb 11, 2020
1 parent a96215a commit bcc3633
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions client/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class App extends React.Component<IAppProps> {
}

sendSofieMessage(type: string, payload?: any | '', replyTo?: string | '') {
if (!window.parent) return;
window.parent.postMessage({
if (!window.frameElement) return;
window.top.postMessage({
id: Date.now().toString(),
replyToId: replyTo,
type: type,
Expand All @@ -44,27 +44,29 @@ class App extends React.Component<IAppProps> {
}

iFrameFocusHandler() {
this.sendSofieMessage('hello')
document.addEventListener('click', (e) => {
e.preventDefault()
this.sendSofieMessage('focus_in')
}, true)
window.addEventListener('message', (event) => {
try {
const message = event.data
if (!message || !message.type) return;
switch (message.type) {
case 'welcome':
console.log('Hosted by: ' + message.payload);
// finish three-way handshake
this.sendSofieMessage('ack', undefined, message.id);
break;
if (window.frameElement) {
this.sendSofieMessage('hello')
document.addEventListener('click', (e) => {
e.preventDefault()
this.sendSofieMessage('focus_in')
}, true)
window.addEventListener('message', (event) => {
try {
const message = event.data
if (!message || !message.type) return;
switch (message.type) {
case 'welcome':
console.log('Hosted by: ' + message.payload);
// finish three-way handshake
this.sendSofieMessage('ack', undefined, message.id);
break;

}
} catch (e) {
console.log('Error Sofie API')
}
} catch (e) {
console.log('Error Sofie API')
}
})
})
}
}

render() {
Expand Down

0 comments on commit bcc3633

Please sign in to comment.