@colyseus/monitor 0.16.7 → 0.17.1

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.
@@ -6,8 +6,10 @@
6
6
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
7
7
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
8
8
  <title>Colyseus Stats</title>
9
- <link href="styles.css" rel="stylesheet"></head>
9
+ <script type="module" crossorigin src="./assets/index-CX4Xvsdn.js"></script>
10
+ <link rel="stylesheet" crossorigin href="./assets/index-8wRFHIxm.css">
11
+ </head>
10
12
  <body>
11
13
  <div id="app"></div>
12
- <script type="text/javascript" src="bundle.js"></script></body>
13
- </html>
14
+ </body>
15
+ </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colyseus/monitor",
3
- "version": "0.16.7",
3
+ "version": "0.17.1",
4
4
  "description": "Web Monitoring Panel for Colyseus",
5
5
  "input": "./src/index.ts",
6
6
  "main": "./build/index.js",
@@ -11,13 +11,17 @@
11
11
  "types": "./build/index.d.ts",
12
12
  "import": "./build/index.mjs",
13
13
  "require": "./build/index.js"
14
+ },
15
+ "./*": {
16
+ "types": "./build/*.d.ts",
17
+ "import": "./src-backend/*.ts",
18
+ "require": "./build/*.js"
14
19
  }
15
20
  },
16
- "scripts": {
17
- "start": "ts-node example/Server.ts",
18
- "build": "node build.mjs && NODE_OPTIONS=--openssl-legacy-provider webpack --env.production",
19
- "prepublishOnly": "node build.mjs && npm run build"
20
- },
21
+ "files": [
22
+ "build",
23
+ "src-backend"
24
+ ],
21
25
  "repository": {
22
26
  "type": "git",
23
27
  "url": "git://github.com/colyseus/colyseus.git"
@@ -37,8 +41,6 @@
37
41
  },
38
42
  "homepage": "https://github.com/colyseus/colyseus#readme",
39
43
  "devDependencies": {
40
- "@colyseus/core": "^0.16.0",
41
- "@colyseus/playground": "^0.16.0",
42
44
  "@emotion/react": "^11.11.1",
43
45
  "@emotion/styled": "^11.11.0",
44
46
  "@fontsource/roboto": "^5.0.8",
@@ -46,35 +48,29 @@
46
48
  "@mui/lab": "^5.0.0-alpha.153",
47
49
  "@mui/material": "^5.14.18",
48
50
  "@mui/x-data-grid": "^6.18.2",
49
- "@types/node-os-utils": "^1.1.0",
50
51
  "@types/react": "^18.2.38",
51
52
  "@types/react-router-dom": "^4.2.6",
52
53
  "@types/superagent": "^3.5.8",
53
- "colyseus": "^0.16.0",
54
- "css-loader": "^0.28.11",
54
+ "@vitejs/plugin-react": "^4.2.1",
55
55
  "esbuild": "^0.25.0",
56
- "extract-text-webpack-plugin": "^4.0.0-beta.0",
57
56
  "fast-glob": "^3.3.2",
58
- "file-loader": "^1.1.11",
59
57
  "history": "^5.3.0",
60
- "html-webpack-plugin": "^3.2.0",
61
58
  "react": "^18.2.0",
62
59
  "react-dom": "^18.2.0",
63
60
  "react-json-edit": "^0.3.1",
64
61
  "react-router-dom": "^4.2.2",
65
62
  "react18-json-view": "^0.2.6",
66
- "style-loader": "^0.20.3",
67
- "ts-loader": "^8.3.0",
68
- "ts-node": "^10.9.2",
69
- "typescript": "^4.9.5",
70
- "webpack": "^4.5.0",
71
- "webpack-cli": "^3.2.3",
72
- "webpack-dev-middleware": "^3.1.2",
73
- "webpack-dev-server": "^3.1.3"
63
+ "typescript": "^5.9.3",
64
+ "vite": "^5.0.11"
74
65
  },
75
66
  "dependencies": {
76
67
  "express": ">=4.16.0",
77
- "node-os-utils": "^1.2.0"
68
+ "node-os-utils": "^2.0.0",
69
+ "@colyseus/core": "^0.17.1"
78
70
  },
79
- "gitHead": "320a0325f01eff3cd7afa8fb2efa80077ebdbf4a"
80
- }
71
+ "scripts": {
72
+ "start": "vite",
73
+ "build": "vite build && node build.mjs",
74
+ "preview": "vite preview"
75
+ }
76
+ }
@@ -1,13 +1,15 @@
1
1
  import { matchMaker } from '@colyseus/core';
2
2
 
3
3
  import express from 'express';
4
- import osUtils from 'node-os-utils';
4
+ import { OSUtils } from 'node-os-utils';
5
5
 
6
6
  import type { MonitorOptions } from './index.js';
7
7
 
8
+ const osutils = new OSUtils();
9
+
8
10
  const UNAVAILABLE_ROOM_ERROR = "@colyseus/monitor: room $roomId is not available anymore.";
9
11
 
10
- export function getAPI (opts: Partial<MonitorOptions>) {
12
+ export function getAPI (opts: Partial<MonitorOptions>): express.Router {
11
13
  const api = express.Router();
12
14
 
13
15
  api.get("/", async (req: express.Request, res: express.Response) => {
@@ -22,6 +24,13 @@ export function getAPI (opts: Partial<MonitorOptions>) {
22
24
 
23
25
  let connections: number = 0;
24
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
+
25
34
  res.json({
26
35
  columns,
27
36
  rooms: rooms.map(room => {
@@ -40,10 +49,13 @@ export function getAPI (opts: Partial<MonitorOptions>) {
40
49
  }),
41
50
 
42
51
  connections,
43
- cpu: await osUtils.cpu.usage(),
44
- memory: await osUtils.mem.used()
52
+ cpu,
53
+ memory: {
54
+ totalMemMb,
55
+ usedMemMb
56
+ },
45
57
  });
46
- } catch (e) {
58
+ } catch (e: any) {
47
59
  const message = e.message;
48
60
  console.error(message);
49
61
  res.status(500);
@@ -58,7 +70,6 @@ export function getAPI (opts: Partial<MonitorOptions>) {
58
70
  res.json(inspectData);
59
71
  } catch (e) {
60
72
  const message = UNAVAILABLE_ROOM_ERROR.replace("$roomId", roomId);
61
- console.error(message);
62
73
  res.status(500);
63
74
  res.json({ message });
64
75
  }
@@ -74,7 +85,6 @@ export function getAPI (opts: Partial<MonitorOptions>) {
74
85
  res.json(data);
75
86
  } catch (e) {
76
87
  const message = UNAVAILABLE_ROOM_ERROR.replace("$roomId", roomId);
77
- console.error(message);
78
88
  res.status(500);
79
89
  res.json({ message });
80
90
  }
@@ -1,7 +1,7 @@
1
1
  //
2
2
  // Monkey-patch Colyseus' default behaviour
3
3
  //
4
- import { Room, Client, ClientPrivate } from "@colyseus/core";
4
+ import { Room, type Client, type ClientPrivate } from "@colyseus/core";
5
5
 
6
6
  function getStateSize(room) {
7
7
  // TODO: `Serializer<T>` should provide a method for this (e.g. `serializer.hasState()`)
@@ -14,7 +14,7 @@ function getStateSize(room) {
14
14
  return fullState && (fullState.byteLength || fullState.length) || 0;
15
15
  }
16
16
 
17
- (<any>Room.prototype).getAvailableData = function () {
17
+ (Room.prototype as any).getAvailableData = function () {
18
18
  return {
19
19
  clients: this.clients.length,
20
20
  maxClients: this.maxClients,
@@ -23,7 +23,7 @@ function getStateSize(room) {
23
23
  };
24
24
  };
25
25
 
26
- (<any>Room.prototype).getRoomListData = async function () {
26
+ (Room.prototype as any).getRoomListData = async function () {
27
27
  const stateSize = getStateSize(this);
28
28
  const elapsedTime = this.clock.elapsedTime;
29
29
  const locked = this.locked;
@@ -32,7 +32,7 @@ function getStateSize(room) {
32
32
  return { ...data, locked, elapsedTime, stateSize };
33
33
  };
34
34
 
35
- (<any>Room.prototype).getInspectData = async function () {
35
+ (Room.prototype as any).getInspectData = async function () {
36
36
  const state = this.state;
37
37
  const stateSize = getStateSize(this);
38
38
  const roomElapsedTime = this.clock.elapsedTime;
@@ -48,7 +48,7 @@ function getStateSize(room) {
48
48
  };
49
49
 
50
50
  // Actions
51
- (<any>Room.prototype)._forceClientDisconnect = async function (sessionId) {
51
+ (Room.prototype as any)._forceClientDisconnect = async function (sessionId) {
52
52
  for (let i = 0; i < this.clients.length; i++) {
53
53
  if (this.clients[i].sessionId === sessionId) {
54
54
  this.clients[i].leave();
@@ -57,7 +57,7 @@ function getStateSize(room) {
57
57
  }
58
58
  };
59
59
 
60
- (<any>Room.prototype)._sendMessageToClient = async function (sessionId, type, data) {
60
+ (Room.prototype as any)._sendMessageToClient = async function (sessionId, type, data) {
61
61
  for (let i = 0; i < this.clients.length; i++) {
62
62
  if (this.clients[i].sessionId === sessionId) {
63
63
  this.clients[i].send(type, data);
@@ -23,9 +23,6 @@ export interface MonitorOptions {
23
23
  >
24
24
  }
25
25
 
26
- /**
27
- * TODO: expose the `router` instead on next major version.
28
- */
29
26
  export function monitor (opts: Partial<MonitorOptions> = {}): express.Router {
30
27
  const router = express.Router();
31
28
  router.use(express.static(frontendDirectory));
package/.editorconfig DELETED
@@ -1,6 +0,0 @@
1
- [*]
2
- end_of_line = lf
3
- charset = utf-8
4
- trim_trailing_whitespace = true
5
- indent_style = space
6
- indent_size = 2
@@ -1,2 +0,0 @@
1
- import React from "react";
2
- export declare function App(): React.JSX.Element;
@@ -1,8 +0,0 @@
1
- import * as React from "react";
2
- export declare class CAppBar extends React.Component {
3
- state: {
4
- open: boolean;
5
- };
6
- handleToggle: () => void;
7
- render(): React.JSX.Element;
8
- }
@@ -1,40 +0,0 @@
1
- import * as React from "react";
2
- import 'react18-json-view/src/style.css';
3
- interface Props {
4
- }
5
- interface State {
6
- roomId?: string;
7
- state: any;
8
- clients: Array<{
9
- sessionId: string;
10
- elapsedTime: number;
11
- }>;
12
- maxClients: number;
13
- stateSize: number;
14
- locked: boolean;
15
- currentTab: string;
16
- sendDialogTitle: string;
17
- sendDialogOpen: boolean;
18
- sendToClient?: any;
19
- sendType: string;
20
- sendData: string;
21
- }
22
- export declare class RoomInspect extends React.Component<Props, State> {
23
- state: State;
24
- updateDataInterval: number;
25
- componentDidMount(): void;
26
- fetchRoomData(): void;
27
- roomCall(method: string, ...args: any[]): Promise<void>;
28
- componentWillUnmount(): void;
29
- sendMessage(sessionId?: string): void;
30
- disconnectClient(sessionId: string): void;
31
- disposeRoom(): void;
32
- updateSendType: (e: any) => void;
33
- updateSendData: (changes: any) => void;
34
- handleCloseSend: () => void;
35
- handleSend: () => void;
36
- goBack(): void;
37
- handleTabChange: (event: React.SyntheticEvent, newValue: string) => void;
38
- render(): React.JSX.Element;
39
- }
40
- export {};
@@ -1,30 +0,0 @@
1
- import * as React from "react";
2
- import { GridColDef } from '@mui/x-data-grid';
3
- export declare class RoomList extends React.Component {
4
- state: {
5
- selected: number[];
6
- rooms: any[];
7
- connections: number;
8
- cpu: number;
9
- memory: {
10
- totalMemMb: number;
11
- usedMemMb: number;
12
- };
13
- columns: any[];
14
- };
15
- updateRoomListInterval: number;
16
- isSelected: (index: any) => boolean;
17
- componentWillMount(): void;
18
- componentWillUnmount(): void;
19
- fetchRoomList(): Promise<void>;
20
- handleRowSelection: (selectedRows: any) => void;
21
- inspectRoom(roomId: any): void;
22
- disposeRoom(roomId: any): Promise<void>;
23
- getColumnHeader(column: any): any;
24
- getRoomColumn(room: any, column: any): any;
25
- bytesToStr(size: number): string;
26
- getColumnsNames(columns: any): Array<GridColDef>;
27
- getRowsData(rooms: any): Array<any>;
28
- generateRoomListDataGrid(): JSX.Element;
29
- render(): React.JSX.Element;
30
- }
@@ -1,6 +0,0 @@
1
- import type { MonitorOptions } from "../../";
2
- export type ExtractStringNames<T> = T extends (infer U)[] ? U extends string ? U : never : never;
3
- export declare const valueFormatter: {
4
- [key in ExtractStringNames<MonitorOptions['columns']>]?: Function;
5
- };
6
- export declare function humanizeElapsedTime(milliseconds: number): string;
@@ -1 +0,0 @@
1
- import "./css/index.css";
@@ -1,3 +0,0 @@
1
- export declare function fetchRoomList(): Promise<any>;
2
- export declare function fetchRoomData(roomId: string): Promise<any>;
3
- export declare function remoteRoomCall(roomId: string, method: string, ...args: any[]): Promise<any>;
@@ -1,2 +0,0 @@
1
- import type { MonitorOptions } from './index.js';
2
- export declare function getAPI(opts: Partial<MonitorOptions>): any;
@@ -1 +0,0 @@
1
- export {};
@@ -1,11 +0,0 @@
1
- import express from 'express';
2
- import './ext/Room.js';
3
- export interface MonitorOptions {
4
- columns: Array<'roomId' | 'name' | 'clients' | 'maxClients' | 'locked' | 'elapsedTime' | {
5
- metadata: string;
6
- } | 'processId' | "publicAddress">;
7
- }
8
- /**
9
- * TODO: expose the `router` instead on next major version.
10
- */
11
- export declare function monitor(opts?: Partial<MonitorOptions>): express.Router;