Home
/
browser-rts.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
0a13d92
)
track online users without async calls
author
xangelo
<git@xangelo.ca>
Tue, 7 Jun 2022 04:08:46 +0000
(
00:08
-0400)
committer
xangelo
<git@xangelo.ca>
Tue, 7 Jun 2022 04:08:46 +0000
(
00:08
-0400)
src/api.ts
patch
|
blob
|
history
diff --git
a/src/api.ts
b/src/api.ts
index 5b1edc657a5969056141dc3190231d429106e519..86b1b93b19676f86623d9728eb09c2c81c72eb80 100644
(file)
--- a/
src/api.ts
+++ b/
src/api.ts
@@
-27,6
+27,9
@@
const accountRepo = new AccountRepository();
const cityRepo = new CityRepository();
const mailRepo = new MailRepository();
const cityRepo = new CityRepository();
const mailRepo = new MailRepository();
+const cache: Record<string, any> = {
+ online_users: []
+};
const msgBuffer: string[] = [];
createBullBoard({
const msgBuffer: string[] = [];
createBullBoard({
@@
-479,11
+482,12
@@
server.post<{params: {queueId: string}}, void>('/training/:queueId/cancel', asyn
server.get<void, string>('/server-stats', async req => {
const date = new Date();
server.get<void, string>('/server-stats', async req => {
const date = new Date();
+ const min = date.getMinutes();
return `
<div class="text-right">
return `
<div class="text-right">
- <span class="success-text">${
(await server.ws.allSockets()).size
} Online</span><br>
+ <span class="success-text">${
server.ws.engine.clientsCount
} Online</span><br>
<span>
<span>
- Server Time: ${date.getHours()}:${
date.getMinutes()
}
+ Server Time: ${date.getHours()}:${
min < 10 ? '0'+min : min
}
</span>
</div>`;
});
</span>
</div>`;
});
@@
-496,6
+500,11
@@
server.ws.on('connection', async socket => {
server.ws.emit('/chat-message', renderPublicChatMessage('Server', `${acct.username} logged in`));
server.ws.emit('/chat-message', renderPublicChatMessage('Server', `${acct.username} logged in`));
+ cache.online_users.push(acct.username);
+
+ socket.on('disconnect', () => {
+ cache.online_users.splice(cache.online_users.indexOf(acct.username), 1);
+ });
});
server.start();
});
server.start();