forked from eyra/port
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.tsx
37 lines (30 loc) · 1.17 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import './fonts.css'
import './framework/styles.css'
import Assembly from './framework/assembly'
import { Bridge } from './framework/types/modules'
import LiveBridge from './live_bridge'
import FakeBridge from './fake_bridge'
const rootElement = document.getElementById('root') as HTMLElement
const workerFile = new URL('./framework/processing/py_worker.js', import.meta.url)
const worker = new Worker(workerFile)
let assembly: Assembly
const run = (bridge: Bridge, locale: string): void => {
assembly = new Assembly(worker, bridge)
assembly.visualisationEngine.start(rootElement, locale)
assembly.processingEngine.start()
}
if (process.env.REACT_APP_BUILD !== 'standalone' && process.env.NODE_ENV === 'production') {
// Setup embedded mode (requires to be embedded in iFrame)
console.log('Initializing bridge system')
LiveBridge.create(window, run)
} else {
// Setup local development mode
console.log('Running with fake bridge')
run(new FakeBridge(), 'en')
}
const observer = new ResizeObserver(() => {
const height = window.document.body.scrollHeight;
const action = "resize"
window.parent.postMessage({action, height}, "*")
});
observer.observe(window.document.body);