Skip to content

Instantly share code, notes, and snippets.

@giljr
Last active January 17, 2020 23:43
Show Gist options
  • Save giljr/ace70ded1d56690640fe8bf5f991445a to your computer and use it in GitHub Desktop.
Save giljr/ace70ded1d56690640fe8bf5f991445a to your computer and use it in GitHub Desktop.
(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