add socket.io

This commit is contained in:
2023-06-04 14:44:13 +02:00
parent 9fabb64161
commit 60ffb862dc
9 changed files with 494 additions and 60 deletions

View File

@@ -6,11 +6,24 @@ const bodyParser = require( 'body-parser' );
const exec = require( 'child_process' ).exec;
const upscaling = require( './upscalingHandler.js' );
const upscalingHandler = new upscaling();
const http = require( 'http' );
const server = require( 'socket.io' ).Server;
const Server = http.createServer( app );
const io = new server( Server, {
cors: {
origin: 'http://localhost:8080'
}
} );
app.use( bodyParser.urlencoded( { extended: false } ) );
app.use( bodyParser.json() );
app.use( cors() );
io.on( 'connection', ( socket ) => {
console.log( 'connected' );
} )
app.get( '/api/getEngines', ( request, response ) => {
console.log( 'engines' );
@@ -45,10 +58,10 @@ app.post( '/api/startUpscaling', ( request, response ) => {
let checks = upscalingHandler.verifyDataIntegrity( request.body );
if ( checks[ 0 ] ) {
response.send( { 'data': checks[ 1 ] } );
upscalingHandler.upscale( request.body );
upscalingHandler.upscale( request.body, io );
} else {
response.send( { 'data': checks[ 1 ] } );
}
} );
app.listen( 8081 );
Server.listen( 8081 );