import { WebSocketServer } from 'ws'; import { Config } from '../config/config.js'; import { Storage } from './storage.js'; export class WebSock { constructor() { let wss = new WebSocketServer({ port: Config.WEB_SERVER.WSPORT }); wss.on('connection', function connection(ws) { let sendData = setInterval(()=>{ Storage.hub.getTemp().then(r=>{ let data = {type:'temp',inside:r,outside:Storage.weather.data}; ws.send(JSON.stringify(data)); //console.log(ws) }) },10000) ws.on('message', function message(data) { console.log('received: %s', data); }); ws.on('close',()=>{ clearInterval(sendData); }) }); this.wss = wss; /*Storage.web.app.on('upgrade', (request, socket, head) => { wss.handleUpgrade(request, socket, head, socket => { wss.emit('connection', socket, request); }); });*/ } }