feat: add data generation logic and history file class
This commit is contained in:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user