Forgive me, I've been learning node and js over the last few days, come from C#/unity and everything is a little bit different from what I know. I'm making a collaborative drum machine, I've got 90% working: http://ec2-54-194-29-66.eu-west-1.compute.amazonaws.com:9000/
I have the node server working, with key presses being sent and mouse co-ords, however I have an issue with mapping a mouse click event, I am registering the click in console of other connections and server, but seems I don't quite understand sending the contents of events properly. I can't write var data = list: e.classList and read data.list to do the see the same thing?
Here's code I've been trying to get working, but I get cannot read property error:
function newMouseOn(data)
{
console.log("Is this working Click On?" + data.target);
data.list.add('active');
//clickPlayOn(data);
data.target.play();
}
function newMouseOff(data)
{
console.log("Is this working ClickOff?" + data.target);
//clickPlayOff(data);
data.list.remove('active');
}
socket.on('mouseOn', newMouseOn);
socket.on('mouseOff', newMouseOff);
function clickPlayOn(e)
{
var data = {
id: e.target.id,
timeStamp: e.timeStamp,
type: e.type,
target: e.target,
list: e.classList
}
socket.emit('mouseOn', data);
e.target.classList.add('active');
e.target.play();
}
function clickPlayOff(e)
{
var data =
{
id: e.target.id,
timeStamp: e.timeStamp,
type: e.type,
target: e.target,
list: e.classList
}
socket.emit('mouseOff', data);
e.target.classList.remove('active');
}
server side:
socket.on('mouseOn', MouseClick);
socket.on('mouseOff', MouseClicked);
function MouseClick(data)
{
socket.broadcast.emit('mouseOn', data);
console.log(data);
}
function MouseClicked(data)
{
socket.broadcast.emit('mouseOff', data);
console.log(data);
}
I was originally trying to just emit e or e.target instead of that data struct, but that didn't seem to work. Has anyone got any ideas on what I'm missing? (other than a brain)