mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core: auto disconnect inactive session
This commit is contained in:
1 parent
5834c5856a
commit
0b77ed6b76
4 files changed
+11
-1
No files matched your search
@@ -32,6 +32,7 @@
|
||||
"devDependencies": {
|
||||
"@types/autocannon": "^7.6.1",
|
||||
"@types/cross-spawn": "^6.0.2",
|
||||
"@types/mocha": "^9.1.0",
|
||||
"@types/node": "^17.0.23",
|
||||
"@types/semver": "^7.3.9",
|
||||
"@types/supertest": "^2.0.12",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "3.11.12",
|
||||
"version": "3.11.13",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "src/loader",
|
||||
"module": "src/loader",
|
||||
|
||||
@@ -284,6 +284,7 @@ class RecordMainConnectionHandler extends ConnectionHandler {
|
||||
class RecordDetailConnectionHandler extends ConnectionHandler {
|
||||
cleanup: bus.Disposable = () => { };
|
||||
rid: string = '';
|
||||
disconnectTimeout: NodeJS.Timeout;
|
||||
|
||||
@param('rid', Types.ObjectID)
|
||||
async prepare(domainId: string, rid: ObjectID) {
|
||||
@@ -322,12 +323,19 @@ class RecordDetailConnectionHandler extends ConnectionHandler {
|
||||
// eslint-disable-next-line
|
||||
async onRecordChange(rdoc: RecordDoc, $set?: any, $push?: any) {
|
||||
if (rdoc._id.toString() !== this.rid) return;
|
||||
if (this.disconnectTimeout) {
|
||||
clearTimeout(this.disconnectTimeout);
|
||||
this.disconnectTimeout = null;
|
||||
}
|
||||
// TODO: frontend doesn't support incremental update
|
||||
// if ($set) this.send({ $set, $push });
|
||||
this.send({
|
||||
status_html: await this.renderHTML('record_detail_status.html', { rdoc }),
|
||||
summary_html: await this.renderHTML('record_detail_summary.html', { rdoc }),
|
||||
});
|
||||
if (![STATUS.STATUS_WAITING, STATUS.STATUS_JUDGING, STATUS.STATUS_COMPILING, STATUS.STATUS_FETCHED].includes(rdoc.status)) {
|
||||
this.disconnectTimeout = setTimeout(() => this.close(4001, 'Ended'), 10000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { NamedPage } from 'vj/misc/Page';
|
||||
|
||||
const page = new NamedPage('record_detail', async () => {
|
||||
if (!UiContext.socketUrl) return;
|
||||
const [{ default: SockJs }, { DiffDOM }] = await Promise.all([
|
||||
import('../components/socket'),
|
||||
import('diff-dom'),
|
||||
|
||||
Reference in new issue
Block a user