/**
 * 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('hi', function(data){        console.log(data)    })

    socket.on('voiceMessage', function (data) {
        console.log("Voice Message received/sent...")
        socket.broadcast.emit("voiceMessageFromServer", data);
    });

    socket.on('updatePhoto', function(data){
        console.log("Photo Message received/sent...")
        socket.broadcast.emit("updatePhoto", data);
    })

    socket.on('alarmOn', function(data){
        console.log("Alarm turned on")
        socket.broadcast.emit("alarmOn", data);
    })
    socket.on('alarmOff', function(data){
        console.log("Alarm turned off")
        socket.broadcast.emit("alarmOff", data);
    })
});

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