Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
xosg committed Jan 19, 2024
1 parent c306a12 commit 61927e0
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 70 deletions.
79 changes: 39 additions & 40 deletions signal.html
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@
></a>
<checkUpdate
class="sidebarBtn"
data-normal="🔍 检查更新 1.16"
data-normal="🔍 检查更新 1.17"
data-mini="🔍"
onclick="handleCheckUpdate()"
></checkUpdate>
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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 });
Expand All @@ -936,13 +912,13 @@
logs = logs
.map(
(a) => `
<tr>
<td>${a.type}</td>
<td>${a.address}</td>
<td>${a.PORT}</td>
<td>${a.path}</td>
<td>断开</td>
</tr> `
<tr>
<td>${a.type}</td>
<td>${a.address}</td>
<td>${a.PORT}</td>
<td>${a.path}</td>
<td>断开</td>
</tr> `
)
.join("");
$("table tbody").innerHTML = logs;
Expand All @@ -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})`,
};
Expand All @@ -975,9 +951,7 @@
if (!r.ok) throw r.headers.get("error");
handleUpdateSuccess($(`#process`));
})
.catch((err) => {
alert(err);
});
.catch((error) => alert(error));
}
}

Expand Down Expand Up @@ -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: {
}
}
};
</script>
</body>
Expand Down
64 changes: 35 additions & 29 deletions signal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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);
Expand Down Expand Up @@ -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());
});
})
}
2 changes: 1 addition & 1 deletion signal.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
}
],
"boot": true,
"comment": "备注\n1234"
"comment": "INVETA官网:https://inveta.cn\nGITHUB源码:https://github.com/inveta"
}

0 comments on commit 61927e0

Please sign in to comment.