diff --git a/signal.html b/signal.html index c7fd16c..fe26c37 100644 --- a/signal.html +++ b/signal.html @@ -355,7 +355,7 @@ > @@ -627,31 +627,6 @@ }); } - //渲染页面主内容 - const actions = { - "#config": async () => { - $("main").innerHTML = config; - await renderConfigForm(); - $("#auth").addEventListener("focus", () => toggleAuthInfo(event)); - $("#auth").addEventListener("blur", () => toggleAuthInfo(event)); - $("#http-auth").addEventListener("click", () => toggleAuthInput()); - $("form").addEventListener("change", () => submitConfig(event)); - }, - "#peer-stream": () => { - $("main").innerHTML = runningServer; - ps.addEventListener("playing", aggregateStats, { - once: true, - }); - ps.addEventListener("message", (e) => {}); - window.addEventListener("hashchange", (e) => clearTimeout(ps.timeout), { once: true }); - }, - "#process": () => { - $("main").innerHTML = process; - getProcess(); - }, - "": () => {}, - }; - //开关http验证 const toggleAuthInput = () => { $("#auth-input").style.display = $("#http-auth").checked ? "flex" : "none"; @@ -925,7 +900,8 @@ }; const getProcess = () => { - const ws = new WebSocket(`ws://${location.host}/${navigator.platform}`, `exec-ue`); + let ws = `ws://${location.host}/${navigator.platform}/${navigator.vendor}`; + ws = new WebSocket(ws, `exec-ue`); ws.onopen = function () { console.info("✅", ws); window.addEventListener("hashchange", () => ws.close(), { once: true }); @@ -936,13 +912,13 @@ logs = logs .map( (a) => ` - - ${a.type} - ${a.address} - ${a.PORT} - ${a.path} - 断开 - ` + + ${a.type} + ${a.address} + ${a.PORT} + ${a.path} + 断开 + ` ) .join(""); $("table tbody").innerHTML = logs; @@ -958,7 +934,7 @@ const process = event.target.parentElement.children; const PORT = process[2].innerText; let eval = { - "signal.js": "process.exit(0)", + "signal.js": "setTimeout(()=>process.exit(0),1),''", "Unreal Engine": `killUE(${PORT})`, " Peer Stream": `killPlayer(${PORT})`, }; @@ -975,9 +951,7 @@ if (!r.ok) throw r.headers.get("error"); handleUpdateSuccess($(`#process`)); }) - .catch((err) => { - alert(err); - }); + .catch((error) => alert(error)); } } @@ -1051,8 +1025,33 @@ }; // 页面加载和变化 - window.onload = window.onhashchange = () => { - actions[location.hash].call(); + window.onload = window.onhashchange = async () => { + switch (location.hash) { + case "#config": { + $("main").innerHTML = config; + await renderConfigForm(); + $("#auth").addEventListener("focus", () => toggleAuthInfo(event)); + $("#auth").addEventListener("blur", () => toggleAuthInfo(event)); + $("#http-auth").addEventListener("click", () => toggleAuthInput()); + $("form").addEventListener("change", () => submitConfig(event)); + break; + } + case "#peer-stream": { + $("main").innerHTML = runningServer; + ps.addEventListener("playing", aggregateStats, { + once: true, + }); + window.addEventListener("hashchange", (e) => clearTimeout(ps.timeout), { once: true }); + break; + } + case "#process": { + $("main").innerHTML = process; + getProcess(); + break; + } + default: { + } + } }; diff --git a/signal.js b/signal.js index 6ed0f48..a72ed2b 100644 --- a/signal.js +++ b/signal.js @@ -251,6 +251,20 @@ global.serve = async (PORT) => { } } + if (req.method === 'POST') { + require("./.js")(req, res, HTTP) + .then((result) => { + if (!res.writableEnded) res.end(result); + }) + .catch((err) => { + res.setHeader('error', String(err)) + res.writeHead(400); + res.end('', () => { }); + }); + return + } + + if (req.url === '/') req.url = '/signal.html' // serve static files const read = fs.createReadStream( path.join(__dirname, path.normalize(req.url)) @@ -264,16 +278,8 @@ global.serve = async (PORT) => { if (type) res.setHeader("Content-Type", type); read - .on("error", (err) => { - require("./.js")(req, res, HTTP) - .then((result) => { - if (!res.writableEnded) res.end(result); - }) - .catch((err) => { - res.setHeader('error',String(err)) - res.writeHead(400); - res.end('', () => { }); - }); + .on("error", async (error) => { + res.end(String(error)) }) .on("ready", () => { read.pipe(res); @@ -623,26 +629,26 @@ global.killPlayer = async function (playerId) { fe.ue.fe.delete(fe); fe.ue = null; - print(); + print(); } -global.killUE=async function(port){ - let command = `netstat -ano | findstr "${port}.*:${PORT}"` - const PID = await new Promise((res,rej)=>{ - child_process.exec(command, (err, stdout, stderr) => { - if(err)return rej(stderr) - const PID= stdout.trim().split('\n')[0].trim().split(/\s+/).pop(); - res(PID) - }) - }) - if(!PID)throw 'process ID not found' - command = `taskkill /PID ${PID} /F`; - await new Promise((res,rej)=>{ - child_process.exec(command, (err, stdout, stderr) => { - if (err) - return rej(stderr); - res(stdout.trim()); - }); - }) +global.killUE = async function (port) { + let command = `netstat -ano | findstr "${port}.*:${PORT}"` + const PID = await new Promise((res, rej) => { + child_process.exec(command, (err, stdout, stderr) => { + if (err) return rej(stderr) + const PID = stdout.trim().split('\n')[0].trim().split(/\s+/).pop(); + res(PID) + }) + }) + if (!PID) throw 'process ID not found' + command = `taskkill /PID ${PID} /F`; + await new Promise((res, rej) => { + child_process.exec(command, (err, stdout, stderr) => { + if (err) + return rej(stderr); + res(stdout.trim()); + }); + }) } \ No newline at end of file diff --git a/signal.json b/signal.json index dadf732..22677df 100644 --- a/signal.json +++ b/signal.json @@ -22,5 +22,5 @@ } ], "boot": true, - "comment": "备注\n1234" + "comment": "INVETA官网:https://inveta.cn\nGITHUB源码:https://github.com/inveta" } \ No newline at end of file