auto delete on inactivity
This commit is contained in:
parent
586cb1738c
commit
5980709885
@ -1,11 +1,11 @@
|
|||||||
// Global networking variables
|
// Global networking variables
|
||||||
let pretext = {
|
const pretext = {
|
||||||
original: "root@baipyr.us:~# ",
|
original: "root@baipyr.us:~# ",
|
||||||
current: "root@baipyr.us:~# "
|
current: "root@baipyr.us:~# "
|
||||||
};
|
};
|
||||||
|
|
||||||
const userData = { history: [], chatPull: null };
|
const userData = { history: [], chatPull: null };
|
||||||
let chatMode = "default";
|
let chatMode = "default", activityNotify;
|
||||||
|
|
||||||
if (window.localStorage.getItem("id") === null)
|
if (window.localStorage.getItem("id") === null)
|
||||||
window.localStorage.setItem("id", "");
|
window.localStorage.setItem("id", "");
|
||||||
@ -13,9 +13,53 @@ if (window.localStorage.getItem("name") === null)
|
|||||||
window.localStorage.setItem("name", "");
|
window.localStorage.setItem("name", "");
|
||||||
if (window.localStorage.getItem("connected") === null)
|
if (window.localStorage.getItem("connected") === null)
|
||||||
window.localStorage.setItem("connected", "");
|
window.localStorage.setItem("connected", "");
|
||||||
else if (!!window.localStorage.getItem("connected"))
|
|
||||||
|
function setNotification() {
|
||||||
|
return setInterval(()=>{
|
||||||
|
fetch('/activity', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
name: window.localStorage.getItem("name"),
|
||||||
|
id: window.localStorage.getItem("id")
|
||||||
|
})
|
||||||
|
}).then(res => {});
|
||||||
|
}, 60000);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window.localStorage.getItem("id") !== "" && window.localStorage.getItem("name") !== "") {
|
||||||
pretext.original = pretext.current = `${window.localStorage.getItem("name")}@baipyr.us:~# `;
|
pretext.original = pretext.current = `${window.localStorage.getItem("name")}@baipyr.us:~# `;
|
||||||
|
|
||||||
|
fetch('/login', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
name: window.localStorage.getItem("name"),
|
||||||
|
id: window.localStorage.getItem("id")
|
||||||
|
})
|
||||||
|
}).then(res => {
|
||||||
|
if (res.status === 200)
|
||||||
|
return res.json();
|
||||||
|
}).then(res => {
|
||||||
|
if (res === undefined)
|
||||||
|
return;
|
||||||
|
if (res.success)
|
||||||
|
activityNotify = setNotification();
|
||||||
|
else {
|
||||||
|
window.localStorage.setItem("id", "");
|
||||||
|
window.localStorage.setItem("name", "");
|
||||||
|
window.localStorage.setItem("connected", "");
|
||||||
|
pretext.original = pretext.current = "root@baipyr.us:~# ";
|
||||||
|
cmd_clear();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Tell server to disconnect
|
// Tell server to disconnect
|
||||||
function disconnect() {
|
function disconnect() {
|
||||||
@ -23,7 +67,6 @@ function disconnect() {
|
|||||||
fetch('/disconnect', {
|
fetch('/disconnect', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'application/json',
|
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
@ -50,6 +93,7 @@ function connect(name) {
|
|||||||
body: JSON.stringify({ name })
|
body: JSON.stringify({ name })
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
|
activityNotify = setNotification();
|
||||||
window.localStorage.setItem("connected", "1");
|
window.localStorage.setItem("connected", "1");
|
||||||
return res.json();
|
return res.json();
|
||||||
}
|
}
|
||||||
@ -137,7 +181,6 @@ function directMessage(name, message) {
|
|||||||
fetch('/message', {
|
fetch('/message', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'application/json',
|
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
@ -174,7 +217,12 @@ function requestUsernames() {
|
|||||||
// Ping host for two-way-delay
|
// Ping host for two-way-delay
|
||||||
function requestPing() {
|
function requestPing() {
|
||||||
const startTime = new Date();
|
const startTime = new Date();
|
||||||
fetch('/ping').then(res => {
|
fetch('/ping', {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
}
|
||||||
|
}).then(res => {
|
||||||
if (res.status !== 200)
|
if (res.status !== 200)
|
||||||
return;
|
return;
|
||||||
const diff = new Date() - startTime;
|
const diff = new Date() - startTime;
|
||||||
|
Loading…
Reference in New Issue
Block a user