feat: add data generation logic and history file class

This commit is contained in:
Leons Aleksandrovs
2025-07-07 15:52:32 +03:00
parent 4284804536
commit 675f12906e
5 changed files with 126 additions and 2 deletions

View File

@@ -1,8 +1,15 @@
const WebSocket = require('ws');
import { WebSocketServer } from 'ws';
import HistoryFile from './classes/HistoryFile.js';
const wss = new WebSocket.Server({ port: 8080 });
// Define WebSocket server
const wss = new WebSocketServer({ port: 8080 });
// Define History file class
// For managing data state beyond restart
const history = new HistoryFile('data.json');
wss.on('connection', (ws) => {
// On successful connection, we send history data to the client
// After that, we procceed sending data update every 10 seconds
console.log('Client connected');
ws.on('message', (message) => {