N
N
nezzard2016-12-26 16:35:38
Node.js
nezzard, 2016-12-26 16:35:38

How to kill socket.emit?

Good afternoon, there

socket.on('songchanged', function(changed){
  setInterval(function(){
     socket.broadcast.emit('changed', changed);
   }, 3000);
});

It is necessary to clear and delete the interval when the songchanged is repeated, killed in different ways, but everything sends the previous and new values ​​exactly from

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
catHD, 2016-12-26
@catHD

Why are you creating a question and not listening to the answers?
Why in the event system, do broadcast via Interval?
Why Interval and not setTimeout ?
Why are you even using Nodejs if you clearly don't understand it?

N
nezzard, 2016-12-26
@nezzard

io.on('connection', function (socket) {
   socket.on('songchanged', function(changed){
      socket.broadcast.emit('changed',  data);
   })
})

This is if without an interval, broadcast because, just the socket did not send anything to the client.
Interval because it is needed when a new client that has just connected received data that was received before it was connected

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question