I'm sending some data from my web page using socket.io and then handling it in the node.js back end.
The code I use to send my data is:
var joystick1 = new VirtualJoystick({
container : document.body,
strokeStyle : 'cyan'
});
setInterval(function(){
var outputEl = document.getElementById('resulty');
outputEl.innerHTML = joystick1.deltaY();
//THE DATA IS SENT HERE
socket.emit('key', {Speed: joystick1.deltaY()});
}, 1/30 * 1000);
joystick1.addEventListener('touchStartValidation', function(event){
var touch = event.changedTouches[0];
if( touch.pageX >= window.innerWidth/2 ) return false;
return true
});
I handle it in node.js using this code:
socket.on('key', KeyReceived); //Key received from client
function KeyReceived(data)
{
//DATA IS PRINTED HERE
console.log(data);
switch(data.Key)
{
case "Steering":
_direction = 90 + data.value;
console.log(_direction);
break;
case "Speed":
_speed = 90 + data.value;
console.log(_speed);
break;
case "Adjustment":
_adjustment = data.value;
break;
}
}
In the console this prints out my data, but for some reason it won’t go into my case statements because my keys don't match?
What do I need to change to make this work?