From eedf717f10124f6c8b71068438d76096ac742067 Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Sat, 16 Dec 2023 09:28:50 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E6=9C=89=E6=97=A7?= =?UTF-8?q?=E4=BC=9A=E8=AF=9D=E4=BF=A1=E6=81=AF=E6=97=B6=EF=BC=8C=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=87=AA=E5=8A=A8=E9=87=8D=E7=BD=AE=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/Web/communication.js | 15 --------------- frontend/Web/index.html | 2 ++ frontend/Web/index.js | 3 +++ frontend/Web/login.html | 1 + frontend/Web/passwd.html | 1 + frontend/Web/register.html | 1 + frontend/Web/sessioninit.js | 15 +++++++++++++++ 7 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 frontend/Web/sessioninit.js diff --git a/frontend/Web/communication.js b/frontend/Web/communication.js index 15369a9..4fcf21e 100644 --- a/frontend/Web/communication.js +++ b/frontend/Web/communication.js @@ -70,21 +70,6 @@ async function Request(req) return response; } -var SessionReadyEvent = new Event('SessionReady'); -(async () => { - if(session_token==null||outhentication_key==null||operation_count==null){ - let tmp_channel=generateRandomString(10); - let ret=await RawRequest('#OpenSession '+tmp_channel); - operation_count=0; - session_token=ret.split('\n')[1].split(' ')[0]; - outhentication_key=ret.split('\n')[1].split(' ')[1]; - localStorage.setItem("session_token", session_token); - localStorage.setItem("outhentication_key", outhentication_key); - localStorage.setItem("operation_count", operation_count); - document.dispatchEvent(SessionReadyEvent); - } -})(); - async function GetMyName() { session_token=localStorage.getItem("session_token"); diff --git a/frontend/Web/index.html b/frontend/Web/index.html index e9fdeea..b3abc37 100644 --- a/frontend/Web/index.html +++ b/frontend/Web/index.html @@ -195,8 +195,10 @@ } } document.addEventListener('SessionReady', async () => { + console.log("receive event session ready"); await UpdateUserInfo(); }); + \ No newline at end of file diff --git a/frontend/Web/index.js b/frontend/Web/index.js index c45caf3..3ac8ac6 100644 --- a/frontend/Web/index.js +++ b/frontend/Web/index.js @@ -106,6 +106,9 @@ app.get('/', (req, res) => { app.get('/communication.js', (req, res) => { res.sendFile(join(__dirname, 'communication.js')); }); +app.get('/sessioninit.js', (req, res) => { + res.sendFile(join(__dirname, 'sessioninit.js')); +}); io.on('connection', async (socket) => { console.log('a user connected'); diff --git a/frontend/Web/login.html b/frontend/Web/login.html index fc4c74c..b2cfe36 100644 --- a/frontend/Web/login.html +++ b/frontend/Web/login.html @@ -257,5 +257,6 @@ } } + \ No newline at end of file diff --git a/frontend/Web/passwd.html b/frontend/Web/passwd.html index 97a409a..ada0800 100644 --- a/frontend/Web/passwd.html +++ b/frontend/Web/passwd.html @@ -269,5 +269,6 @@ } })(); + \ No newline at end of file diff --git a/frontend/Web/register.html b/frontend/Web/register.html index 0f95f56..7d19af4 100644 --- a/frontend/Web/register.html +++ b/frontend/Web/register.html @@ -261,5 +261,6 @@ } } + \ No newline at end of file diff --git a/frontend/Web/sessioninit.js b/frontend/Web/sessioninit.js new file mode 100644 index 0000000..65955e4 --- /dev/null +++ b/frontend/Web/sessioninit.js @@ -0,0 +1,15 @@ +var SessionReadyEvent = new Event('SessionReady'); +(async () => { + if(session_token==null||outhentication_key==null||operation_count==null){ + let tmp_channel=generateRandomString(10); + let ret=await RawRequest('#OpenSession '+tmp_channel); + operation_count=0; + session_token=ret.split('\n')[1].split(' ')[0]; + outhentication_key=ret.split('\n')[1].split(' ')[1]; + localStorage.setItem("session_token", session_token); + localStorage.setItem("outhentication_key", outhentication_key); + localStorage.setItem("operation_count", operation_count); + } + document.dispatchEvent(SessionReadyEvent); + console.log("Sent event Session Ready"); +})(); \ No newline at end of file