Skip to content

Commit f2d2c62

Browse files
author
Max Carlson
committed
Fix css, clean up subscription logic and qr code generation
1 parent 7b07e4b commit f2d2c62

File tree

1 file changed

+43
-14
lines changed

1 file changed

+43
-14
lines changed

WebSites/spacetime/index.html

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,46 @@
77
<link rel="icon" href="https://brand.publiccode.net/logo/mark-128w128h.png">
88
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js"></script>
99
<script src="qrcode.min.js"></script>
10+
<script>
11+
const qrcodeDefaults = {dim: 100, pad: 1, pal: ['#000','#fff']}
12+
const getQrcodeLink = (url) => {
13+
const el = document.createElement('a');
14+
el.href = url;
15+
el.target = "_new";
16+
el.className = "qrcode";
17+
// pass {msg: 'http://...'} and/or overrides for qrcodeDefaults
18+
const svg = QRCode( {...qrcodeDefaults, msg: url})
19+
el.appendChild(svg);
20+
return el;
21+
}
22+
</script>
23+
<style>
24+
body {
25+
text-align: right;
26+
padding: 0;
27+
border: 0;
28+
margin: 0;
29+
width: 100vw;
30+
height: 100vh;
31+
overflow: hidden;
32+
}
33+
.qrcode {
34+
position: absolute;
35+
top: 0;
36+
left: 0;
37+
width: 100px;
38+
height: 100px;
39+
}
40+
</style>
1041
</head>
11-
<body style="text-align: center; padding: 0; border: 0; margin: 0; width: 100vw; height: 100vh; overflow: hidden;">
42+
<body>
1243
<script>
1344
// Create a single supabase client for interacting with your database
1445
const client = supabase.createClient('https://gwodhwyvuftyrvbymmvc.supabase.co', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imd3b2Rod3l2dWZ0eXJ2YnltbXZjIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDIzNDkyMDMsImV4cCI6MjA1NzkyNTIwM30.APVpyOupY84gQ7c0vBZkY-GqoJRPhb4oD4Lcj9CEzlc')
1546

1647
const channel = client.channel("navigators")
1748

1849
let subscribed = false;
19-
channel.subscribe((status) => {
20-
console.log('subscribe', status)
21-
if (status === 'SUBSCRIBED') {
22-
subscribed = true;
23-
}
24-
})
25-
2650
function sendEvent(event, payload) {
2751
if (! subscribed) return;
2852
console.log('sendEvent', name, payload)
@@ -33,6 +57,7 @@
3357
})
3458
}
3559

60+
// handlers to send events into Unity
3661
function handlePos(payload) {
3762
console.log('handlePos', payload)
3863
}
@@ -43,6 +68,12 @@
4368

4469
// Subscribe to the Channel
4570
channel
71+
.subscribe((status) => {
72+
console.log('subscribe', status)
73+
if (status === 'SUBSCRIBED') {
74+
subscribed = true;
75+
}
76+
})
4677
.on(
4778
'broadcast',
4879
{ event: 'pos' },
@@ -55,12 +86,6 @@
5586
)
5687
</script>
5788
<canvas id="unity-canvas" width=960 height=600 tabindex="-1" style="width: 100%; height: 100%; position: fixed; top: 0; left: 0; background: #1F1F20"></canvas>
58-
<a href="navigator.html" target="_new" id="navqrcode" style="position: absolute; top:0; left:0; width:100px; height: 100px;"></a>
59-
<script>
60-
const qrcode = document.querySelector("#navqrcode");
61-
const msg = window.location + 'navigator.html'
62-
qrcode.appendChild( QRCode( {msg, dim: 200} ) )
63-
</script>
6489
<script src="Build/CraftSpace.loader.js"></script>
6590
<script>
6691
if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
@@ -91,5 +116,9 @@
91116
// devicePixelRatio: 1, // Uncomment this to override low DPI rendering on high DPI displays.
92117
});
93118
</script>
119+
<script>
120+
// add nagigator qr code
121+
document.body.appendChild( getQrcodeLink( window.location + 'navigator.html') );
122+
</script>
94123
</body>
95124
</html>

0 commit comments

Comments
 (0)