-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from eyra/locale
Added locale as parameter, renamed Storage to Bridge, and add CommandSystemExit
- Loading branch information
Showing
14 changed files
with
121 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { CommandSystem, CommandSystemDonate, CommandSystemExit, isCommandSystemDonate, isCommandSystemExit } from './framework/types/commands' | ||
import { Bridge } from './framework/types/modules' | ||
|
||
export default class FakeBridge implements Bridge { | ||
send (command: CommandSystem): void { | ||
if (isCommandSystemDonate(command)) { | ||
this.handleDonation(command) | ||
} else if (isCommandSystemExit(command)) { | ||
this.handleExit(command) | ||
} else { | ||
console.log('[FakeBridge] received unknown command: ' + JSON.stringify(command)) | ||
} | ||
} | ||
|
||
handleDonation (command: CommandSystemDonate): void { | ||
console.log(`[FakeBridge] received donation: ${command.key}=${command.json_string}`) | ||
} | ||
|
||
handleExit (command: CommandSystemExit): void { | ||
console.log(`[FakeBridge] received exit: ${command.code}=${command.info}`) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import ReactEngine from './visualisation/react/engine' | ||
import ReactFactory from './visualisation/react/factory' | ||
import WorkerProcessingEngine from './processing/worker_engine' | ||
import { VisualisationEngine, ProcessingEngine, Storage } from './types/modules' | ||
import { VisualisationEngine, ProcessingEngine, Bridge } from './types/modules' | ||
import CommandRouter from './command_router' | ||
|
||
export default class Assembly { | ||
visualisationEngine: VisualisationEngine | ||
processingEngine: ProcessingEngine | ||
router: CommandRouter | ||
|
||
constructor (worker: Worker, system: Storage) { | ||
constructor (worker: Worker, bridge: Bridge) { | ||
const sessionId = String(Date.now()) | ||
this.visualisationEngine = new ReactEngine(new ReactFactory()) | ||
this.router = new CommandRouter(system, this.visualisationEngine) | ||
this.router = new CommandRouter(bridge, this.visualisationEngine) | ||
this.processingEngine = new WorkerProcessingEngine(sessionId, worker, this.router) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+96 Bytes
(100%)
src/framework/processing/py/dist/port-0.0.0-py3-none-any.whl
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,37 @@ | ||
import './fonts.css' | ||
import './framework/styles.css' | ||
import Assembly from './framework/assembly' | ||
import { Storage } from './framework/types/modules' | ||
import LiveStorage from './live_storage' | ||
import FakeStorage from './fake_storage' | ||
import { Bridge } from './framework/types/modules' | ||
import LiveBridge from './live_bridge' | ||
import FakeBridge from './fake_bridge' | ||
|
||
const rootElement = document.getElementById('root') as HTMLElement | ||
|
||
const locale = 'en' | ||
const workerFile = new URL('./framework/processing/py_worker.js', import.meta.url) | ||
const worker = new Worker(workerFile) | ||
|
||
let assembly: Assembly | ||
|
||
const run = (system: Storage): void => { | ||
assembly = new Assembly(worker, system) | ||
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') { | ||
if (process.env.REACT_APP_BUILD !== 'standalone' && process.env.NODE_ENV === 'production') { | ||
// Setup embedded mode (requires to be embedded in iFrame) | ||
console.log('Initializing storage system') | ||
LiveStorage.create(window, run) | ||
console.log('Initializing bridge system') | ||
LiveBridge.create(window, run) | ||
} else { | ||
// Setup local development mode | ||
console.log('Running with fake storage') | ||
run(new FakeStorage()) | ||
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { CommandSystem, isCommandSystem } from './framework/types/commands' | ||
import { Bridge } from './framework/types/modules' | ||
|
||
export default class LiveBridge implements Bridge { | ||
port: MessagePort | ||
|
||
constructor (port: MessagePort) { | ||
this.port = port | ||
} | ||
|
||
static create (window: Window, callback: (bridge: Bridge, locale: string) => void): void { | ||
window.addEventListener('message', (event) => { | ||
console.log('MESSAGE RECEIVED', event) | ||
// Skip webpack messages | ||
if (event.data.action === 'live-init') { | ||
const bridge = new LiveBridge(event.ports[0]) | ||
const locale = event.data.locale | ||
console.log('LOCALE', locale) | ||
callback(bridge, locale) | ||
} | ||
}) | ||
} | ||
|
||
send (command: CommandSystem): void { | ||
if (isCommandSystem(command)) { | ||
this.port.postMessage(command) | ||
} else { | ||
this.log('error', 'received unknown command', command) | ||
} | ||
} | ||
|
||
private log (level: 'info' | 'error', ...message: any[]): void { | ||
const logger = level === 'info' ? console.log : console.error | ||
logger(`[${this.constructor.name}]`, ...message) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.