socket implementation
function subscribeToTimer(cb) {
socket.on("timer", timestamp => {
console.log(timestamp);
});
socket.emit("subscribeToTimer", 1000);
}
subscribeToTimer();
const io = require("socket.io")();
io.on("connection", client => {
client.on("subscribeToTimer", interval => {
console.log("client is subscribing to timer with interval ", interval);
setInterval(() => {
client.emit("timer", new Date());
}, interval);
});
});
const port = 8000;
io.listen(port);
console.log("listening on port ", port);