Last active
December 10, 2016 01:43
-
-
Save aldidas/801d0e50b096077698fcdd9e808e5769 to your computer and use it in GitHub Desktop.
Rendered for the lamp app
This file contains 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
const io = require('socket.io-client') | |
const CONSTANTS = require('./const') | |
const socket = io.connect('http://localhost:' + CONSTANTS.PORT) | |
const theLight = document.getElementById('the-light') | |
// log the message, check if socket.io server is connected | |
socket.on('init', (data) => { | |
console.log(data.message) | |
}) | |
// catch the data if 'ldr' event occur | |
socket.on('ldr', (data) => { | |
let opacity = data.opacity | |
if( opacity < 85 ) { | |
opacity = 0 | |
} | |
// set element opacity based on data value | |
theLight.style.opacity = opacity / 100 | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment