@colyseus/monitor 0.17.7 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/ext/Room.cjs +38 -2
- package/build/ext/Room.cjs.map +2 -2
- package/build/ext/Room.mjs +38 -2
- package/build/ext/Room.mjs.map +2 -2
- package/build/index.cjs +129 -7
- package/build/index.cjs.map +3 -3
- package/build/index.d.ts +9 -4
- package/build/index.mjs +124 -7
- package/build/index.mjs.map +2 -2
- package/build/serve-static.cjs +107 -0
- package/build/serve-static.cjs.map +7 -0
- package/build/serve-static.d.ts +1 -0
- package/build/serve-static.mjs +72 -0
- package/build/serve-static.mjs.map +7 -0
- package/build/static/assets/index-BibYO4R0.js +247 -0
- package/build/static/assets/index-BibYO4R0.js.map +1 -0
- package/build/static/assets/index-C4SPBCkT.css +1 -0
- package/build/static/index.html +2 -2
- package/package.json +8 -6
- package/src-backend/ext/Room.ts +41 -2
- package/src-backend/index.ts +154 -21
- package/src-backend/serve-static.ts +73 -0
- package/README.md +0 -57
- package/build/api.cjs +0 -110
- package/build/api.cjs.map +0 -7
- package/build/api.d.ts +0 -3
- package/build/api.mjs +0 -75
- package/build/api.mjs.map +0 -7
- package/build/static/assets/index-8wRFHIxm.css +0 -1
- package/build/static/assets/index-pYihVoWY.js +0 -248
- package/build/static/assets/index-pYihVoWY.js.map +0 -1
- package/src-backend/api.ts +0 -94
package/src-backend/api.ts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { matchMaker } from '@colyseus/core';
|
|
2
|
-
|
|
3
|
-
import express from 'express';
|
|
4
|
-
import { OSUtils } from 'node-os-utils';
|
|
5
|
-
|
|
6
|
-
import type { MonitorOptions } from './index.js';
|
|
7
|
-
|
|
8
|
-
const osutils = new OSUtils();
|
|
9
|
-
|
|
10
|
-
const UNAVAILABLE_ROOM_ERROR = "@colyseus/monitor: room $roomId is not available anymore.";
|
|
11
|
-
|
|
12
|
-
export function getAPI (opts: Partial<MonitorOptions>): express.Router {
|
|
13
|
-
const api = express.Router();
|
|
14
|
-
|
|
15
|
-
api.get("/", async (req: express.Request, res: express.Response) => {
|
|
16
|
-
try {
|
|
17
|
-
const rooms: any[] = await matchMaker.query({});
|
|
18
|
-
const columns = opts.columns || ['roomId', 'name', 'clients', 'maxClients', 'locked', 'elapsedTime'];
|
|
19
|
-
|
|
20
|
-
// extend columns to expose "publicAddress", if present
|
|
21
|
-
if (!opts.columns && rooms[0] && rooms[0].publicAddress !== undefined) {
|
|
22
|
-
columns.push("publicAddress");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
let connections: number = 0;
|
|
26
|
-
|
|
27
|
-
const cpuUsage = await osutils.cpu.usage();
|
|
28
|
-
const cpu = (cpuUsage.success) ? cpuUsage.data : NaN;
|
|
29
|
-
|
|
30
|
-
const memoryInfo = await osutils.memory.info();
|
|
31
|
-
const totalMemMb = (memoryInfo.success) ? memoryInfo.data.total?.toMB() : NaN;
|
|
32
|
-
const usedMemMb = (memoryInfo.success) ? memoryInfo.data.used?.toMB() : NaN;
|
|
33
|
-
|
|
34
|
-
res.json({
|
|
35
|
-
columns,
|
|
36
|
-
rooms: rooms.map(room => {
|
|
37
|
-
const data = JSON.parse(JSON.stringify(room));
|
|
38
|
-
|
|
39
|
-
connections += room.clients;
|
|
40
|
-
|
|
41
|
-
// additional data
|
|
42
|
-
data.locked = room.locked || false;
|
|
43
|
-
data.private = room.private;
|
|
44
|
-
|
|
45
|
-
data.maxClients = `${room.maxClients}`;
|
|
46
|
-
|
|
47
|
-
data.elapsedTime = Date.now() - new Date(room.createdAt).getTime();
|
|
48
|
-
return data;
|
|
49
|
-
}),
|
|
50
|
-
|
|
51
|
-
connections,
|
|
52
|
-
cpu,
|
|
53
|
-
memory: {
|
|
54
|
-
totalMemMb,
|
|
55
|
-
usedMemMb
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
} catch (e: any) {
|
|
59
|
-
const message = e.message;
|
|
60
|
-
console.error(message);
|
|
61
|
-
res.status(500);
|
|
62
|
-
res.json({ message });
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
api.get("/room", async (req: express.Request, res: express.Response) => {
|
|
67
|
-
const roomId = req.query.roomId as string;
|
|
68
|
-
try {
|
|
69
|
-
const inspectData = await matchMaker.remoteRoomCall(roomId, "getInspectData");
|
|
70
|
-
res.json(inspectData);
|
|
71
|
-
} catch (e) {
|
|
72
|
-
const message = UNAVAILABLE_ROOM_ERROR.replace("$roomId", roomId);
|
|
73
|
-
res.status(500);
|
|
74
|
-
res.json({ message });
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
api.get("/room/call", async (req: express.Request, res: express.Response) => {
|
|
79
|
-
const roomId = req.query.roomId as string;
|
|
80
|
-
const method = req.query.method as string;
|
|
81
|
-
const args = JSON.parse(req.query.args as string);
|
|
82
|
-
|
|
83
|
-
try {
|
|
84
|
-
const data = await matchMaker.remoteRoomCall(roomId, method, args);
|
|
85
|
-
res.json(data);
|
|
86
|
-
} catch (e) {
|
|
87
|
-
const message = UNAVAILABLE_ROOM_ERROR.replace("$roomId", roomId);
|
|
88
|
-
res.status(500);
|
|
89
|
-
res.json({ message });
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
return api;
|
|
94
|
-
}
|