/**
 * This is the server side of the handswithoutborders project.
 * It acts as a notification server that relays messages between
 * two clients.
 **/

var io = require('socket.io')({
    transports: ['websocket']
}).listen(1337);
//io.set('destroy upgrade', false);
//io.set('log level',5);

io.on('connection', function (socket) {
    console.log("SOMETHING CONNECTED");
    socket.on('error', function() { console.log("error"); });
    socket.on('disconnect', function() {
        console.log('Something disconnect...');
    });

    //debug unhandled messages//
    socket.on('message', function(data){        console.log(data)    })

    socket.on('getVacation', function (data) {
        console.log("Phone asked Display for vacation number.")
        socket.broadcast.emit("getVacation", data);
    });

    socket.on('setVacation', function(data){
        console.log("Display passed back vacation number to Phone.")
        socket.broadcast.emit("setVacation", data);
    })
});

io.sockets.on('error', function (data) {
    console.log("some error");
});
