-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcode.html
101 lines (100 loc) · 2.74 KB
/
code.html
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>LiveCodes Broadcast</title>
<style>
body {
display: flex;
flex-direction: column;
font: 0.9em sans-serif;
justify-content: center;
overflow: hidden;
}
h1 {
text-align: center;
font-size: 1.5em;
color: rgb(72, 72, 72);
}
#container {
border: 1px solid black;
border-radius: 5px;
height: 80vh;
min-height: 250px;
width: 80%;
margin: auto;
}
#container iframe {
border: 0;
border-radius: 5px;
height: 100%;
width: 100%;
}
#footer {
margin: 1em;
text-align: center;
}
#footer a {
color: rgb(72, 72, 72);
font-size: 0.9em;
margin: 1em;
text-decoration: none;
}
#footer a:hover {
text-decoration: underline;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/socket.io-client@4.5.1/dist/socket.io.min.js"></script>
</head>
<body>
<h1>LiveCodes Broadcast</h1>
<div id="container"></div>
<div id="footer">
<a target="_blank" href="https://livecodes.io">LiveCodes</a>
<a
target="_blank"
href="https://livecodes.io/web/docs/features/broadcast"
>Broadcast docs</a
>
</div>
<script type="module">
import { createPlayground } from "https://livecodes.io/sdk/livecodes.js";
const options = {
config: {
markup: {
language: "html",
content: "Loading...",
},
readonly: true,
},
};
createPlayground("#container", options).then(async (playground) => {
const loadConfig = async (_result, config) => {
await playground.setConfig({
...config,
readonly: true,
});
if (config.activeEditor) {
const { lineNumber = 1, column = 1 } =
config[config.activeEditor]?.position;
await playground.show(config.activeEditor, {
line: lineNumber,
column,
});
}
};
const socket = io();
socket.on("receive", loadConfig);
window.playground = playground;
socket.on("disconnect", async () => {
await playground.destroy();
document.querySelector("#container").innerHTML =
'<div style="text-align: center; padding: 2em;">Broadcast Disconnected!</div>';
});
const channel = location.pathname.split("/").slice(-1)[0];
socket.emit("join", channel);
});
</script>
</body>
</html>