-
Notifications
You must be signed in to change notification settings - Fork 0
/
websocket-test.html
44 lines (38 loc) · 1.55 KB
/
websocket-test.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
<style>
button {
font-size: 16px;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
background: #ddd;
padding: 1em 2em;
border: 1px solid #ccc;
border-radius: 5px;
margin: .5em;
}
</style>
<button data-send-color data-color="255,0,0">Send red!</button><br />
<button data-send-color data-color="0,255,0">Send blue!</button><br />
<button data-send-color data-color="0,0,255">Send green!</button><br />
<br /><br />
<button data-send-color data-color="255,0,0" data-fade>Fade red!</button><br />
<button data-send-color data-color="0,255,0" data-fade>Fade blue!</button><br />
<button data-send-color data-color="0,0,255" data-fade>Fade green!</button><br />
<script src="https://cdn.jsdelivr.net/npm/socket.io-client@2/dist/socket.io.js"></script>
<script>
const socket = io('http://localhost:3030');
socket.on('connect', function () {
console.log('connected!')
});
socket.on('disconnect', function () {
console.log('disconnected!')
});
[...document.querySelectorAll('[data-send-color]')].forEach(button => {
button.addEventListener('click', () => {
sendColor(button.dataset.fade, button.dataset.color.split(','));
});
});
function sendColor(fade, [r, g, b]) {
console.log('send color', fade, r,g,b);
const arr = new Array(300).fill([r, g, b]);
socket.emit(typeof fade !== undefined ? 'data-fade' : 'data', arr);
}
</script>