Sunday, 14 May 2017

Click event in node.js does not work

I am using Node.js + Express + Jade + Socket.io to set up click events in one browser to trigger a click on a button in another. I am having difficulty getting this to work. The code I have so far is:

Client side (index.jade):

var socket = io.connect('http://localhost:8080');
  $('#buttonLeft').tap(function() {
    socket.emit('keyLeft');
  });
});

Server side:

var sockets = {};
io.sockets.on('connection', function (socket) {
  socket.on('keyLeft', function(){
    socket.broadcast.emit('keyLeft');
  });
});

Another client side (index.html):

var socket = io.connect('http://localhost:8080');

socket.on('keyLeft', function(){
  $('a.previousSlideArrow').click();
});

Any help would be really appreciated. Thanks~



via Fanny Febriani Susilo

No comments:

Post a Comment