diff --git a/NxStreamingService/Build.bat b/NxStreamingService/Build.bat new file mode 100644 index 0000000..2b6c6c5 --- /dev/null +++ b/NxStreamingService/Build.bat @@ -0,0 +1,5 @@ +@echo off +Title Building... +Echo Building... +nexe main.js -o "./NxStreamingService.exe" +pause \ No newline at end of file diff --git a/WindowsStreamer/Devlord_modules/DB.js b/NxStreamingService/Devlord_modules/DB.js similarity index 100% rename from WindowsStreamer/Devlord_modules/DB.js rename to NxStreamingService/Devlord_modules/DB.js diff --git a/WindowsStreamer/Devlord_modules/conColors.js b/NxStreamingService/Devlord_modules/conColors.js similarity index 100% rename from WindowsStreamer/Devlord_modules/conColors.js rename to NxStreamingService/Devlord_modules/conColors.js diff --git a/WindowsStreamer/Devlord_modules/conSplash.js b/NxStreamingService/Devlord_modules/conSplash.js similarity index 100% rename from WindowsStreamer/Devlord_modules/conSplash.js rename to NxStreamingService/Devlord_modules/conSplash.js diff --git a/WindowsStreamer/InstallModules.bat b/NxStreamingService/InstallModules.bat similarity index 100% rename from WindowsStreamer/InstallModules.bat rename to NxStreamingService/InstallModules.bat diff --git a/NxStreamingService/NXStreamer.exe b/NxStreamingService/NXStreamer.exe new file mode 100644 index 0000000..07d4259 Binary files /dev/null and b/NxStreamingService/NXStreamer.exe differ diff --git a/WindowsStreamer/Package.bat b/NxStreamingService/Package.bat similarity index 100% rename from WindowsStreamer/Package.bat rename to NxStreamingService/Package.bat diff --git a/NxStreamingService/Start.bat b/NxStreamingService/Start.bat new file mode 100644 index 0000000..0a01dc4 --- /dev/null +++ b/NxStreamingService/Start.bat @@ -0,0 +1,4 @@ +@echo off +cls +npm start main.js /ip 172.16.0.10 /q 10 +pause \ No newline at end of file diff --git a/WindowsStreamer/ffmpeg.exe b/NxStreamingService/lib/ffmpeg.exe similarity index 100% rename from WindowsStreamer/ffmpeg.exe rename to NxStreamingService/lib/ffmpeg.exe diff --git a/WindowsStreamer/main.js b/NxStreamingService/main.js similarity index 89% rename from WindowsStreamer/main.js rename to NxStreamingService/main.js index 7c3b5ac..4ec473b 100644 --- a/WindowsStreamer/main.js +++ b/NxStreamingService/main.js @@ -9,14 +9,15 @@ const VGen = require("vgen-xbox") const vgen = new VGen(); const cc = require('./Devlord_modules/conColors.js'); const cs = require('./Devlord_modules/conSplash.js'); - +var ip = "0.0.0.0" +var quality = 5; var screenSize = robot.getScreenSize(); var sheight = screenSize.height; var swidth = screenSize.width; var hidStreamClient = new net.Socket(); -function connect(address) { +function connect() { hidStreamClient.connect({ - host: "172.16.0.10", + host: ip, port: 2223 }); } @@ -31,8 +32,7 @@ hidStreamClient.on('error', function (ex) { setTimeout(connect, 1000); } }); -hidStreamClient.on('connect', function () { - console.log('Connected to Switch!'); +function plugControllerIn() { try { // Try plugging in first controller controllerId = vgen.pluginNext(); @@ -40,23 +40,28 @@ hidStreamClient.on('connect', function () { catch (e) { // Exception most probably due to drivers not installed vgen.installDriver(() => { - vgen.plugin(controllerId); + setTimeout(plugControllerIn, 1000); }); } +} +hidStreamClient.on('connect', function () { + console.log('Connected to Switch!'); + + + plugControllerIn(); + + ffmpegProcess = spawn( - "./ffmpeg.exe", - ["-probesize", "10M", "-f", "gdigrab", "-framerate", "60", "-video_size", swidth + "x" + sheight, "-offset_x", "0", "-offset_y", "0", "-i", "desktop", "-f", "h264", "-vf", "scale=1280x720", "-preset", "ultrafast", "-tune", "zerolatency", "-pix_fmt", "yuv420p", "-profile:v", "baseline", "-x264-params", "\"nal-hrd=cbr\"", "-b:v", "5M", "-minrate", "5M", "-maxrate", "5M", "-bufsize", "2M", "tcp://172.16.0.10:2222"], + "./lib/ffmpeg.exe", + ["-probesize", "10M", "-f", "gdigrab", "-framerate", "60", "-video_size", swidth + "x" + sheight, "-offset_x", "0", "-offset_y", "0", "-i", "desktop", "-f", "h264", "-vf", "scale=1280x720", "-preset", "ultrafast", "-tune", "zerolatency", "-pix_fmt", "yuv420p", "-profile:v", "baseline", "-x264-params", "\"nal-hrd=cbr\"", "-b:v", quality + "M", "-minrate", quality + "M", "-maxrate", quality + "M", "-bufsize", "2M", "tcp://" + ip + ":2222"], { stdio: "pipe" } ); - ffmpegProcess.stdout.on("data", chunk => { }); - ffmpegProcess.stderr.on('data', (data) => { //console.error(`stderr: ${data}`); }); - ffmpegProcess.on('close', (code) => { console.log(`ffmpegProcess process exited with code ${code}`); }); @@ -64,22 +69,19 @@ hidStreamClient.on('connect', function () { ffmpegAudioProcess = spawn( - "./ffmpeg.exe", - ["-y", "-f", "dshow", "-i", "audio=virtual-audio-capturer", "-f", "s16le", "-ar", "16000", "-ac", "2", "-c:a", "pcm_s16le", "udp://172.16.0.10:2224?pkt_size=640"], + "./lib/ffmpeg.exe", + ["-y", "-f", "dshow", "-i", "audio=virtual-audio-capturer", "-f", "s16le", "-ar", "16000", "-ac", "2", "-c:a", "pcm_s16le", "udp://" + ip + ":2224?pkt_size=640"], { stdio: "pipe" } ); ffmpegAudioProcess.stdout.on("data", chunk => { //videoStreamClient.write(chunk); }); - ffmpegAudioProcess.stderr.on('data', (data) => { //console.error(`stderr: ${data}`); }); - ffmpegAudioProcess.on('close', (code) => { console.log(`ffmpegAudioProcess process exited with code ${code}`); }); - }); var switchHidBuffer = new Buffer.alloc(0); function parseInputStruct(buff) { @@ -275,11 +277,26 @@ hidStreamClient.on('end', function () { connect(); }); -connect(); - -module.exports.init = connect - +var args = process.argv.slice(" "); + +if (args.length > 1) { + if (args.includes("/ip") && args[args.indexOf("/ip") + 1]) { + ip = args[args.indexOf("/ip") + 1]; + console.log('Waiting for connection...'); + if (args.includes("/q") && args[args.indexOf("/q") + 1]) { + quality = args[args.indexOf("/q") + 1]; + } else { + console.log('Error: Usage NXStreamer.exe ip 0.0.0.0 q 5'); + } + connect(); + } else { + console.log('Error: Usage NXStreamer.exe ip 0.0.0.0 q 5'); + } +} else { + +} +console.log(args[args.indexOf("/ip") + 1]); diff --git a/WindowsStreamer/package-lock.json b/NxStreamingService/package-lock.json similarity index 100% rename from WindowsStreamer/package-lock.json rename to NxStreamingService/package-lock.json diff --git a/WindowsStreamer/package.json b/NxStreamingService/package.json similarity index 85% rename from WindowsStreamer/package.json rename to NxStreamingService/package.json index 1e701ca..d1126a3 100644 --- a/WindowsStreamer/package.json +++ b/NxStreamingService/package.json @@ -16,5 +16,9 @@ }, "scripts": { "start": "node main.js" + }, + "pkg": { + "scripts": "node_modules/**/*", + "assets": "lib/**/*" } -} +} \ No newline at end of file diff --git a/WindowsStreamer/settings.json b/NxStreamingService/settings.json similarity index 100% rename from WindowsStreamer/settings.json rename to NxStreamingService/settings.json diff --git a/WindowsStreamer/testStreamServer.bat b/NxStreamingService/testStreamServer.bat similarity index 100% rename from WindowsStreamer/testStreamServer.bat rename to NxStreamingService/testStreamServer.bat diff --git a/WindowsStreamer/Start.bat b/WindowsStreamer/Start.bat deleted file mode 100644 index ed0e063..0000000 --- a/WindowsStreamer/Start.bat +++ /dev/null @@ -1,4 +0,0 @@ -@echo off -cls -npm start -pause \ No newline at end of file