Skip to content

Instantly share code, notes, and snippets.

@aldidas
Last active December 10, 2016 01:43
Show Gist options
  • Save aldidas/801d0e50b096077698fcdd9e808e5769 to your computer and use it in GitHub Desktop.
Save aldidas/801d0e50b096077698fcdd9e808e5769 to your computer and use it in GitHub Desktop.
Rendered for the lamp app
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