@colyseus/monitor 0.16.7 → 0.17.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.
Files changed (42) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +1 -3
  3. package/build/api.d.ts +2 -1
  4. package/build/api.js +13 -5
  5. package/build/api.js.map +3 -3
  6. package/build/api.mjs +12 -5
  7. package/build/api.mjs.map +2 -2
  8. package/build/ext/Room.js.map +2 -2
  9. package/build/ext/Room.mjs.map +2 -2
  10. package/build/index.d.ts +0 -3
  11. package/build/index.js.map +2 -2
  12. package/build/index.mjs.map +2 -2
  13. package/build/static/assets/index-8wRFHIxm.css +1 -0
  14. package/build/static/assets/index-B2aU-jt1.js +248 -0
  15. package/build/static/assets/index-B2aU-jt1.js.map +1 -0
  16. package/build/static/index.html +5 -3
  17. package/build.mjs +2 -4
  18. package/index.html +14 -0
  19. package/package.json +17 -25
  20. package/src-backend/api.ts +17 -7
  21. package/src-backend/ext/Room.ts +6 -6
  22. package/src-backend/index.ts +0 -3
  23. package/tsconfig.backend.json +16 -0
  24. package/tsconfig.json +10 -6
  25. package/tsconfig.node.json +10 -0
  26. package/vite.config.ts +26 -0
  27. package/.editorconfig +0 -6
  28. package/build/src/App.d.ts +0 -2
  29. package/build/src/components/CAppBar.d.ts +0 -8
  30. package/build/src/components/RoomInspect.d.ts +0 -40
  31. package/build/src/components/RoomList.d.ts +0 -30
  32. package/build/src/helpers/helpers.d.ts +0 -6
  33. package/build/src/index.d.ts +0 -1
  34. package/build/src/services.d.ts +0 -3
  35. package/build/src-backend/api.d.ts +0 -2
  36. package/build/src-backend/ext/Room.d.ts +0 -1
  37. package/build/src-backend/index.d.ts +0 -11
  38. package/build/static/bundle.js +0 -279
  39. package/build/static/bundle.js.map +0 -1
  40. package/build/static/styles.css +0 -153
  41. package/build/static/styles.css.map +0 -1
  42. package/webpack.config.js +0 -52
@@ -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-B2aU-jt1.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/build.mjs CHANGED
@@ -11,7 +11,6 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
11
11
  async function main() {
12
12
  // Absolute path to package directory
13
13
  const basePath = __dirname;
14
- const target = "es2017";
15
14
 
16
15
  // Get all .ts as input files
17
16
  const entryPoints = glob.sync(path.resolve(basePath, "src-backend", "**", "**.ts")
@@ -26,8 +25,8 @@ async function main() {
26
25
  declaration: true,
27
26
  emitDeclarationOnly: true,
28
27
  skipLibCheck: true,
29
- module: "commonjs",
30
- target,
28
+ module: ts.ModuleKind.CommonJS,
29
+ target: ts.ScriptTarget.ES2017,
31
30
  outDir: outdir,
32
31
  esModuleInterop: true,
33
32
  experimentalDecorators: true,
@@ -54,7 +53,6 @@ async function main() {
54
53
  esbuild.build({
55
54
  entryPoints,
56
55
  outdir,
57
- target,
58
56
  format: "cjs",
59
57
  target: "es2017",
60
58
  sourcemap: "external",
package/index.html ADDED
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
7
+ <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
8
+ <title>Colyseus Stats</title>
9
+ </head>
10
+ <body>
11
+ <div id="app"></div>
12
+ <script type="module" src="/src/index.tsx"></script>
13
+ </body>
14
+ </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.0",
4
4
  "description": "Web Monitoring Panel for Colyseus",
5
5
  "input": "./src/index.ts",
6
6
  "main": "./build/index.js",
@@ -11,13 +11,13 @@
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
21
  "repository": {
22
22
  "type": "git",
23
23
  "url": "git://github.com/colyseus/colyseus.git"
@@ -37,8 +37,6 @@
37
37
  },
38
38
  "homepage": "https://github.com/colyseus/colyseus#readme",
39
39
  "devDependencies": {
40
- "@colyseus/core": "^0.16.0",
41
- "@colyseus/playground": "^0.16.0",
42
40
  "@emotion/react": "^11.11.1",
43
41
  "@emotion/styled": "^11.11.0",
44
42
  "@fontsource/roboto": "^5.0.8",
@@ -46,35 +44,29 @@
46
44
  "@mui/lab": "^5.0.0-alpha.153",
47
45
  "@mui/material": "^5.14.18",
48
46
  "@mui/x-data-grid": "^6.18.2",
49
- "@types/node-os-utils": "^1.1.0",
50
47
  "@types/react": "^18.2.38",
51
48
  "@types/react-router-dom": "^4.2.6",
52
49
  "@types/superagent": "^3.5.8",
53
- "colyseus": "^0.16.0",
54
- "css-loader": "^0.28.11",
50
+ "@vitejs/plugin-react": "^4.2.1",
55
51
  "esbuild": "^0.25.0",
56
- "extract-text-webpack-plugin": "^4.0.0-beta.0",
57
52
  "fast-glob": "^3.3.2",
58
- "file-loader": "^1.1.11",
59
53
  "history": "^5.3.0",
60
- "html-webpack-plugin": "^3.2.0",
61
54
  "react": "^18.2.0",
62
55
  "react-dom": "^18.2.0",
63
56
  "react-json-edit": "^0.3.1",
64
57
  "react-router-dom": "^4.2.2",
65
58
  "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"
59
+ "typescript": "^5.9.3",
60
+ "vite": "^5.0.11"
74
61
  },
75
62
  "dependencies": {
76
63
  "express": ">=4.16.0",
77
- "node-os-utils": "^1.2.0"
64
+ "node-os-utils": "^2.0.0",
65
+ "@colyseus/core": "^0.17.0"
78
66
  },
79
- "gitHead": "320a0325f01eff3cd7afa8fb2efa80077ebdbf4a"
80
- }
67
+ "scripts": {
68
+ "start": "vite",
69
+ "build": "vite build && node build.mjs",
70
+ "preview": "vite preview"
71
+ }
72
+ }
@@ -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));
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "build",
4
+ "module": "commonjs",
5
+ "lib": ["ES2022"],
6
+ "target": "es2017",
7
+ "declaration": true,
8
+ "noImplicitAny": false,
9
+ "esModuleInterop": true,
10
+ "experimentalDecorators": true,
11
+ "skipLibCheck": true
12
+ },
13
+ "include": [
14
+ "src-backend/**/*.ts"
15
+ ]
16
+ }
package/tsconfig.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "outDir": "build",
4
- "module": "commonjs",
4
+ "module": "ESNext",
5
5
  "lib": ["ES2022", "DOM"],
6
6
  "target": "ES2022",
7
7
  "declaration": true,
@@ -11,12 +11,16 @@
11
11
  "useDefineForClassFields": false,
12
12
  "sourceMap": false,
13
13
  "skipLibCheck": true,
14
- "jsx": "react"
14
+ "jsx": "react-jsx",
15
+ "moduleResolution": "bundler",
16
+ "resolveJsonModule": true,
17
+ "isolatedModules": true,
18
+ "noEmit": true
15
19
  },
16
20
  "include": [
17
- "src-backend/**/*.ts"
21
+ "src/**/*.ts",
22
+ "src/**/*.tsx",
23
+ "src-backend/**/*.ts",
18
24
  ],
19
- "exclude": [
20
- "src/**"
21
- ]
25
+ "references": [{ "path": "./tsconfig.node.json" }]
22
26
  }
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "skipLibCheck": true,
5
+ "module": "ESNext",
6
+ "moduleResolution": "bundler",
7
+ "allowSyntheticDefaultImports": true
8
+ },
9
+ "include": ["vite.config.ts"]
10
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { defineConfig } from 'vite';
2
+ import react from '@vitejs/plugin-react';
3
+ import path from 'path';
4
+
5
+ // https://vitejs.dev/config/
6
+ export default defineConfig({
7
+ plugins: [react()],
8
+ base: './',
9
+ server: {
10
+ port: 3000,
11
+ open: true,
12
+ },
13
+ build: {
14
+ outDir: 'build/static',
15
+ sourcemap: true,
16
+ },
17
+ define: {
18
+ 'process.env.npm_package_version': JSON.stringify(process.env.npm_package_version || '0.17.0'),
19
+ },
20
+ resolve: {
21
+ extensions: ['.ts', '.tsx', '.js', '.json'],
22
+ },
23
+ optimizeDeps: {
24
+ include: ['react', 'react-dom', 'react-router-dom'],
25
+ },
26
+ });
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;