Last active
January 17, 2020 23:43
-
-
Save giljr/ace70ded1d56690640fe8bf5f991445a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var socket = io.connect(window.location.hostname + ':' + 3000); | |
var red = document.getElementById('red'); | |
var green = document.getElementById('green'); | |
var blue = document.getElementById('blue'); | |
function emitValue(color, e) { | |
socket.emit('rgb', { | |
color: color, | |
value: e.target.value | |
}); | |
} | |
red.addEventListener('change', emitValue.bind(null, 'red')); | |
blue.addEventListener('change', emitValue.bind(null, 'blue')); | |
green.addEventListener('change', emitValue.bind(null, 'green')); | |
socket.on('connect', function(data) { | |
socket.emit('join', 'Client is connected!'); | |
}); | |
socket.on('rgb', function(data) { | |
var color = data.color; | |
document.getElementById(color).value = data.value; | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment