latest_fix_read_live_files_from_/dev/shm/1.txt_file__to_lip_sink_with_external_tts
This commit is contained in:
39
server.js
39
server.js
@@ -1,11 +1,48 @@
|
||||
const express = require('express');
|
||||
const path = require('path');
|
||||
const http = require('http');
|
||||
const WebSocket = require('ws');
|
||||
const fs = require('fs');
|
||||
|
||||
const app = express();
|
||||
const PORT = 3000;
|
||||
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
|
||||
app.listen(PORT, () => {
|
||||
const server = http.createServer(app);
|
||||
const wss = new WebSocket.Server({ server });
|
||||
|
||||
wss.on('connection', (ws, req) => {
|
||||
const endpoint = req.url;
|
||||
|
||||
if (endpoint === '/handler1') {
|
||||
const interval = setInterval(() => {
|
||||
try {
|
||||
const data = fs.readFileSync('/dev/shm/1.txt', 'utf8').trim();
|
||||
ws.send(data);
|
||||
} catch (e) {
|
||||
ws.send('0');
|
||||
}
|
||||
}, 50); // sends every 50ms = 20 times per second
|
||||
|
||||
ws.on('close', () => {
|
||||
clearInterval(interval); // cleanup when client disconnects
|
||||
});
|
||||
}
|
||||
|
||||
// if (endpoint === '/handler2') {
|
||||
// const interval = setInterval(() => {
|
||||
// try {
|
||||
// const data = fs.readFileSync('/dev/shm/2.txt', 'utf8').trim();
|
||||
// ws.send(data);
|
||||
// } catch (e) {
|
||||
// ws.send('0');
|
||||
// }
|
||||
// }, 50);
|
||||
// ws.on('close', () => clearInterval(interval));
|
||||
// }
|
||||
});
|
||||
|
||||
server.listen(PORT, () => {
|
||||
console.log(`Server running at http://localhost:${PORT}`);
|
||||
});
|
||||
Reference in New Issue
Block a user