Remove Wasm preload; instead, actually load it sooner

This commit is contained in:
Ingvar Stepanyan
2021-07-20 16:14:14 +00:00
parent 379c6ead81
commit e4afa15c2c
2 changed files with 9 additions and 8 deletions

View File

@@ -6,7 +6,6 @@
href="https://unpkg.com/purecss@2.0.6/build/pure-min.css" href="https://unpkg.com/purecss@2.0.6/build/pure-min.css"
crossorigin="anonymous" crossorigin="anonymous"
/> />
<link rel="preload" href="libapi.wasm" as="fetch" />
<style> <style>
.center-parent { .center-parent {
display: flex; display: flex;

16
ui.js
View File

@@ -12,15 +12,17 @@ if (isDebug) {
} }
/** This function should be called once user has selected the camera and other operations can begin. */ /** This function should be called once user has selected the camera and other operations can begin. */
let prepareContext; let start;
let started = new Promise(resolve => {
start = resolve;
});
/** Schedules an exclusive async operation on the global context. */ /** Schedules an exclusive async operation on the global context. */
const scheduleOp = (() => { const scheduleOp = (() => {
let queue = (async () => { let queue = (async () => {
await new Promise(resolve => {
prepareContext = resolve;
});
let { Context } = await initModule(); let { Context } = await initModule();
await started;
let ctx = await new Context(); let ctx = await new Context();
addEventListener('beforeunload', e => { addEventListener('beforeunload', e => {
ctx.delete(); ctx.delete();
@@ -281,12 +283,12 @@ class App extends Component {
} }
this.setState({ type: 'CameraPicker' }); this.setState({ type: 'CameraPicker' });
}); });
window.onerror = message => { addEventListener('error', ({ message }) => {
this.setState({ this.setState({
type: 'Status', type: 'Status',
message: `${message}` message: `${message}`
}); });
}; });
} }
selectDevice = async () => { selectDevice = async () => {
@@ -303,7 +305,7 @@ class App extends Component {
}; };
connectToCamera() { connectToCamera() {
prepareContext(); start();
this.setState({ type: 'Status', message: 'Connecting...' }); this.setState({ type: 'Status', message: 'Connecting...' });
(async () => { (async () => {
while (true) { while (true) {