-
Notifications
You must be signed in to change notification settings - Fork 53
/
index.js
53 lines (45 loc) · 1.36 KB
/
index.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2022 by Croquet Corporation, Inc. All Rights Reserved.
// https://croquet.io
import { startShell, startMicroverse, setupController, setupFullScreenButton } from "./shell.js";
window.microverseEnablePortal = new URL(window.location).searchParams.has("enablePortal");
function isShellFrame() {
const isOuterFrame = window.self === window.parent;
if (isOuterFrame) return true;
const portalId = new URL(location.href).searchParams.get("portal");
return !portalId;
}
async function runPrelude() {
let url = window.location.origin + window.location.pathname;
let match = /([^/]+)\.html$/.exec(url);
let baseurl;
if (match) {
baseurl = url.slice(0, match.index);
} else {
let slash = url.lastIndexOf("/");
baseurl = url.slice(0, slash + 1);
}
try {
const { prelude } = await eval(`import('${baseurl}prelude.js')`);
await prelude();
} catch(e) {
console.log("error in the prelude function");
}
}
async function start() {
await runPrelude();
if (!window.microverseEnablePortal) {
startShell();
setupController(true);
startMicroverse();
return;
}
if (isShellFrame()) {
startShell(true);
setupFullScreenButton();
} else {
setupController();
startMicroverse();
}
}
start();