Skip to content

Commit

Permalink
feat: implement Sofie iFrame support
Browse files Browse the repository at this point in the history
  • Loading branch information
olzzons-mac authored and olzzons-mac committed Feb 11, 2020
1 parent c27e757 commit a96215a
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion client/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class App extends React.Component<IAppProps> {
console.log('http args : ', window.location.search.includes('settings=0'))
window.socketIoClient.emit('get-mixerprotocol', 'get selected mixerprotocol')
window.socketIoClient.emit('get-store', 'update local store');
window.socketIoClient.emit('get-settings', 'update local settings');
window.socketIoClient.emit('get-settings', 'update local settings');
this.iFrameFocusHandler()
}

public shouldComponentUpdate(nextProps: IAppProps) {
Expand All @@ -32,6 +33,40 @@ class App extends React.Component<IAppProps> {
)
}

sendSofieMessage(type: string, payload?: any | '', replyTo?: string | '') {
if (!window.parent) return;
window.parent.postMessage({
id: Date.now().toString(),
replyToId: replyTo,
type: type,
payload: payload
}, "*");
}

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;

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

render() {
return (
<div>
Expand Down

0 comments on commit a96215a

Please sign in to comment.