mirror of
https://github.com/yldio/copilot.git
synced 2024-12-27 04:10:05 +02:00
8295bd6882
this shall be a progressive process
35 lines
645 B
JavaScript
35 lines
645 B
JavaScript
const Emitter = require('component-emitter');
|
|
|
|
const cdm = {};
|
|
|
|
module.exports = (server) => ({
|
|
on: (id) => {
|
|
console.log('on', cdm[id]);
|
|
if (cdm[id] && (cdm[id].sockets > 0)) {
|
|
cdm[id].sockets +=1;
|
|
return;
|
|
}
|
|
|
|
|
|
let messageId = 0;
|
|
const interval = setInterval(() => {
|
|
console.log(`publishing /stats/${id}`);
|
|
|
|
server.publish(`/stats/${id}`, {
|
|
when: new Date().getTime(),
|
|
cpu: Math.random() * 100
|
|
});
|
|
}, 45);
|
|
|
|
cdm[id] = {
|
|
interval,
|
|
sockets: 1
|
|
};
|
|
},
|
|
off: (id) => {
|
|
if (!(cdm[id].sockets -= 1)) {
|
|
clearInterval(cdm[id].interval);
|
|
}
|
|
}
|
|
});
|