Commit 51f0ad11 by Иван Кубота

no socket

parent c0d0b8d0
......@@ -116,12 +116,17 @@ wss.on('connection', function connection(ws) {
ws.send(JSON.stringify({type: 'connected', data: null}));
});
console.log('WS LISTEN port: '+env.WS_PORT);
var logging = [];
global.log = function(type, data){
try{
logging.push({date:+new Date(), type, data});
wss.clients.forEach(function each(client) {
client.send(JSON.stringify({type, data}));
});
}catch (e) {
}
}
\ No newline at end of file
}
global.log.logging = logging;
\ No newline at end of file
......@@ -140,14 +140,28 @@
if(code.join('91') === '1391666911391666'){
hh1.style.display = 'none';
hh2.style.display = 'block';
var begin = 0;
setInterval(function () {
fetch('http://vkusvill.flexlab.pro:4001/api/quiz/monitordata?start='+begin)
.then(response => response.json())
.then(data => {
debugger;
data;
data.forEach(data=>{
actions[data.type](data.data);
begin = data.date;
})
} );
},1000);
let socket = new WebSocket('ws://'+location.hostname+':8080');
socket.onmessage = function(event) {
/* socket.onmessage = function(event) {
var data = JSON.parse(event.data);
actions[data.type](data.data);
};
};*/
}
};
/*code = [0,13,666,13,666];
......
......@@ -274,5 +274,15 @@ module.exports = {
return (await readFile('./public/monitor.html')).toString('utf-8');
}
},
'/api/quiz/monitordata': {
method: 'GET',
options: {
start: {required: false, description: 'begin date', type: Number},
},
summary: 'monitordata',
fn: async function(args, req, res){
return log.logging.filter(l=>l.start>=args.start);
}
}
};
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment