iosignal 9.13.0 → 9.14.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.
@@ -6,6 +6,8 @@ import { EventEmitter } from 'eventemitter3';
6
6
  import * as stream from 'stream';
7
7
  import { Transform } from 'stream';
8
8
  import EventEmitter$1 from 'events';
9
+ import * as perf_hooks from 'perf_hooks';
10
+ import http from 'http';
9
11
  export { default as MBP } from 'meta-buffer-pack';
10
12
 
11
13
  type STATE = {
@@ -686,6 +688,25 @@ declare class Host extends EventEmitter$1<[never]> {
686
688
  closed: boolean;
687
689
  /** @type {Map<string, Readonly<object>>} cid -> from, connections that sent to this host */
688
690
  _participants: Map<string, Readonly<object>>;
691
+ /** cid -> { inputs, firstAt, lastAt }: activity of each participant, for the dashboard */
692
+ _activity: Map<any, any>;
693
+ counters: {
694
+ inbound: number;
695
+ rejected: number;
696
+ denied: number;
697
+ published: number;
698
+ delivered: number;
699
+ sent: number;
700
+ joins: number;
701
+ leaves: number;
702
+ errors: number;
703
+ handlerMs: number;
704
+ };
705
+ handlerMaxMs: number;
706
+ reported: {};
707
+ _journal: any[];
708
+ _journalSeq: number;
709
+ _loops: Set<any>;
689
710
  /** Connections that have sent to this host and are still online: cid -> from. */
690
711
  get participants(): Map<string, object>;
691
712
  /** Stop tracking a participant; no 'leave' is emitted for it (until it sends again). */
@@ -700,6 +721,35 @@ declare class Host extends EventEmitter$1<[never]> {
700
721
  * or its receive buffer is too small for the message.
701
722
  */
702
723
  to(cid: any, topic: any, ...args: any[]): boolean;
724
+ /**
725
+ * Values to show on the server dashboard ("game" panel), e.g. { round: 3, players: 8 }.
726
+ * Merged into the last report; a key set to null is removed. Numbers, short strings and booleans,
727
+ * at most 20 keys.
728
+ */
729
+ report(values: any): this;
730
+ /**
731
+ * Run fn(now) every intervalMs, like setInterval, and measure it for the dashboard: the gap between
732
+ * ticks and how long each tick took. A throwing tick is reported as an 'error' and the loop goes on.
733
+ * Returns a stop function; close() stops every loop.
734
+ */
735
+ loop(intervalMs: any, fn: any): () => void;
736
+ /** Timing of the loops started with loop(): target, ticks, gap p50/p99 and step average/max (ms). */
737
+ loopStats(): {
738
+ intervalMs: any;
739
+ ticks: any;
740
+ gapP50: any;
741
+ gapP99: any;
742
+ gapMax: number;
743
+ stepAvg: number;
744
+ stepMax: number;
745
+ }[];
746
+ /** Participants with their activity: [{ from, inputs, firstAt, lastAt }]. */
747
+ activity(): any[];
748
+ /** Notable events after sequence `after`: [{ seq, at, kind: 'join'|'leave'|'denied'|'error', ... }]. */
749
+ journal(after?: number): any[];
750
+ _note(kind: any, data: any): void;
751
+ _denied(remote: any, tag: any): void;
752
+ _failed(error: any): void;
703
753
  /** Release the tags (they become ordinary channels again) and the host's retained values. */
704
754
  close(): void;
705
755
  _open(): void;
@@ -936,6 +986,135 @@ declare class Manager {
936
986
  close(): void;
937
987
  }
938
988
 
989
+ declare class ServerStats {
990
+ constructor(server: any, { onSample }?: {
991
+ onSample?: null | undefined;
992
+ });
993
+ server: any;
994
+ onSample: any;
995
+ base: any;
996
+ counters: {
997
+ opened: number;
998
+ closed: number;
999
+ authFailed: number;
1000
+ };
1001
+ onState: (_peer: any, _previous: any) => void;
1002
+ delay: perf_hooks.IntervalHistogram;
1003
+ cpu: NodeJS.CpuUsage;
1004
+ elu: perf_hooks.EventLoopUtilization;
1005
+ previousAt: number;
1006
+ previous: {
1007
+ opened: number;
1008
+ closed: number;
1009
+ authFailed: number;
1010
+ };
1011
+ timer: NodeJS.Timeout;
1012
+ sample(): void;
1013
+ value: {
1014
+ at: number;
1015
+ total: any;
1016
+ authenticated: number;
1017
+ anonymous: number;
1018
+ websocket: number;
1019
+ transports: {
1020
+ websocket: {
1021
+ total: number;
1022
+ authenticated: number;
1023
+ };
1024
+ tcp: {
1025
+ total: number;
1026
+ authenticated: number;
1027
+ };
1028
+ };
1029
+ hostAvailableBytes: number | null;
1030
+ hostTotalBytes: number;
1031
+ channels: any;
1032
+ states: {};
1033
+ queuedBytes: number;
1034
+ maxQueuedBytes: number;
1035
+ txQueuePeakBytes: number;
1036
+ txWriteFalseCount: number;
1037
+ txDrainMaxMs: number;
1038
+ txBlockedConnections: number;
1039
+ txBlockedMaxMs: number;
1040
+ counters: {
1041
+ opened: number;
1042
+ closed: number;
1043
+ authFailed: number;
1044
+ };
1045
+ rates: {
1046
+ [k: string]: number;
1047
+ };
1048
+ rss: number;
1049
+ heapUsed: number;
1050
+ cpuPercent: number;
1051
+ eventLoopUtilization: number;
1052
+ eventLoopP99Ms: number;
1053
+ quota: {
1054
+ anonymous: any;
1055
+ profiles: any;
1056
+ };
1057
+ } | undefined;
1058
+ dispose(): void;
1059
+ }
1060
+
1061
+ /**
1062
+ * The server dashboard: a web page (options.path) that shows the server and its hosts live.
1063
+ * It talks to the page through IOSignal itself: viewers send 'hello' to DASHBOARD.IN, a host checks
1064
+ * access, and every second it sends the latest sample to each viewer with host.to().
1065
+ *
1066
+ * options (all optional):
1067
+ * path: '/dashboard'
1068
+ * access: 'open' | { token: '...' } | { login: { roles: ['admin'], cids: [] } }
1069
+ * panels: panels shown first (DASHBOARD_PANELS); viewers can switch them
1070
+ * history: seconds kept for the charts (default 300, 10-3600)
1071
+ * maxViewers: default 20
1072
+ * showIdentities: show participant CIDs and names (default: true unless access is 'open')
1073
+ */
1074
+ declare class Dashboard {
1075
+ constructor(server: any, options?: {});
1076
+ path: string;
1077
+ access: {
1078
+ mode: string;
1079
+ hash?: undefined;
1080
+ roles?: undefined;
1081
+ cids?: undefined;
1082
+ } | {
1083
+ mode: string;
1084
+ hash: NonSharedBuffer;
1085
+ roles?: undefined;
1086
+ cids?: undefined;
1087
+ } | {
1088
+ mode: string;
1089
+ roles: any[];
1090
+ cids: Set<any>;
1091
+ hash?: undefined;
1092
+ };
1093
+ panels: any[];
1094
+ history: any;
1095
+ maxViewers: any;
1096
+ showIdentities: any;
1097
+ server: any;
1098
+ startedAt: number;
1099
+ viewers: Map<any, any>;
1100
+ series: any[];
1101
+ lastHostCounters: Map<any, any>;
1102
+ lastJournal: Map<any, any>;
1103
+ events: any[];
1104
+ host: any;
1105
+ stats: ServerStats;
1106
+ /** Whether this viewer (the server's view of it) may watch. */
1107
+ allowed(from: any, msg: any): boolean;
1108
+ /**
1109
+ * Serves the page (GET path) and the browser client (path + '/io.js'). Returns true when it
1110
+ * answered. A Server with `port` calls it itself; with your own httpServer call it first in
1111
+ * your request handler: if (server.dashboard.handle(req, res)) return
1112
+ */
1113
+ handle(req: any, res: any): boolean;
1114
+ close(): void;
1115
+ #private;
1116
+ }
1117
+
939
1118
  declare class Server extends EventEmitter$1<[never]> {
940
1119
  /**
941
1120
  * @param {object} options Server configuration.
@@ -962,6 +1141,9 @@ declare class Server extends EventEmitter$1<[never]> {
962
1141
  * options.anonymousQuota: profile of a connection that has not authenticated (default 'anonymous').
963
1142
  * options.duplicateLogin: 'keepOld' | 'keepNew' for this Server's connections; overrides the auth
964
1143
  * manager's own policy without changing it, so an auth manager can be shared between servers.
1144
+ * options.dashboard: true or { path, access, panels, history, maxViewers, showIdentities } shows a live
1145
+ * status page of the server and its hosts (see Dashboard.js); off by default. With `port` the Server
1146
+ * serves it itself; with your own httpServer call server.dashboard.handle(req, res) in its handler.
965
1147
  * A failed listen (e.g. EADDRINUSE) is emitted as 'error'.
966
1148
  * @param {any} [authManager] Optional authentication manager.
967
1149
  */
@@ -988,9 +1170,11 @@ declare class Server extends EventEmitter$1<[never]> {
988
1170
  httpServer: any;
989
1171
  wsPath: any;
990
1172
  manager: Manager;
1173
+ dashboard: Dashboard | null;
991
1174
  serverCountToListen: number;
992
1175
  listeningServerCount: number;
993
1176
  startWSServer(): void;
1177
+ ownHttp: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse> | undefined;
994
1178
  startCongServer(): void;
995
1179
  congServer: any;
996
1180
  onListenerError(name: any, err: any): void;
@@ -6,6 +6,8 @@ import { EventEmitter } from 'eventemitter3';
6
6
  import * as stream from 'stream';
7
7
  import { Transform } from 'stream';
8
8
  import EventEmitter$1 from 'events';
9
+ import * as perf_hooks from 'perf_hooks';
10
+ import http from 'http';
9
11
  export { default as MBP } from 'meta-buffer-pack';
10
12
 
11
13
  type STATE = {
@@ -686,6 +688,25 @@ declare class Host extends EventEmitter$1<[never]> {
686
688
  closed: boolean;
687
689
  /** @type {Map<string, Readonly<object>>} cid -> from, connections that sent to this host */
688
690
  _participants: Map<string, Readonly<object>>;
691
+ /** cid -> { inputs, firstAt, lastAt }: activity of each participant, for the dashboard */
692
+ _activity: Map<any, any>;
693
+ counters: {
694
+ inbound: number;
695
+ rejected: number;
696
+ denied: number;
697
+ published: number;
698
+ delivered: number;
699
+ sent: number;
700
+ joins: number;
701
+ leaves: number;
702
+ errors: number;
703
+ handlerMs: number;
704
+ };
705
+ handlerMaxMs: number;
706
+ reported: {};
707
+ _journal: any[];
708
+ _journalSeq: number;
709
+ _loops: Set<any>;
689
710
  /** Connections that have sent to this host and are still online: cid -> from. */
690
711
  get participants(): Map<string, object>;
691
712
  /** Stop tracking a participant; no 'leave' is emitted for it (until it sends again). */
@@ -700,6 +721,35 @@ declare class Host extends EventEmitter$1<[never]> {
700
721
  * or its receive buffer is too small for the message.
701
722
  */
702
723
  to(cid: any, topic: any, ...args: any[]): boolean;
724
+ /**
725
+ * Values to show on the server dashboard ("game" panel), e.g. { round: 3, players: 8 }.
726
+ * Merged into the last report; a key set to null is removed. Numbers, short strings and booleans,
727
+ * at most 20 keys.
728
+ */
729
+ report(values: any): this;
730
+ /**
731
+ * Run fn(now) every intervalMs, like setInterval, and measure it for the dashboard: the gap between
732
+ * ticks and how long each tick took. A throwing tick is reported as an 'error' and the loop goes on.
733
+ * Returns a stop function; close() stops every loop.
734
+ */
735
+ loop(intervalMs: any, fn: any): () => void;
736
+ /** Timing of the loops started with loop(): target, ticks, gap p50/p99 and step average/max (ms). */
737
+ loopStats(): {
738
+ intervalMs: any;
739
+ ticks: any;
740
+ gapP50: any;
741
+ gapP99: any;
742
+ gapMax: number;
743
+ stepAvg: number;
744
+ stepMax: number;
745
+ }[];
746
+ /** Participants with their activity: [{ from, inputs, firstAt, lastAt }]. */
747
+ activity(): any[];
748
+ /** Notable events after sequence `after`: [{ seq, at, kind: 'join'|'leave'|'denied'|'error', ... }]. */
749
+ journal(after?: number): any[];
750
+ _note(kind: any, data: any): void;
751
+ _denied(remote: any, tag: any): void;
752
+ _failed(error: any): void;
703
753
  /** Release the tags (they become ordinary channels again) and the host's retained values. */
704
754
  close(): void;
705
755
  _open(): void;
@@ -936,6 +986,135 @@ declare class Manager {
936
986
  close(): void;
937
987
  }
938
988
 
989
+ declare class ServerStats {
990
+ constructor(server: any, { onSample }?: {
991
+ onSample?: null | undefined;
992
+ });
993
+ server: any;
994
+ onSample: any;
995
+ base: any;
996
+ counters: {
997
+ opened: number;
998
+ closed: number;
999
+ authFailed: number;
1000
+ };
1001
+ onState: (_peer: any, _previous: any) => void;
1002
+ delay: perf_hooks.IntervalHistogram;
1003
+ cpu: NodeJS.CpuUsage;
1004
+ elu: perf_hooks.EventLoopUtilization;
1005
+ previousAt: number;
1006
+ previous: {
1007
+ opened: number;
1008
+ closed: number;
1009
+ authFailed: number;
1010
+ };
1011
+ timer: NodeJS.Timeout;
1012
+ sample(): void;
1013
+ value: {
1014
+ at: number;
1015
+ total: any;
1016
+ authenticated: number;
1017
+ anonymous: number;
1018
+ websocket: number;
1019
+ transports: {
1020
+ websocket: {
1021
+ total: number;
1022
+ authenticated: number;
1023
+ };
1024
+ tcp: {
1025
+ total: number;
1026
+ authenticated: number;
1027
+ };
1028
+ };
1029
+ hostAvailableBytes: number | null;
1030
+ hostTotalBytes: number;
1031
+ channels: any;
1032
+ states: {};
1033
+ queuedBytes: number;
1034
+ maxQueuedBytes: number;
1035
+ txQueuePeakBytes: number;
1036
+ txWriteFalseCount: number;
1037
+ txDrainMaxMs: number;
1038
+ txBlockedConnections: number;
1039
+ txBlockedMaxMs: number;
1040
+ counters: {
1041
+ opened: number;
1042
+ closed: number;
1043
+ authFailed: number;
1044
+ };
1045
+ rates: {
1046
+ [k: string]: number;
1047
+ };
1048
+ rss: number;
1049
+ heapUsed: number;
1050
+ cpuPercent: number;
1051
+ eventLoopUtilization: number;
1052
+ eventLoopP99Ms: number;
1053
+ quota: {
1054
+ anonymous: any;
1055
+ profiles: any;
1056
+ };
1057
+ } | undefined;
1058
+ dispose(): void;
1059
+ }
1060
+
1061
+ /**
1062
+ * The server dashboard: a web page (options.path) that shows the server and its hosts live.
1063
+ * It talks to the page through IOSignal itself: viewers send 'hello' to DASHBOARD.IN, a host checks
1064
+ * access, and every second it sends the latest sample to each viewer with host.to().
1065
+ *
1066
+ * options (all optional):
1067
+ * path: '/dashboard'
1068
+ * access: 'open' | { token: '...' } | { login: { roles: ['admin'], cids: [] } }
1069
+ * panels: panels shown first (DASHBOARD_PANELS); viewers can switch them
1070
+ * history: seconds kept for the charts (default 300, 10-3600)
1071
+ * maxViewers: default 20
1072
+ * showIdentities: show participant CIDs and names (default: true unless access is 'open')
1073
+ */
1074
+ declare class Dashboard {
1075
+ constructor(server: any, options?: {});
1076
+ path: string;
1077
+ access: {
1078
+ mode: string;
1079
+ hash?: undefined;
1080
+ roles?: undefined;
1081
+ cids?: undefined;
1082
+ } | {
1083
+ mode: string;
1084
+ hash: NonSharedBuffer;
1085
+ roles?: undefined;
1086
+ cids?: undefined;
1087
+ } | {
1088
+ mode: string;
1089
+ roles: any[];
1090
+ cids: Set<any>;
1091
+ hash?: undefined;
1092
+ };
1093
+ panels: any[];
1094
+ history: any;
1095
+ maxViewers: any;
1096
+ showIdentities: any;
1097
+ server: any;
1098
+ startedAt: number;
1099
+ viewers: Map<any, any>;
1100
+ series: any[];
1101
+ lastHostCounters: Map<any, any>;
1102
+ lastJournal: Map<any, any>;
1103
+ events: any[];
1104
+ host: any;
1105
+ stats: ServerStats;
1106
+ /** Whether this viewer (the server's view of it) may watch. */
1107
+ allowed(from: any, msg: any): boolean;
1108
+ /**
1109
+ * Serves the page (GET path) and the browser client (path + '/io.js'). Returns true when it
1110
+ * answered. A Server with `port` calls it itself; with your own httpServer call it first in
1111
+ * your request handler: if (server.dashboard.handle(req, res)) return
1112
+ */
1113
+ handle(req: any, res: any): boolean;
1114
+ close(): void;
1115
+ #private;
1116
+ }
1117
+
939
1118
  declare class Server extends EventEmitter$1<[never]> {
940
1119
  /**
941
1120
  * @param {object} options Server configuration.
@@ -962,6 +1141,9 @@ declare class Server extends EventEmitter$1<[never]> {
962
1141
  * options.anonymousQuota: profile of a connection that has not authenticated (default 'anonymous').
963
1142
  * options.duplicateLogin: 'keepOld' | 'keepNew' for this Server's connections; overrides the auth
964
1143
  * manager's own policy without changing it, so an auth manager can be shared between servers.
1144
+ * options.dashboard: true or { path, access, panels, history, maxViewers, showIdentities } shows a live
1145
+ * status page of the server and its hosts (see Dashboard.js); off by default. With `port` the Server
1146
+ * serves it itself; with your own httpServer call server.dashboard.handle(req, res) in its handler.
965
1147
  * A failed listen (e.g. EADDRINUSE) is emitted as 'error'.
966
1148
  * @param {any} [authManager] Optional authentication manager.
967
1149
  */
@@ -988,9 +1170,11 @@ declare class Server extends EventEmitter$1<[never]> {
988
1170
  httpServer: any;
989
1171
  wsPath: any;
990
1172
  manager: Manager;
1173
+ dashboard: Dashboard | null;
991
1174
  serverCountToListen: number;
992
1175
  listeningServerCount: number;
993
1176
  startWSServer(): void;
1177
+ ownHttp: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse> | undefined;
994
1178
  startCongServer(): void;
995
1179
  congServer: any;
996
1180
  onListenerError(name: any, err: any): void;