Skip to content

Commit 14d1598

Browse files
authored
Merge pull request #1 from LiaScript/main
feat: Add synchronization of courses via Edrys
2 parents 8da102a + 073812d commit 14d1598

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

index.html

+40-2
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,53 @@
1313
<script src="https://edrys-org.github.io/edrys/module/edrys.js"></script>
1414

1515
<script defer src="https://edrys-org.github.io/edrys/module/vendor/alpine.min.js"></script>
16+
17+
<script>
18+
function init(iframe) {
19+
Edrys.onMessage(({
20+
from,
21+
subject,
22+
body
23+
}) => {
24+
if (Edrys.username !== from) {
25+
iframe.contentWindow.postMessage({
26+
subject: subject,
27+
body: body
28+
}, "*")
29+
}
30+
})
31+
32+
window.addEventListener('message', function (e) {
33+
// Get the sent data
34+
const msg = e.data;
35+
36+
switch (msg.subject) {
37+
case "init":
38+
iframe.contentWindow.postMessage({
39+
subject: msg.subject,
40+
body: true
41+
}, "*")
42+
break
43+
44+
default:
45+
// this is required in order to transmit only messages
46+
// from LiaScript otherwise it will loop forever
47+
if (!(msg.event && msg.event == "message"))
48+
Edrys.sendMessage(msg.subject, msg.body)
49+
}
50+
});
51+
}
52+
</script>
53+
1654
</head>
1755

1856
<body>
1957
<template x-if="!!edrys && !!url" x-data="{ edrys: undefined, url: undefined }" x-init="Edrys.onUpdate((e) => {
2058
edrys = {...e}
21-
url = `https://liascript.github.io/course/?${edrys.module.config.course}`
59+
url = `https://liascript.github.io/course/?${Edrys.liveRoom.name == 'Lobby' ? edrys.module.config.course : btoa(JSON.stringify({'backend':'edrys','course':edrys.module.config.course,'room':Edrys.liveRoom.name}))}`
2260
})">
2361

24-
<iframe :src="url" frameborder="0" style="width:100%;height:100%;"
62+
<iframe :src="url" frameborder="0" style="width:100%;height:100%;" onload="init(this)"
2563
allow="camera; microphone; fullscreen; display-capture;"></iframe>
2664
</template>
2765

0 commit comments

Comments
 (0)