var WS = require('ws').Server
var server = new WS({ port: 3000 })
var attachAPI = require('./api')

server.on('connection', function (socket) {
  var api = attachAPI(socket)
  socket.on('close', function () {
    api.sensorUnsubscribe()
  })

  socket.on('message', function (data) {
    data = JSON.parse(data)
    try {
      var value = api[data.type](data)
      if (value) {
        socket.send(JSON.stringify(value))
      }
    } catch (e) {
      socket.send(JSON.stringify({
        type: 'error',
        value: e
      }))
    }
  })
})

@@ -228,16 +228,23 @@
 bscribe(
+'close'
 )%0A  %7D)%0A%0A

add tests