26 lines
890 B
JavaScript
26 lines
890 B
JavaScript
|
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);
|
||
|
})
|
||
|
ws.send('something');
|
||
|
});
|
||
|
this.wss = wss;
|
||
|
}
|
||
|
}
|