|
6 | 6 | <title>Spacecraft in Unity</title> |
7 | 7 | <link rel="icon" href="https://brand.publiccode.net/logo/mark-128w128h.png"> |
8 | 8 | <script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js"></script> |
| 9 | + <script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js"></script> |
9 | 10 | <script src="qrcode.min.js"></script> |
10 | 11 | <script> |
11 | 12 | const qrcodeDefaults = {dim: 100, pad: 1, pal: ['#000','#fff']} |
12 | | - const getQrcodeLink = (url) => { |
| 13 | + const getQrcodeLink = (url, id) => { |
13 | 14 | const el = document.createElement('a'); |
14 | 15 | el.href = url; |
15 | 16 | el.target = "_new"; |
16 | 17 | el.className = "qrcode"; |
| 18 | + el.id = id; |
17 | 19 | // pass {msg: 'http://...'} and/or overrides for qrcodeDefaults |
18 | 20 | const svg = QRCode( {...qrcodeDefaults, msg: url}) |
19 | 21 | el.appendChild(svg); |
| 22 | + const label = document.createElement('div'); |
| 23 | + label.innerText = id; |
| 24 | + label.className = 'label'; |
| 25 | + el.appendChild(label); |
20 | 26 | return el; |
21 | 27 | } |
22 | 28 | </script> |
23 | 29 | <style> |
24 | 30 | body { |
| 31 | + font-family: "Mulish", Helvetica; |
25 | 32 | text-align: right; |
26 | 33 | padding: 0; |
27 | 34 | border: 0; |
|
37 | 44 | width: 100px; |
38 | 45 | height: 100px; |
39 | 46 | padding: 10px; |
| 47 | + opacity: .60; |
| 48 | + transition: opacity 1s; |
| 49 | + } |
| 50 | + .label { |
| 51 | + color: white; |
| 52 | + margin-top: 0; |
| 53 | + margin-bottom: 50px; |
40 | 54 | } |
41 | 55 | </style> |
42 | 56 | </head> |
|
60 | 74 |
|
61 | 75 | // handlers to send events into Unity |
62 | 76 | function handlePos(payload) { |
63 | | - console.log('handlePos', payload) |
| 77 | + console.debug('handlePos', payload) |
64 | 78 | } |
65 | 79 |
|
66 | 80 | function handleZoom(zoom) { |
67 | | - console.log('handleZoom', zoom) |
| 81 | + console.debug('handleZoom', zoom) |
| 82 | + } |
| 83 | + |
| 84 | + function handlePresence(id, payload) { |
| 85 | + const el = document.getElementById(id); |
| 86 | + console.debug('handlePresence', id, payload, el) |
| 87 | + userCount = Object.keys(payload).length |
| 88 | + el.style.opacity = userCount ? 1 : ''; |
68 | 89 | } |
69 | 90 |
|
70 | 91 | function handleSelectPos(payload) { |
71 | | - console.log('handleSelectPos', payload) |
| 92 | + console.debug('handleSelectPos', payload) |
72 | 93 | } |
73 | 94 |
|
74 | 95 | // handlers to send events into Unity |
75 | 96 | function handleSelectZoom(payload) { |
76 | | - console.log('handleSelectZoom', payload) |
| 97 | + console.debug('handleSelectZoom', payload) |
77 | 98 | } |
78 | 99 |
|
79 | 100 | // Subscribe to the navigatorChannel |
|
94 | 115 | { event: 'zoom' }, |
95 | 116 | (data) => handleZoom(data.payload.zoom) |
96 | 117 | ) |
| 118 | + .on('presence', { event: 'sync' }, () => { |
| 119 | + const newState = navigatorChannel.presenceState() |
| 120 | + handlePresence('navigator', newState) |
| 121 | + }) |
97 | 122 |
|
98 | 123 | const selectorChannel = client.channel("selectors") |
99 | 124 | // Subscribe to the selectorChannel |
100 | 125 | selectorChannel |
101 | 126 | .subscribe((status) => { |
102 | | - console.log('subscribe', status) |
| 127 | + console.debug('subscribe', status) |
103 | 128 | if (status === 'SUBSCRIBED') { |
104 | 129 | subscribed = true; |
105 | 130 | } |
|
114 | 139 | { event: 'zoom' }, |
115 | 140 | (data) => handleSelectZoom(data.payload.zoom) |
116 | 141 | ) |
| 142 | + .on('presence', { event: 'sync' }, () => { |
| 143 | + const newState = selectorChannel.presenceState() |
| 144 | + handlePresence('selector', newState) |
| 145 | + }) |
117 | 146 | </script> |
118 | 147 | <canvas id="unity-canvas" width=960 height=600 tabindex="-1" style="width: 100%; height: 100%; position: fixed; top: 0; left: 0; background: #1F1F20"></canvas> |
119 | 148 | <script src="Build/CraftSpace.loader.js"></script> |
|
148 | 177 | </script> |
149 | 178 | <script> |
150 | 179 | // add navigator and selector qr codes |
151 | | - document.body.appendChild( getQrcodeLink( window.location + 'navigator.html') ); |
152 | | - document.body.appendChild( getQrcodeLink( window.location + 'selector.html') ); |
| 180 | + document.body.appendChild( getQrcodeLink( window.location + 'navigator.html', 'navigator') ); |
| 181 | + document.body.appendChild( getQrcodeLink( window.location + 'selector.html', 'selector') ); |
153 | 182 | </script> |
154 | 183 | </body> |
155 | 184 | </html> |
0 commit comments