you need to add a function that clears the interval and then restarts it
function resetInterval() { clearInterval(timer); timer = setInterval(function() { console.log("restarted interval"); test1(); }, 5000); }
then you can just call him as needed
chat.client.addMessage = function(data) { resetInterval(); test2(data); };
source share