@colyseus/core 0.16.0-preview.34 → 0.16.0-preview.36

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 (57) hide show
  1. package/build/MatchMaker.d.ts +5 -8
  2. package/build/MatchMaker.js +40 -13
  3. package/build/MatchMaker.js.map +2 -2
  4. package/build/MatchMaker.mjs +40 -13
  5. package/build/MatchMaker.mjs.map +2 -2
  6. package/build/Protocol.d.ts +3 -3
  7. package/build/Room.d.ts +30 -8
  8. package/build/Room.js +91 -35
  9. package/build/Room.js.map +2 -2
  10. package/build/Room.mjs +93 -37
  11. package/build/Room.mjs.map +2 -2
  12. package/build/Server.d.ts +2 -0
  13. package/build/Server.js +10 -1
  14. package/build/Server.js.map +2 -2
  15. package/build/Server.mjs +10 -1
  16. package/build/Server.mjs.map +2 -2
  17. package/build/Stats.d.ts +2 -0
  18. package/build/Stats.js +37 -2
  19. package/build/Stats.js.map +2 -2
  20. package/build/Stats.mjs +25 -2
  21. package/build/Stats.mjs.map +2 -2
  22. package/build/Transport.d.ts +5 -0
  23. package/build/Transport.js.map +2 -2
  24. package/build/Transport.mjs.map +2 -2
  25. package/build/errors/RoomExceptions.d.ts +39 -0
  26. package/build/errors/RoomExceptions.js +100 -0
  27. package/build/errors/RoomExceptions.js.map +7 -0
  28. package/build/errors/RoomExceptions.mjs +71 -0
  29. package/build/errors/RoomExceptions.mjs.map +7 -0
  30. package/build/index.d.ts +2 -1
  31. package/build/index.js +19 -0
  32. package/build/index.js.map +2 -2
  33. package/build/index.mjs +20 -0
  34. package/build/index.mjs.map +2 -2
  35. package/build/matchmaker/controller.d.ts +2 -1
  36. package/build/matchmaker/controller.js.map +2 -2
  37. package/build/matchmaker/controller.mjs.map +2 -2
  38. package/build/matchmaker/driver/index.d.ts +2 -2
  39. package/build/matchmaker/driver/index.js +2 -2
  40. package/build/matchmaker/driver/index.js.map +2 -2
  41. package/build/matchmaker/driver/index.mjs +5 -4
  42. package/build/matchmaker/driver/index.mjs.map +2 -2
  43. package/build/matchmaker/driver/local/LocalDriver.js +2 -2
  44. package/build/matchmaker/driver/local/LocalDriver.js.map +2 -2
  45. package/build/matchmaker/driver/local/LocalDriver.mjs +2 -2
  46. package/build/matchmaker/driver/local/LocalDriver.mjs.map +2 -2
  47. package/build/serializer/SchemaSerializer.d.ts +4 -4
  48. package/build/serializer/SchemaSerializer.js +3 -3
  49. package/build/serializer/SchemaSerializer.js.map +2 -2
  50. package/build/serializer/SchemaSerializer.mjs +3 -3
  51. package/build/serializer/SchemaSerializer.mjs.map +2 -2
  52. package/build/utils/Utils.d.ts +4 -1
  53. package/build/utils/Utils.js +25 -2
  54. package/build/utils/Utils.js.map +2 -2
  55. package/build/utils/Utils.mjs +23 -1
  56. package/build/utils/Utils.mjs.map +2 -2
  57. package/package.json +10 -5
package/build/Stats.js CHANGED
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,15 +16,25 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
  var Stats_exports = {};
19
29
  __export(Stats_exports, {
30
+ clearAutoPersistInterval: () => clearAutoPersistInterval,
20
31
  excludeProcess: () => excludeProcess,
21
32
  fetchAll: () => fetchAll,
22
33
  getGlobalCCU: () => getGlobalCCU,
23
34
  local: () => local,
24
35
  persist: () => persist,
25
- reset: () => reset
36
+ reset: () => reset,
37
+ setAutoPersistInterval: () => setAutoPersistInterval
26
38
  });
27
39
  module.exports = __toCommonJS(Stats_exports);
28
40
  var import_MatchMaker = require("./MatchMaker.js");
@@ -30,6 +42,11 @@ let local = {
30
42
  roomCount: 0,
31
43
  ccu: 0
32
44
  };
45
+ import("@pm2/io").then((io) => {
46
+ io.default.metric({ id: "app/stats/ccu", name: "ccu", value: () => local.ccu });
47
+ io.default.metric({ id: "app/stats/roomcount", name: "roomcount", value: () => local.roomCount });
48
+ }).catch(() => {
49
+ });
33
50
  async function fetchAll() {
34
51
  const allStats = [];
35
52
  const allProcesses = await import_MatchMaker.presence.hgetall(getRoomCountKey());
@@ -47,6 +64,9 @@ let lastPersisted = 0;
47
64
  let persistTimeout = void 0;
48
65
  const persistInterval = 1e3;
49
66
  function persist(forceNow = false) {
67
+ if (import_MatchMaker.state === import_MatchMaker.MatchMakerState.SHUTTING_DOWN) {
68
+ return;
69
+ }
50
70
  const now = Date.now();
51
71
  if (forceNow || now - lastPersisted > persistInterval) {
52
72
  lastPersisted = now;
@@ -72,15 +92,30 @@ async function getGlobalCCU() {
72
92
  const allStats = await fetchAll();
73
93
  return allStats.reduce((prev, next) => prev + next.ccu, 0);
74
94
  }
95
+ let autoPersistInterval = void 0;
96
+ function setAutoPersistInterval() {
97
+ const interval = 60 * 1e3;
98
+ autoPersistInterval = setInterval(() => {
99
+ const now = Date.now();
100
+ if (now - lastPersisted > interval) {
101
+ persist();
102
+ }
103
+ }, interval);
104
+ }
105
+ function clearAutoPersistInterval() {
106
+ clearInterval(autoPersistInterval);
107
+ }
75
108
  function getRoomCountKey() {
76
109
  return "roomcount";
77
110
  }
78
111
  // Annotate the CommonJS export names for ESM import in node:
79
112
  0 && (module.exports = {
113
+ clearAutoPersistInterval,
80
114
  excludeProcess,
81
115
  fetchAll,
82
116
  getGlobalCCU,
83
117
  local,
84
118
  persist,
85
- reset
119
+ reset,
120
+ setAutoPersistInterval
86
121
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/Stats.ts"],
4
- "sourcesContent": ["import { presence, processId } from './MatchMaker.js';\n\nexport type Stats = {\n roomCount: number;\n ccu: number;\n}\n\nexport let local: Stats = {\n roomCount: 0,\n ccu: 0,\n};\n\nexport async function fetchAll() {\n // TODO: cache this value to avoid querying too often\n const allStats: Array<Stats & { processId: string }> = [];\n const allProcesses = await presence.hgetall(getRoomCountKey());\n for (let remoteProcessId in allProcesses) {\n if (remoteProcessId === processId) {\n allStats.push({ processId, roomCount: local.roomCount, ccu: local.ccu, });\n\n } else {\n const [roomCount, ccu] = allProcesses[remoteProcessId].split(',').map(Number);\n allStats.push({ processId: remoteProcessId, roomCount, ccu });\n }\n }\n return allStats;\n}\n\nlet lastPersisted = 0;\nlet persistTimeout = undefined;\nconst persistInterval = 1000;\n\nexport function persist(forceNow: boolean = false) {\n /**\n * Avoid persisting too often.\n */\n const now = Date.now();\n\n if (forceNow || (now - lastPersisted > persistInterval)) {\n lastPersisted = now;\n return presence.hset(getRoomCountKey(), processId, `${local.roomCount},${local.ccu}`);\n\n } else {\n clearTimeout(persistTimeout);\n persistTimeout = setTimeout(persist, persistInterval);\n }\n}\n\nexport function reset(_persist: boolean = true) {\n local.roomCount = 0;\n local.ccu = 0;\n\n if (_persist) {\n lastPersisted = 0;\n clearTimeout(persistTimeout);\n persist();\n }\n}\n\nexport function excludeProcess(_processId: string) {\n return presence.hdel(getRoomCountKey(), _processId);\n}\n\nexport async function getGlobalCCU() {\n const allStats = await fetchAll();\n return allStats.reduce((prev, next) => prev + next.ccu, 0);\n}\n\nfunction getRoomCountKey() {\n return 'roomcount';\n}"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAoC;AAO7B,IAAI,QAAe;AAAA,EACxB,WAAW;AAAA,EACX,KAAK;AACP;AAEA,eAAsB,WAAW;AAE/B,QAAM,WAAiD,CAAC;AACxD,QAAM,eAAe,MAAM,2BAAS,QAAQ,gBAAgB,CAAC;AAC7D,WAAS,mBAAmB,cAAc;AACxC,QAAI,oBAAoB,6BAAW;AACjC,eAAS,KAAK,EAAE,wCAAW,WAAW,MAAM,WAAW,KAAK,MAAM,IAAK,CAAC;AAAA,IAE1E,OAAO;AACL,YAAM,CAAC,WAAW,GAAG,IAAI,aAAa,eAAe,EAAE,MAAM,GAAG,EAAE,IAAI,MAAM;AAC5E,eAAS,KAAK,EAAE,WAAW,iBAAiB,WAAW,IAAI,CAAC;AAAA,IAC9D;AAAA,EACF;AACA,SAAO;AACT;AAEA,IAAI,gBAAgB;AACpB,IAAI,iBAAiB;AACrB,MAAM,kBAAkB;AAEjB,SAAS,QAAQ,WAAoB,OAAO;AAIjD,QAAM,MAAM,KAAK,IAAI;AAErB,MAAI,YAAa,MAAM,gBAAgB,iBAAkB;AACvD,oBAAgB;AAChB,WAAO,2BAAS,KAAK,gBAAgB,GAAG,6BAAW,GAAG,MAAM,SAAS,IAAI,MAAM,GAAG,EAAE;AAAA,EAEtF,OAAO;AACL,iBAAa,cAAc;AAC3B,qBAAiB,WAAW,SAAS,eAAe;AAAA,EACtD;AACF;AAEO,SAAS,MAAM,WAAoB,MAAM;AAC9C,QAAM,YAAY;AAClB,QAAM,MAAM;AAEZ,MAAI,UAAU;AACZ,oBAAgB;AAChB,iBAAa,cAAc;AAC3B,YAAQ;AAAA,EACV;AACF;AAEO,SAAS,eAAe,YAAoB;AACjD,SAAO,2BAAS,KAAK,gBAAgB,GAAG,UAAU;AACpD;AAEA,eAAsB,eAAe;AACnC,QAAM,WAAW,MAAM,SAAS;AAChC,SAAO,SAAS,OAAO,CAAC,MAAM,SAAS,OAAO,KAAK,KAAK,CAAC;AAC3D;AAEA,SAAS,kBAAkB;AACzB,SAAO;AACT;",
4
+ "sourcesContent": ["import { MatchMakerState, presence, processId, state } from './MatchMaker.js';\n\nexport type Stats = {\n roomCount: number;\n ccu: number;\n}\n\nexport let local: Stats = {\n roomCount: 0,\n ccu: 0,\n};\n\n//\n// Attach local metrics to PM2 (if available)\n//\n// @ts-ignore\nimport('@pm2/io')\n .then((io) => {\n io.default.metric({ id: 'app/stats/ccu', name: 'ccu', value: () => local.ccu });\n io.default.metric({ id: 'app/stats/roomcount', name: 'roomcount', value: () => local.roomCount });\n })\n .catch(() => { });\n\nexport async function fetchAll() {\n // TODO: cache this value to avoid querying too often\n const allStats: Array<Stats & { processId: string }> = [];\n const allProcesses = await presence.hgetall(getRoomCountKey());\n\n for (let remoteProcessId in allProcesses) {\n if (remoteProcessId === processId) {\n allStats.push({ processId, roomCount: local.roomCount, ccu: local.ccu, });\n\n } else {\n const [roomCount, ccu] = allProcesses[remoteProcessId].split(',').map(Number);\n allStats.push({ processId: remoteProcessId, roomCount, ccu });\n }\n }\n\n return allStats;\n}\n\nlet lastPersisted = 0;\nlet persistTimeout = undefined;\nconst persistInterval = 1000;\n\nexport function persist(forceNow: boolean = false) {\n // skip if shutting down\n if (state === MatchMakerState.SHUTTING_DOWN) {\n return;\n }\n\n /**\n * Avoid persisting more than once per second.\n */\n const now = Date.now();\n\n if (forceNow || (now - lastPersisted > persistInterval)) {\n lastPersisted = now;\n return presence.hset(getRoomCountKey(), processId, `${local.roomCount},${local.ccu}`);\n\n } else {\n clearTimeout(persistTimeout);\n persistTimeout = setTimeout(persist, persistInterval);\n }\n}\n\nexport function reset(_persist: boolean = true) {\n local.roomCount = 0;\n local.ccu = 0;\n\n if (_persist) {\n lastPersisted = 0;\n clearTimeout(persistTimeout);\n persist();\n }\n}\n\nexport function excludeProcess(_processId: string) {\n return presence.hdel(getRoomCountKey(), _processId);\n}\n\nexport async function getGlobalCCU() {\n const allStats = await fetchAll();\n return allStats.reduce((prev, next) => prev + next.ccu, 0);\n}\n\n/**\n * Auto-persist every minute.\n */\nlet autoPersistInterval = undefined;\n\nexport function setAutoPersistInterval() {\n const interval = 60 * 1000;// 1 minute\n\n autoPersistInterval = setInterval(() => {\n const now = Date.now();\n\n if (now - lastPersisted > interval) {\n persist();\n }\n }, interval);\n}\n\nexport function clearAutoPersistInterval() {\n clearInterval(autoPersistInterval);\n}\n\nfunction getRoomCountKey() {\n return 'roomcount';\n}"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA4D;AAOrD,IAAI,QAAe;AAAA,EACxB,WAAW;AAAA,EACX,KAAK;AACP;AAMA,OAAO,SAAS,EACb,KAAK,CAAC,OAAO;AACZ,KAAG,QAAQ,OAAO,EAAE,IAAI,iBAAiB,MAAM,OAAO,OAAO,MAAM,MAAM,IAAI,CAAC;AAC9E,KAAG,QAAQ,OAAO,EAAE,IAAI,uBAAuB,MAAM,aAAa,OAAO,MAAM,MAAM,UAAU,CAAC;AAClG,CAAC,EACA,MAAM,MAAM;AAAE,CAAC;AAElB,eAAsB,WAAW;AAE/B,QAAM,WAAiD,CAAC;AACxD,QAAM,eAAe,MAAM,2BAAS,QAAQ,gBAAgB,CAAC;AAE7D,WAAS,mBAAmB,cAAc;AACxC,QAAI,oBAAoB,6BAAW;AACjC,eAAS,KAAK,EAAE,wCAAW,WAAW,MAAM,WAAW,KAAK,MAAM,IAAK,CAAC;AAAA,IAE1E,OAAO;AACL,YAAM,CAAC,WAAW,GAAG,IAAI,aAAa,eAAe,EAAE,MAAM,GAAG,EAAE,IAAI,MAAM;AAC5E,eAAS,KAAK,EAAE,WAAW,iBAAiB,WAAW,IAAI,CAAC;AAAA,IAC9D;AAAA,EACF;AAEA,SAAO;AACT;AAEA,IAAI,gBAAgB;AACpB,IAAI,iBAAiB;AACrB,MAAM,kBAAkB;AAEjB,SAAS,QAAQ,WAAoB,OAAO;AAEjD,MAAI,4BAAU,kCAAgB,eAAe;AAC3C;AAAA,EACF;AAKA,QAAM,MAAM,KAAK,IAAI;AAErB,MAAI,YAAa,MAAM,gBAAgB,iBAAkB;AACvD,oBAAgB;AAChB,WAAO,2BAAS,KAAK,gBAAgB,GAAG,6BAAW,GAAG,MAAM,SAAS,IAAI,MAAM,GAAG,EAAE;AAAA,EAEtF,OAAO;AACL,iBAAa,cAAc;AAC3B,qBAAiB,WAAW,SAAS,eAAe;AAAA,EACtD;AACF;AAEO,SAAS,MAAM,WAAoB,MAAM;AAC9C,QAAM,YAAY;AAClB,QAAM,MAAM;AAEZ,MAAI,UAAU;AACZ,oBAAgB;AAChB,iBAAa,cAAc;AAC3B,YAAQ;AAAA,EACV;AACF;AAEO,SAAS,eAAe,YAAoB;AACjD,SAAO,2BAAS,KAAK,gBAAgB,GAAG,UAAU;AACpD;AAEA,eAAsB,eAAe;AACnC,QAAM,WAAW,MAAM,SAAS;AAChC,SAAO,SAAS,OAAO,CAAC,MAAM,SAAS,OAAO,KAAK,KAAK,CAAC;AAC3D;AAKA,IAAI,sBAAsB;AAEnB,SAAS,yBAAyB;AACvC,QAAM,WAAW,KAAK;AAEtB,wBAAsB,YAAY,MAAM;AACtC,UAAM,MAAM,KAAK,IAAI;AAErB,QAAI,MAAM,gBAAgB,UAAU;AAClC,cAAQ;AAAA,IACV;AAAA,EACF,GAAG,QAAQ;AACb;AAEO,SAAS,2BAA2B;AACzC,gBAAc,mBAAmB;AACnC;AAEA,SAAS,kBAAkB;AACzB,SAAO;AACT;",
6
6
  "names": []
7
7
  }
package/build/Stats.mjs CHANGED
@@ -1,9 +1,14 @@
1
1
  // packages/core/src/Stats.ts
2
- import { presence, processId } from "./MatchMaker.mjs";
2
+ import { MatchMakerState, presence, processId, state } from "./MatchMaker.mjs";
3
3
  var local = {
4
4
  roomCount: 0,
5
5
  ccu: 0
6
6
  };
7
+ import("@pm2/io").then((io) => {
8
+ io.default.metric({ id: "app/stats/ccu", name: "ccu", value: () => local.ccu });
9
+ io.default.metric({ id: "app/stats/roomcount", name: "roomcount", value: () => local.roomCount });
10
+ }).catch(() => {
11
+ });
7
12
  async function fetchAll() {
8
13
  const allStats = [];
9
14
  const allProcesses = await presence.hgetall(getRoomCountKey());
@@ -21,6 +26,9 @@ var lastPersisted = 0;
21
26
  var persistTimeout = void 0;
22
27
  var persistInterval = 1e3;
23
28
  function persist(forceNow = false) {
29
+ if (state === MatchMakerState.SHUTTING_DOWN) {
30
+ return;
31
+ }
24
32
  const now = Date.now();
25
33
  if (forceNow || now - lastPersisted > persistInterval) {
26
34
  lastPersisted = now;
@@ -46,14 +54,29 @@ async function getGlobalCCU() {
46
54
  const allStats = await fetchAll();
47
55
  return allStats.reduce((prev, next) => prev + next.ccu, 0);
48
56
  }
57
+ var autoPersistInterval = void 0;
58
+ function setAutoPersistInterval() {
59
+ const interval = 60 * 1e3;
60
+ autoPersistInterval = setInterval(() => {
61
+ const now = Date.now();
62
+ if (now - lastPersisted > interval) {
63
+ persist();
64
+ }
65
+ }, interval);
66
+ }
67
+ function clearAutoPersistInterval() {
68
+ clearInterval(autoPersistInterval);
69
+ }
49
70
  function getRoomCountKey() {
50
71
  return "roomcount";
51
72
  }
52
73
  export {
74
+ clearAutoPersistInterval,
53
75
  excludeProcess,
54
76
  fetchAll,
55
77
  getGlobalCCU,
56
78
  local,
57
79
  persist,
58
- reset
80
+ reset,
81
+ setAutoPersistInterval
59
82
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/Stats.ts"],
4
- "sourcesContent": ["import { presence, processId } from './MatchMaker.js';\n\nexport type Stats = {\n roomCount: number;\n ccu: number;\n}\n\nexport let local: Stats = {\n roomCount: 0,\n ccu: 0,\n};\n\nexport async function fetchAll() {\n // TODO: cache this value to avoid querying too often\n const allStats: Array<Stats & { processId: string }> = [];\n const allProcesses = await presence.hgetall(getRoomCountKey());\n for (let remoteProcessId in allProcesses) {\n if (remoteProcessId === processId) {\n allStats.push({ processId, roomCount: local.roomCount, ccu: local.ccu, });\n\n } else {\n const [roomCount, ccu] = allProcesses[remoteProcessId].split(',').map(Number);\n allStats.push({ processId: remoteProcessId, roomCount, ccu });\n }\n }\n return allStats;\n}\n\nlet lastPersisted = 0;\nlet persistTimeout = undefined;\nconst persistInterval = 1000;\n\nexport function persist(forceNow: boolean = false) {\n /**\n * Avoid persisting too often.\n */\n const now = Date.now();\n\n if (forceNow || (now - lastPersisted > persistInterval)) {\n lastPersisted = now;\n return presence.hset(getRoomCountKey(), processId, `${local.roomCount},${local.ccu}`);\n\n } else {\n clearTimeout(persistTimeout);\n persistTimeout = setTimeout(persist, persistInterval);\n }\n}\n\nexport function reset(_persist: boolean = true) {\n local.roomCount = 0;\n local.ccu = 0;\n\n if (_persist) {\n lastPersisted = 0;\n clearTimeout(persistTimeout);\n persist();\n }\n}\n\nexport function excludeProcess(_processId: string) {\n return presence.hdel(getRoomCountKey(), _processId);\n}\n\nexport async function getGlobalCCU() {\n const allStats = await fetchAll();\n return allStats.reduce((prev, next) => prev + next.ccu, 0);\n}\n\nfunction getRoomCountKey() {\n return 'roomcount';\n}"],
5
- "mappings": ";AAAA,SAAS,UAAU,iBAAiB;AAO7B,IAAI,QAAe;AAAA,EACxB,WAAW;AAAA,EACX,KAAK;AACP;AAEA,eAAsB,WAAW;AAE/B,QAAM,WAAiD,CAAC;AACxD,QAAM,eAAe,MAAM,SAAS,QAAQ,gBAAgB,CAAC;AAC7D,WAAS,mBAAmB,cAAc;AACxC,QAAI,oBAAoB,WAAW;AACjC,eAAS,KAAK,EAAE,WAAW,WAAW,MAAM,WAAW,KAAK,MAAM,IAAK,CAAC;AAAA,IAE1E,OAAO;AACL,YAAM,CAAC,WAAW,GAAG,IAAI,aAAa,eAAe,EAAE,MAAM,GAAG,EAAE,IAAI,MAAM;AAC5E,eAAS,KAAK,EAAE,WAAW,iBAAiB,WAAW,IAAI,CAAC;AAAA,IAC9D;AAAA,EACF;AACA,SAAO;AACT;AAEA,IAAI,gBAAgB;AACpB,IAAI,iBAAiB;AACrB,IAAM,kBAAkB;AAEjB,SAAS,QAAQ,WAAoB,OAAO;AAIjD,QAAM,MAAM,KAAK,IAAI;AAErB,MAAI,YAAa,MAAM,gBAAgB,iBAAkB;AACvD,oBAAgB;AAChB,WAAO,SAAS,KAAK,gBAAgB,GAAG,WAAW,GAAG,MAAM,SAAS,IAAI,MAAM,GAAG,EAAE;AAAA,EAEtF,OAAO;AACL,iBAAa,cAAc;AAC3B,qBAAiB,WAAW,SAAS,eAAe;AAAA,EACtD;AACF;AAEO,SAAS,MAAM,WAAoB,MAAM;AAC9C,QAAM,YAAY;AAClB,QAAM,MAAM;AAEZ,MAAI,UAAU;AACZ,oBAAgB;AAChB,iBAAa,cAAc;AAC3B,YAAQ;AAAA,EACV;AACF;AAEO,SAAS,eAAe,YAAoB;AACjD,SAAO,SAAS,KAAK,gBAAgB,GAAG,UAAU;AACpD;AAEA,eAAsB,eAAe;AACnC,QAAM,WAAW,MAAM,SAAS;AAChC,SAAO,SAAS,OAAO,CAAC,MAAM,SAAS,OAAO,KAAK,KAAK,CAAC;AAC3D;AAEA,SAAS,kBAAkB;AACzB,SAAO;AACT;",
4
+ "sourcesContent": ["import { MatchMakerState, presence, processId, state } from './MatchMaker.js';\n\nexport type Stats = {\n roomCount: number;\n ccu: number;\n}\n\nexport let local: Stats = {\n roomCount: 0,\n ccu: 0,\n};\n\n//\n// Attach local metrics to PM2 (if available)\n//\n// @ts-ignore\nimport('@pm2/io')\n .then((io) => {\n io.default.metric({ id: 'app/stats/ccu', name: 'ccu', value: () => local.ccu });\n io.default.metric({ id: 'app/stats/roomcount', name: 'roomcount', value: () => local.roomCount });\n })\n .catch(() => { });\n\nexport async function fetchAll() {\n // TODO: cache this value to avoid querying too often\n const allStats: Array<Stats & { processId: string }> = [];\n const allProcesses = await presence.hgetall(getRoomCountKey());\n\n for (let remoteProcessId in allProcesses) {\n if (remoteProcessId === processId) {\n allStats.push({ processId, roomCount: local.roomCount, ccu: local.ccu, });\n\n } else {\n const [roomCount, ccu] = allProcesses[remoteProcessId].split(',').map(Number);\n allStats.push({ processId: remoteProcessId, roomCount, ccu });\n }\n }\n\n return allStats;\n}\n\nlet lastPersisted = 0;\nlet persistTimeout = undefined;\nconst persistInterval = 1000;\n\nexport function persist(forceNow: boolean = false) {\n // skip if shutting down\n if (state === MatchMakerState.SHUTTING_DOWN) {\n return;\n }\n\n /**\n * Avoid persisting more than once per second.\n */\n const now = Date.now();\n\n if (forceNow || (now - lastPersisted > persistInterval)) {\n lastPersisted = now;\n return presence.hset(getRoomCountKey(), processId, `${local.roomCount},${local.ccu}`);\n\n } else {\n clearTimeout(persistTimeout);\n persistTimeout = setTimeout(persist, persistInterval);\n }\n}\n\nexport function reset(_persist: boolean = true) {\n local.roomCount = 0;\n local.ccu = 0;\n\n if (_persist) {\n lastPersisted = 0;\n clearTimeout(persistTimeout);\n persist();\n }\n}\n\nexport function excludeProcess(_processId: string) {\n return presence.hdel(getRoomCountKey(), _processId);\n}\n\nexport async function getGlobalCCU() {\n const allStats = await fetchAll();\n return allStats.reduce((prev, next) => prev + next.ccu, 0);\n}\n\n/**\n * Auto-persist every minute.\n */\nlet autoPersistInterval = undefined;\n\nexport function setAutoPersistInterval() {\n const interval = 60 * 1000;// 1 minute\n\n autoPersistInterval = setInterval(() => {\n const now = Date.now();\n\n if (now - lastPersisted > interval) {\n persist();\n }\n }, interval);\n}\n\nexport function clearAutoPersistInterval() {\n clearInterval(autoPersistInterval);\n}\n\nfunction getRoomCountKey() {\n return 'roomcount';\n}"],
5
+ "mappings": ";AAAA,SAAS,iBAAiB,UAAU,WAAW,aAAa;AAOrD,IAAI,QAAe;AAAA,EACxB,WAAW;AAAA,EACX,KAAK;AACP;AAMA,OAAO,SAAS,EACb,KAAK,CAAC,OAAO;AACZ,KAAG,QAAQ,OAAO,EAAE,IAAI,iBAAiB,MAAM,OAAO,OAAO,MAAM,MAAM,IAAI,CAAC;AAC9E,KAAG,QAAQ,OAAO,EAAE,IAAI,uBAAuB,MAAM,aAAa,OAAO,MAAM,MAAM,UAAU,CAAC;AAClG,CAAC,EACA,MAAM,MAAM;AAAE,CAAC;AAElB,eAAsB,WAAW;AAE/B,QAAM,WAAiD,CAAC;AACxD,QAAM,eAAe,MAAM,SAAS,QAAQ,gBAAgB,CAAC;AAE7D,WAAS,mBAAmB,cAAc;AACxC,QAAI,oBAAoB,WAAW;AACjC,eAAS,KAAK,EAAE,WAAW,WAAW,MAAM,WAAW,KAAK,MAAM,IAAK,CAAC;AAAA,IAE1E,OAAO;AACL,YAAM,CAAC,WAAW,GAAG,IAAI,aAAa,eAAe,EAAE,MAAM,GAAG,EAAE,IAAI,MAAM;AAC5E,eAAS,KAAK,EAAE,WAAW,iBAAiB,WAAW,IAAI,CAAC;AAAA,IAC9D;AAAA,EACF;AAEA,SAAO;AACT;AAEA,IAAI,gBAAgB;AACpB,IAAI,iBAAiB;AACrB,IAAM,kBAAkB;AAEjB,SAAS,QAAQ,WAAoB,OAAO;AAEjD,MAAI,UAAU,gBAAgB,eAAe;AAC3C;AAAA,EACF;AAKA,QAAM,MAAM,KAAK,IAAI;AAErB,MAAI,YAAa,MAAM,gBAAgB,iBAAkB;AACvD,oBAAgB;AAChB,WAAO,SAAS,KAAK,gBAAgB,GAAG,WAAW,GAAG,MAAM,SAAS,IAAI,MAAM,GAAG,EAAE;AAAA,EAEtF,OAAO;AACL,iBAAa,cAAc;AAC3B,qBAAiB,WAAW,SAAS,eAAe;AAAA,EACtD;AACF;AAEO,SAAS,MAAM,WAAoB,MAAM;AAC9C,QAAM,YAAY;AAClB,QAAM,MAAM;AAEZ,MAAI,UAAU;AACZ,oBAAgB;AAChB,iBAAa,cAAc;AAC3B,YAAQ;AAAA,EACV;AACF;AAEO,SAAS,eAAe,YAAoB;AACjD,SAAO,SAAS,KAAK,gBAAgB,GAAG,UAAU;AACpD;AAEA,eAAsB,eAAe;AACnC,QAAM,WAAW,MAAM,SAAS;AAChC,SAAO,SAAS,OAAO,CAAC,MAAM,SAAS,OAAO,KAAK,KAAK,CAAC;AAC3D;AAKA,IAAI,sBAAsB;AAEnB,SAAS,yBAAyB;AACvC,QAAM,WAAW,KAAK;AAEtB,wBAAsB,YAAY,MAAM;AACtC,UAAM,MAAM,KAAK,IAAI;AAErB,QAAI,MAAM,gBAAgB,UAAU;AAClC,cAAQ;AAAA,IACV;AAAA,EACF,GAAG,QAAQ;AACb;AAEO,SAAS,2BAA2B;AACzC,gBAAc,mBAAmB;AACnC;AAEA,SAAS,kBAAkB;AACzB,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -10,6 +10,11 @@ export declare abstract class Transport {
10
10
  abstract shutdown(): void;
11
11
  abstract simulateLatency(milliseconds: number): void;
12
12
  }
13
+ export type AuthContext = {
14
+ token?: string;
15
+ headers: http.IncomingHttpHeaders;
16
+ ip: string | string[];
17
+ };
13
18
  export interface ISendOptions {
14
19
  afterNextPatch?: boolean;
15
20
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/Transport.ts"],
4
- "sourcesContent": ["import * as http from 'http';\nimport * as https from 'https';\nimport * as net from 'net';\n\nimport { Schema, StateView } from '@colyseus/schema';\nimport { EventEmitter } from 'events';\nimport { spliceOne } from './utils/Utils.js';\n\nexport abstract class Transport {\n public protocol?: string;\n public server?: net.Server | http.Server | https.Server;\n\n public abstract listen(port?: number, hostname?: string, backlog?: number, listeningListener?: Function): this;\n public abstract shutdown(): void;\n\n public abstract simulateLatency(milliseconds: number): void;\n}\n\nexport interface ISendOptions {\n afterNextPatch?: boolean;\n}\n\nexport enum ClientState { JOINING, JOINED, RECONNECTED, LEAVING }\n\n/**\n * The client instance from the server-side is responsible for the transport layer between the server and the client.\n * It should not be confused with the Client from the client-side SDK, as they have completely different purposes!\n * You operate on client instances from `this.clients`, `Room#onJoin()`, `Room#onLeave()` and `Room#onMessage()`.\n *\n * - This is the raw WebSocket connection coming from the `ws` package. There are more methods available which aren't\n * encouraged to use along with Colyseus.\n */\nexport interface Client<UserData=any, AuthData=any> {\n ref: EventEmitter;\n\n /**\n * @deprecated use `sessionId` instead.\n */\n id: string;\n\n /**\n * Unique id per session.\n */\n sessionId: string; // TODO: remove sessionId on version 1.0.0\n\n /**\n * Connection state\n */\n state: ClientState;\n\n /**\n * Optional: when using `@view()` decorator in your state properties, this will be the view instance for this client.\n */\n view?: StateView;\n\n /**\n * User-defined data can be attached to the Client instance through this variable.\n * - Can be used to store custom data about the client's connection. userData is not synchronized with the client,\n * and should be used only to keep player-specific with its connection.\n */\n userData?: UserData;\n\n /**\n * auth data provided by your `onAuth`\n */\n auth?: AuthData;\n\n /**\n * Reconnection token used to re-join the room after onLeave + allowReconnection().\n *\n * IMPORTANT:\n * This is not the full reconnection token the client provides for the server.\n * The format provided by .reconnect() from the client-side must follow: \"${roomId}:${reconnectionToken}\"\n */\n reconnectionToken: string;\n\n raw(data: Uint8Array | Buffer, options?: ISendOptions, cb?: (err?: Error) => void): void;\n enqueueRaw(data: Uint8Array | Buffer, options?: ISendOptions): void;\n\n /**\n * Send a type of message to the client. Messages are encoded with MsgPack and can hold any\n * JSON-serializable data structure.\n *\n * @param type String or Number identifier the client SDK will use to receive this message\n * @param message Message payload. (automatically encoded with msgpack.)\n * @param options\n */\n send(type: string | number, message?: any, options?: ISendOptions): void;\n send(message: Schema, options?: ISendOptions): void;\n\n /**\n * Send raw bytes to this specific client.\n *\n * @param type String or Number identifier the client SDK will use to receive this message\n * @param bytes Raw byte array payload\n * @param options\n */\n sendBytes(type: string | number, bytes: Buffer | Uint8Array, options?: ISendOptions): void;\n\n /**\n * Disconnect this client from the room.\n *\n * @param code Custom close code. Default value is 1000.\n * @param data\n * @see {@link https://docs.colyseus.io/colyseus/server/room/#leavecode-number}\n */\n leave(code?: number, data?: string): void;\n\n /**\n * @deprecated Use .leave() instead.\n */\n close(code?: number, data?: string): void;\n\n /**\n * Triggers `onError` with specified code to the client-side.\n *\n * @param code\n * @param message\n */\n error(code: number, message?: string): void;\n}\n\n/**\n * Private properties of the Client instance.\n * Only accessible internally by the framework, should not be encouraged/auto-completed for the user.\n *\n * TODO: refactor this.\n * @private\n */\nexport interface ClientPrivate {\n readyState: number; // TODO: remove readyState on version 1.0.0. Use only \"state\" instead.\n _enqueuedMessages?: any[];\n _afterNextPatchQueue: Array<[string | Client, IArguments]>;\n _joinedAt: number; // \"elapsedTime\" when the client joined the room.\n}\n\nexport class ClientArray<UserData = any, AuthData = any> extends Array<Client<UserData, AuthData>> {\n public getById(sessionId: string): Client<UserData, AuthData> | undefined {\n return this.find((client) => client.sessionId === sessionId);\n }\n\n public delete(client: Client<UserData, AuthData>): boolean {\n return spliceOne(this, this.indexOf(client));\n }\n}"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,mBAA0B;AAEnB,MAAe,UAAU;AAQhC;AAMO,IAAK,cAAL,kBAAKA,iBAAL;AAAmB,EAAAA,0BAAA;AAAS,EAAAA,0BAAA;AAAQ,EAAAA,0BAAA;AAAa,EAAAA,0BAAA;AAA5C,SAAAA;AAAA,GAAA;AAkHL,MAAM,oBAAoD,MAAkC;AAAA,EAC1F,QAAQ,WAA2D;AACxE,WAAO,KAAK,KAAK,CAAC,WAAW,OAAO,cAAc,SAAS;AAAA,EAC7D;AAAA,EAEO,OAAO,QAA6C;AACzD,eAAO,wBAAU,MAAM,KAAK,QAAQ,MAAM,CAAC;AAAA,EAC7C;AACF;",
4
+ "sourcesContent": ["import * as http from 'http';\nimport * as https from 'https';\nimport * as net from 'net';\n\nimport { Schema, StateView } from '@colyseus/schema';\nimport { EventEmitter } from 'events';\nimport { spliceOne } from './utils/Utils.js';\n\nexport abstract class Transport {\n public protocol?: string;\n public server?: net.Server | http.Server | https.Server;\n\n public abstract listen(port?: number, hostname?: string, backlog?: number, listeningListener?: Function): this;\n public abstract shutdown(): void;\n\n public abstract simulateLatency(milliseconds: number): void;\n}\n\nexport type AuthContext = {\n token?: string,\n headers: http.IncomingHttpHeaders,\n ip: string | string[];\n};\n\nexport interface ISendOptions {\n afterNextPatch?: boolean;\n}\n\nexport enum ClientState { JOINING, JOINED, RECONNECTED, LEAVING }\n\n/**\n * The client instance from the server-side is responsible for the transport layer between the server and the client.\n * It should not be confused with the Client from the client-side SDK, as they have completely different purposes!\n * You operate on client instances from `this.clients`, `Room#onJoin()`, `Room#onLeave()` and `Room#onMessage()`.\n *\n * - This is the raw WebSocket connection coming from the `ws` package. There are more methods available which aren't\n * encouraged to use along with Colyseus.\n */\nexport interface Client<UserData=any, AuthData=any> {\n ref: EventEmitter;\n\n /**\n * @deprecated use `sessionId` instead.\n */\n id: string;\n\n /**\n * Unique id per session.\n */\n sessionId: string; // TODO: remove sessionId on version 1.0.0\n\n /**\n * Connection state\n */\n state: ClientState;\n\n /**\n * Optional: when using `@view()` decorator in your state properties, this will be the view instance for this client.\n */\n view?: StateView;\n\n /**\n * User-defined data can be attached to the Client instance through this variable.\n * - Can be used to store custom data about the client's connection. userData is not synchronized with the client,\n * and should be used only to keep player-specific with its connection.\n */\n userData?: UserData;\n\n /**\n * auth data provided by your `onAuth`\n */\n auth?: AuthData;\n\n /**\n * Reconnection token used to re-join the room after onLeave + allowReconnection().\n *\n * IMPORTANT:\n * This is not the full reconnection token the client provides for the server.\n * The format provided by .reconnect() from the client-side must follow: \"${roomId}:${reconnectionToken}\"\n */\n reconnectionToken: string;\n\n raw(data: Uint8Array | Buffer, options?: ISendOptions, cb?: (err?: Error) => void): void;\n enqueueRaw(data: Uint8Array | Buffer, options?: ISendOptions): void;\n\n /**\n * Send a type of message to the client. Messages are encoded with MsgPack and can hold any\n * JSON-serializable data structure.\n *\n * @param type String or Number identifier the client SDK will use to receive this message\n * @param message Message payload. (automatically encoded with msgpack.)\n * @param options\n */\n send(type: string | number, message?: any, options?: ISendOptions): void;\n send(message: Schema, options?: ISendOptions): void;\n\n /**\n * Send raw bytes to this specific client.\n *\n * @param type String or Number identifier the client SDK will use to receive this message\n * @param bytes Raw byte array payload\n * @param options\n */\n sendBytes(type: string | number, bytes: Buffer | Uint8Array, options?: ISendOptions): void;\n\n /**\n * Disconnect this client from the room.\n *\n * @param code Custom close code. Default value is 1000.\n * @param data\n * @see {@link https://docs.colyseus.io/colyseus/server/room/#leavecode-number}\n */\n leave(code?: number, data?: string): void;\n\n /**\n * @deprecated Use .leave() instead.\n */\n close(code?: number, data?: string): void;\n\n /**\n * Triggers `onError` with specified code to the client-side.\n *\n * @param code\n * @param message\n */\n error(code: number, message?: string): void;\n}\n\n/**\n * Private properties of the Client instance.\n * Only accessible internally by the framework, should not be encouraged/auto-completed for the user.\n *\n * TODO: refactor this.\n * @private\n */\nexport interface ClientPrivate {\n readyState: number; // TODO: remove readyState on version 1.0.0. Use only \"state\" instead.\n _enqueuedMessages?: any[];\n _afterNextPatchQueue: Array<[string | Client, IArguments]>;\n _joinedAt: number; // \"elapsedTime\" when the client joined the room.\n}\n\nexport class ClientArray<UserData = any, AuthData = any> extends Array<Client<UserData, AuthData>> {\n public getById(sessionId: string): Client<UserData, AuthData> | undefined {\n return this.find((client) => client.sessionId === sessionId);\n }\n\n public delete(client: Client<UserData, AuthData>): boolean {\n return spliceOne(this, this.indexOf(client));\n }\n}"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,mBAA0B;AAEnB,MAAe,UAAU;AAQhC;AAYO,IAAK,cAAL,kBAAKA,iBAAL;AAAmB,EAAAA,0BAAA;AAAS,EAAAA,0BAAA;AAAQ,EAAAA,0BAAA;AAAa,EAAAA,0BAAA;AAA5C,SAAAA;AAAA,GAAA;AAkHL,MAAM,oBAAoD,MAAkC;AAAA,EAC1F,QAAQ,WAA2D;AACxE,WAAO,KAAK,KAAK,CAAC,WAAW,OAAO,cAAc,SAAS;AAAA,EAC7D;AAAA,EAEO,OAAO,QAA6C;AACzD,eAAO,wBAAU,MAAM,KAAK,QAAQ,MAAM,CAAC;AAAA,EAC7C;AACF;",
6
6
  "names": ["ClientState"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/Transport.ts"],
4
- "sourcesContent": ["import * as http from 'http';\nimport * as https from 'https';\nimport * as net from 'net';\n\nimport { Schema, StateView } from '@colyseus/schema';\nimport { EventEmitter } from 'events';\nimport { spliceOne } from './utils/Utils.js';\n\nexport abstract class Transport {\n public protocol?: string;\n public server?: net.Server | http.Server | https.Server;\n\n public abstract listen(port?: number, hostname?: string, backlog?: number, listeningListener?: Function): this;\n public abstract shutdown(): void;\n\n public abstract simulateLatency(milliseconds: number): void;\n}\n\nexport interface ISendOptions {\n afterNextPatch?: boolean;\n}\n\nexport enum ClientState { JOINING, JOINED, RECONNECTED, LEAVING }\n\n/**\n * The client instance from the server-side is responsible for the transport layer between the server and the client.\n * It should not be confused with the Client from the client-side SDK, as they have completely different purposes!\n * You operate on client instances from `this.clients`, `Room#onJoin()`, `Room#onLeave()` and `Room#onMessage()`.\n *\n * - This is the raw WebSocket connection coming from the `ws` package. There are more methods available which aren't\n * encouraged to use along with Colyseus.\n */\nexport interface Client<UserData=any, AuthData=any> {\n ref: EventEmitter;\n\n /**\n * @deprecated use `sessionId` instead.\n */\n id: string;\n\n /**\n * Unique id per session.\n */\n sessionId: string; // TODO: remove sessionId on version 1.0.0\n\n /**\n * Connection state\n */\n state: ClientState;\n\n /**\n * Optional: when using `@view()` decorator in your state properties, this will be the view instance for this client.\n */\n view?: StateView;\n\n /**\n * User-defined data can be attached to the Client instance through this variable.\n * - Can be used to store custom data about the client's connection. userData is not synchronized with the client,\n * and should be used only to keep player-specific with its connection.\n */\n userData?: UserData;\n\n /**\n * auth data provided by your `onAuth`\n */\n auth?: AuthData;\n\n /**\n * Reconnection token used to re-join the room after onLeave + allowReconnection().\n *\n * IMPORTANT:\n * This is not the full reconnection token the client provides for the server.\n * The format provided by .reconnect() from the client-side must follow: \"${roomId}:${reconnectionToken}\"\n */\n reconnectionToken: string;\n\n raw(data: Uint8Array | Buffer, options?: ISendOptions, cb?: (err?: Error) => void): void;\n enqueueRaw(data: Uint8Array | Buffer, options?: ISendOptions): void;\n\n /**\n * Send a type of message to the client. Messages are encoded with MsgPack and can hold any\n * JSON-serializable data structure.\n *\n * @param type String or Number identifier the client SDK will use to receive this message\n * @param message Message payload. (automatically encoded with msgpack.)\n * @param options\n */\n send(type: string | number, message?: any, options?: ISendOptions): void;\n send(message: Schema, options?: ISendOptions): void;\n\n /**\n * Send raw bytes to this specific client.\n *\n * @param type String or Number identifier the client SDK will use to receive this message\n * @param bytes Raw byte array payload\n * @param options\n */\n sendBytes(type: string | number, bytes: Buffer | Uint8Array, options?: ISendOptions): void;\n\n /**\n * Disconnect this client from the room.\n *\n * @param code Custom close code. Default value is 1000.\n * @param data\n * @see {@link https://docs.colyseus.io/colyseus/server/room/#leavecode-number}\n */\n leave(code?: number, data?: string): void;\n\n /**\n * @deprecated Use .leave() instead.\n */\n close(code?: number, data?: string): void;\n\n /**\n * Triggers `onError` with specified code to the client-side.\n *\n * @param code\n * @param message\n */\n error(code: number, message?: string): void;\n}\n\n/**\n * Private properties of the Client instance.\n * Only accessible internally by the framework, should not be encouraged/auto-completed for the user.\n *\n * TODO: refactor this.\n * @private\n */\nexport interface ClientPrivate {\n readyState: number; // TODO: remove readyState on version 1.0.0. Use only \"state\" instead.\n _enqueuedMessages?: any[];\n _afterNextPatchQueue: Array<[string | Client, IArguments]>;\n _joinedAt: number; // \"elapsedTime\" when the client joined the room.\n}\n\nexport class ClientArray<UserData = any, AuthData = any> extends Array<Client<UserData, AuthData>> {\n public getById(sessionId: string): Client<UserData, AuthData> | undefined {\n return this.find((client) => client.sessionId === sessionId);\n }\n\n public delete(client: Client<UserData, AuthData>): boolean {\n return spliceOne(this, this.indexOf(client));\n }\n}"],
5
- "mappings": ";AAMA,SAAS,iBAAiB;AAEnB,IAAe,YAAf,MAAyB;AAQhC;AAMO,IAAK,cAAL,kBAAKA,iBAAL;AAAmB,EAAAA,0BAAA;AAAS,EAAAA,0BAAA;AAAQ,EAAAA,0BAAA;AAAa,EAAAA,0BAAA;AAA5C,SAAAA;AAAA,GAAA;AAkHL,IAAM,cAAN,cAA0D,MAAkC;AAAA,EAC1F,QAAQ,WAA2D;AACxE,WAAO,KAAK,KAAK,CAAC,WAAW,OAAO,cAAc,SAAS;AAAA,EAC7D;AAAA,EAEO,OAAO,QAA6C;AACzD,WAAO,UAAU,MAAM,KAAK,QAAQ,MAAM,CAAC;AAAA,EAC7C;AACF;",
4
+ "sourcesContent": ["import * as http from 'http';\nimport * as https from 'https';\nimport * as net from 'net';\n\nimport { Schema, StateView } from '@colyseus/schema';\nimport { EventEmitter } from 'events';\nimport { spliceOne } from './utils/Utils.js';\n\nexport abstract class Transport {\n public protocol?: string;\n public server?: net.Server | http.Server | https.Server;\n\n public abstract listen(port?: number, hostname?: string, backlog?: number, listeningListener?: Function): this;\n public abstract shutdown(): void;\n\n public abstract simulateLatency(milliseconds: number): void;\n}\n\nexport type AuthContext = {\n token?: string,\n headers: http.IncomingHttpHeaders,\n ip: string | string[];\n};\n\nexport interface ISendOptions {\n afterNextPatch?: boolean;\n}\n\nexport enum ClientState { JOINING, JOINED, RECONNECTED, LEAVING }\n\n/**\n * The client instance from the server-side is responsible for the transport layer between the server and the client.\n * It should not be confused with the Client from the client-side SDK, as they have completely different purposes!\n * You operate on client instances from `this.clients`, `Room#onJoin()`, `Room#onLeave()` and `Room#onMessage()`.\n *\n * - This is the raw WebSocket connection coming from the `ws` package. There are more methods available which aren't\n * encouraged to use along with Colyseus.\n */\nexport interface Client<UserData=any, AuthData=any> {\n ref: EventEmitter;\n\n /**\n * @deprecated use `sessionId` instead.\n */\n id: string;\n\n /**\n * Unique id per session.\n */\n sessionId: string; // TODO: remove sessionId on version 1.0.0\n\n /**\n * Connection state\n */\n state: ClientState;\n\n /**\n * Optional: when using `@view()` decorator in your state properties, this will be the view instance for this client.\n */\n view?: StateView;\n\n /**\n * User-defined data can be attached to the Client instance through this variable.\n * - Can be used to store custom data about the client's connection. userData is not synchronized with the client,\n * and should be used only to keep player-specific with its connection.\n */\n userData?: UserData;\n\n /**\n * auth data provided by your `onAuth`\n */\n auth?: AuthData;\n\n /**\n * Reconnection token used to re-join the room after onLeave + allowReconnection().\n *\n * IMPORTANT:\n * This is not the full reconnection token the client provides for the server.\n * The format provided by .reconnect() from the client-side must follow: \"${roomId}:${reconnectionToken}\"\n */\n reconnectionToken: string;\n\n raw(data: Uint8Array | Buffer, options?: ISendOptions, cb?: (err?: Error) => void): void;\n enqueueRaw(data: Uint8Array | Buffer, options?: ISendOptions): void;\n\n /**\n * Send a type of message to the client. Messages are encoded with MsgPack and can hold any\n * JSON-serializable data structure.\n *\n * @param type String or Number identifier the client SDK will use to receive this message\n * @param message Message payload. (automatically encoded with msgpack.)\n * @param options\n */\n send(type: string | number, message?: any, options?: ISendOptions): void;\n send(message: Schema, options?: ISendOptions): void;\n\n /**\n * Send raw bytes to this specific client.\n *\n * @param type String or Number identifier the client SDK will use to receive this message\n * @param bytes Raw byte array payload\n * @param options\n */\n sendBytes(type: string | number, bytes: Buffer | Uint8Array, options?: ISendOptions): void;\n\n /**\n * Disconnect this client from the room.\n *\n * @param code Custom close code. Default value is 1000.\n * @param data\n * @see {@link https://docs.colyseus.io/colyseus/server/room/#leavecode-number}\n */\n leave(code?: number, data?: string): void;\n\n /**\n * @deprecated Use .leave() instead.\n */\n close(code?: number, data?: string): void;\n\n /**\n * Triggers `onError` with specified code to the client-side.\n *\n * @param code\n * @param message\n */\n error(code: number, message?: string): void;\n}\n\n/**\n * Private properties of the Client instance.\n * Only accessible internally by the framework, should not be encouraged/auto-completed for the user.\n *\n * TODO: refactor this.\n * @private\n */\nexport interface ClientPrivate {\n readyState: number; // TODO: remove readyState on version 1.0.0. Use only \"state\" instead.\n _enqueuedMessages?: any[];\n _afterNextPatchQueue: Array<[string | Client, IArguments]>;\n _joinedAt: number; // \"elapsedTime\" when the client joined the room.\n}\n\nexport class ClientArray<UserData = any, AuthData = any> extends Array<Client<UserData, AuthData>> {\n public getById(sessionId: string): Client<UserData, AuthData> | undefined {\n return this.find((client) => client.sessionId === sessionId);\n }\n\n public delete(client: Client<UserData, AuthData>): boolean {\n return spliceOne(this, this.indexOf(client));\n }\n}"],
5
+ "mappings": ";AAMA,SAAS,iBAAiB;AAEnB,IAAe,YAAf,MAAyB;AAQhC;AAYO,IAAK,cAAL,kBAAKA,iBAAL;AAAmB,EAAAA,0BAAA;AAAS,EAAAA,0BAAA;AAAQ,EAAAA,0BAAA;AAAa,EAAAA,0BAAA;AAA5C,SAAAA;AAAA,GAAA;AAkHL,IAAM,cAAN,cAA0D,MAAkC;AAAA,EAC1F,QAAQ,WAA2D;AACxE,WAAO,KAAK,KAAK,CAAC,WAAW,OAAO,cAAc,SAAS;AAAA,EAC7D;AAAA,EAEO,OAAO,QAA6C;AACzD,WAAO,UAAU,MAAM,KAAK,QAAQ,MAAM,CAAC;AAAA,EAC7C;AACF;",
6
6
  "names": ["ClientState"]
7
7
  }
@@ -0,0 +1,39 @@
1
+ import type { Client } from '../Transport';
2
+ import type { ExtractAuthData, ExtractUserData, Room } from '../Room';
3
+ export type RoomException<R extends Room = Room> = OnCreateException<R> | OnAuthException<R> | OnJoinException<R> | OnLeaveException<R> | OnDisposeException | OnMessageException<R> | SimulationIntervalException | TimedEventException;
4
+ export declare class OnCreateException<R extends Room = Room> extends Error {
5
+ options: Parameters<R['onCreate']>[0];
6
+ constructor(cause: Error, message: string, options: Parameters<R['onCreate']>[0]);
7
+ }
8
+ export declare class OnAuthException<R extends Room = Room> extends Error {
9
+ client: Parameters<R['onAuth']>[0];
10
+ options: Parameters<R['onAuth']>[1];
11
+ constructor(cause: Error, message: string, client: Parameters<R['onAuth']>[0], options: Parameters<R['onAuth']>[1]);
12
+ }
13
+ export declare class OnJoinException<R extends Room = Room> extends Error {
14
+ client: Parameters<R['onJoin']>[0];
15
+ options: Parameters<R['onJoin']>[1];
16
+ auth: Parameters<R['onJoin']>[2];
17
+ constructor(cause: Error, message: string, client: Parameters<R['onJoin']>[0], options: Parameters<R['onJoin']>[1], auth: Parameters<R['onJoin']>[2]);
18
+ }
19
+ export declare class OnLeaveException<R extends Room = Room> extends Error {
20
+ client: Parameters<R['onLeave']>[0];
21
+ consented: Parameters<R['onLeave']>[1];
22
+ constructor(cause: Error, message: string, client: Parameters<R['onLeave']>[0], consented: Parameters<R['onLeave']>[1]);
23
+ }
24
+ export declare class OnDisposeException extends Error {
25
+ constructor(cause: Error, message: string);
26
+ }
27
+ export declare class OnMessageException<R extends Room = Room, MessagePayload = any> extends Error {
28
+ client: Client<ExtractUserData<R['clients']>, ExtractAuthData<R['clients']>>;
29
+ payload: MessagePayload;
30
+ type: string;
31
+ constructor(cause: Error, message: string, client: Client<ExtractUserData<R['clients']>, ExtractAuthData<R['clients']>>, payload: MessagePayload, type: string);
32
+ }
33
+ export declare class SimulationIntervalException extends Error {
34
+ constructor(cause: Error, message: string);
35
+ }
36
+ export declare class TimedEventException extends Error {
37
+ args: any[];
38
+ constructor(cause: Error, message: string, ...args: any[]);
39
+ }
@@ -0,0 +1,100 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var RoomExceptions_exports = {};
19
+ __export(RoomExceptions_exports, {
20
+ OnAuthException: () => OnAuthException,
21
+ OnCreateException: () => OnCreateException,
22
+ OnDisposeException: () => OnDisposeException,
23
+ OnJoinException: () => OnJoinException,
24
+ OnLeaveException: () => OnLeaveException,
25
+ OnMessageException: () => OnMessageException,
26
+ SimulationIntervalException: () => SimulationIntervalException,
27
+ TimedEventException: () => TimedEventException
28
+ });
29
+ module.exports = __toCommonJS(RoomExceptions_exports);
30
+ class OnCreateException extends Error {
31
+ constructor(cause, message, options) {
32
+ super(message, { cause });
33
+ this.options = options;
34
+ this.name = "OnCreateException";
35
+ }
36
+ }
37
+ class OnAuthException extends Error {
38
+ constructor(cause, message, client, options) {
39
+ super(message, { cause });
40
+ this.client = client;
41
+ this.options = options;
42
+ this.name = "OnAuthException";
43
+ }
44
+ }
45
+ class OnJoinException extends Error {
46
+ constructor(cause, message, client, options, auth) {
47
+ super(message, { cause });
48
+ this.client = client;
49
+ this.options = options;
50
+ this.auth = auth;
51
+ this.name = "OnJoinException";
52
+ }
53
+ }
54
+ class OnLeaveException extends Error {
55
+ constructor(cause, message, client, consented) {
56
+ super(message, { cause });
57
+ this.client = client;
58
+ this.consented = consented;
59
+ this.name = "OnLeaveException";
60
+ }
61
+ }
62
+ class OnDisposeException extends Error {
63
+ constructor(cause, message) {
64
+ super(message, { cause });
65
+ this.name = "OnDisposeException";
66
+ }
67
+ }
68
+ class OnMessageException extends Error {
69
+ constructor(cause, message, client, payload, type) {
70
+ super(message, { cause });
71
+ this.client = client;
72
+ this.payload = payload;
73
+ this.type = type;
74
+ this.name = "OnMessageException";
75
+ }
76
+ }
77
+ class SimulationIntervalException extends Error {
78
+ constructor(cause, message) {
79
+ super(message, { cause });
80
+ this.name = "SimulationIntervalException";
81
+ }
82
+ }
83
+ class TimedEventException extends Error {
84
+ constructor(cause, message, ...args) {
85
+ super(message, { cause });
86
+ this.name = "TimedEventException";
87
+ this.args = args;
88
+ }
89
+ }
90
+ // Annotate the CommonJS export names for ESM import in node:
91
+ 0 && (module.exports = {
92
+ OnAuthException,
93
+ OnCreateException,
94
+ OnDisposeException,
95
+ OnJoinException,
96
+ OnLeaveException,
97
+ OnMessageException,
98
+ SimulationIntervalException,
99
+ TimedEventException
100
+ });
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/errors/RoomExceptions.ts"],
4
+ "sourcesContent": ["import type { Client } from '../Transport';\nimport type { ExtractAuthData, ExtractUserData, Room } from '../Room';\n\nexport type RoomException<R extends Room = Room> =\n OnCreateException<R> |\n OnAuthException<R> |\n OnJoinException<R> |\n OnLeaveException<R> |\n OnDisposeException |\n OnMessageException<R> |\n SimulationIntervalException |\n TimedEventException;\n\nexport class OnCreateException<R extends Room = Room> extends Error {\n constructor(\n cause: Error,\n message: string,\n public options: Parameters<R['onCreate']>[0],\n ) {\n super(message, { cause });\n this.name = 'OnCreateException';\n }\n}\n\nexport class OnAuthException<R extends Room = Room> extends Error {\n constructor(\n cause: Error,\n message: string,\n public client: Parameters<R['onAuth']>[0],\n public options: Parameters<R['onAuth']>[1],\n ) {\n super(message, { cause });\n this.name = 'OnAuthException';\n }\n}\n\nexport class OnJoinException<R extends Room = Room> extends Error {\n constructor(\n cause: Error,\n message: string,\n public client: Parameters<R['onJoin']>[0],\n public options: Parameters<R['onJoin']>[1],\n public auth: Parameters<R['onJoin']>[2],\n ) {\n super(message, { cause });\n this.name = 'OnJoinException';\n }\n}\n\nexport class OnLeaveException<R extends Room = Room> extends Error {\n constructor(\n cause: Error,\n message: string,\n public client: Parameters<R['onLeave']>[0],\n public consented: Parameters<R['onLeave']>[1],\n ) {\n super(message, { cause });\n this.name = 'OnLeaveException';\n }\n}\n\nexport class OnDisposeException extends Error {\n constructor(\n cause: Error,\n message: string,\n ) {\n super(message, { cause });\n this.name = 'OnDisposeException';\n }\n}\n\nexport class OnMessageException<R extends Room = Room, MessagePayload = any> extends Error {\n constructor(\n cause: Error,\n message: string,\n public client: Client<ExtractUserData<R['clients']>, ExtractAuthData<R['clients']>>,\n public payload: MessagePayload,\n public type: string,\n ) {\n super(message, { cause });\n this.name = 'OnMessageException';\n }\n}\n\nexport class SimulationIntervalException extends Error {\n constructor(\n cause: Error,\n message: string,\n ) {\n super(message, { cause });\n this.name = 'SimulationIntervalException';\n }\n}\n\nexport class TimedEventException extends Error {\n public args: any[];\n constructor(\n cause: Error,\n message: string,\n ...args: any[]\n ) {\n super(message, { cause });\n this.name = 'TimedEventException';\n this.args = args;\n }\n}"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaO,MAAM,0BAAiD,MAAM;AAAA,EAClE,YACE,OACA,SACO,SACP;AACA,UAAM,SAAS,EAAE,MAAM,CAAC;AAFjB;AAGP,SAAK,OAAO;AAAA,EACd;AACF;AAEO,MAAM,wBAA+C,MAAM;AAAA,EAChE,YACE,OACA,SACO,QACA,SACP;AACA,UAAM,SAAS,EAAE,MAAM,CAAC;AAHjB;AACA;AAGP,SAAK,OAAO;AAAA,EACd;AACF;AAEO,MAAM,wBAA+C,MAAM;AAAA,EAChE,YACE,OACA,SACO,QACA,SACA,MACP;AACA,UAAM,SAAS,EAAE,MAAM,CAAC;AAJjB;AACA;AACA;AAGP,SAAK,OAAO;AAAA,EACd;AACF;AAEO,MAAM,yBAAgD,MAAM;AAAA,EACjE,YACE,OACA,SACO,QACA,WACP;AACA,UAAM,SAAS,EAAE,MAAM,CAAC;AAHjB;AACA;AAGP,SAAK,OAAO;AAAA,EACd;AACF;AAEO,MAAM,2BAA2B,MAAM;AAAA,EAC5C,YACE,OACA,SACA;AACA,UAAM,SAAS,EAAE,MAAM,CAAC;AACxB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,MAAM,2BAAwE,MAAM;AAAA,EACzF,YACE,OACA,SACO,QACA,SACA,MACP;AACA,UAAM,SAAS,EAAE,MAAM,CAAC;AAJjB;AACA;AACA;AAGP,SAAK,OAAO;AAAA,EACd;AACF;AAEO,MAAM,oCAAoC,MAAM;AAAA,EACrD,YACE,OACA,SACA;AACA,UAAM,SAAS,EAAE,MAAM,CAAC;AACxB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,MAAM,4BAA4B,MAAM;AAAA,EAE7C,YACE,OACA,YACG,MACH;AACA,UAAM,SAAS,EAAE,MAAM,CAAC;AACxB,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACd;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,71 @@
1
+ // packages/core/src/errors/RoomExceptions.ts
2
+ var OnCreateException = class extends Error {
3
+ constructor(cause, message, options) {
4
+ super(message, { cause });
5
+ this.options = options;
6
+ this.name = "OnCreateException";
7
+ }
8
+ };
9
+ var OnAuthException = class extends Error {
10
+ constructor(cause, message, client, options) {
11
+ super(message, { cause });
12
+ this.client = client;
13
+ this.options = options;
14
+ this.name = "OnAuthException";
15
+ }
16
+ };
17
+ var OnJoinException = class extends Error {
18
+ constructor(cause, message, client, options, auth) {
19
+ super(message, { cause });
20
+ this.client = client;
21
+ this.options = options;
22
+ this.auth = auth;
23
+ this.name = "OnJoinException";
24
+ }
25
+ };
26
+ var OnLeaveException = class extends Error {
27
+ constructor(cause, message, client, consented) {
28
+ super(message, { cause });
29
+ this.client = client;
30
+ this.consented = consented;
31
+ this.name = "OnLeaveException";
32
+ }
33
+ };
34
+ var OnDisposeException = class extends Error {
35
+ constructor(cause, message) {
36
+ super(message, { cause });
37
+ this.name = "OnDisposeException";
38
+ }
39
+ };
40
+ var OnMessageException = class extends Error {
41
+ constructor(cause, message, client, payload, type) {
42
+ super(message, { cause });
43
+ this.client = client;
44
+ this.payload = payload;
45
+ this.type = type;
46
+ this.name = "OnMessageException";
47
+ }
48
+ };
49
+ var SimulationIntervalException = class extends Error {
50
+ constructor(cause, message) {
51
+ super(message, { cause });
52
+ this.name = "SimulationIntervalException";
53
+ }
54
+ };
55
+ var TimedEventException = class extends Error {
56
+ constructor(cause, message, ...args) {
57
+ super(message, { cause });
58
+ this.name = "TimedEventException";
59
+ this.args = args;
60
+ }
61
+ };
62
+ export {
63
+ OnAuthException,
64
+ OnCreateException,
65
+ OnDisposeException,
66
+ OnJoinException,
67
+ OnLeaveException,
68
+ OnMessageException,
69
+ SimulationIntervalException,
70
+ TimedEventException
71
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/errors/RoomExceptions.ts"],
4
+ "sourcesContent": ["import type { Client } from '../Transport';\nimport type { ExtractAuthData, ExtractUserData, Room } from '../Room';\n\nexport type RoomException<R extends Room = Room> =\n OnCreateException<R> |\n OnAuthException<R> |\n OnJoinException<R> |\n OnLeaveException<R> |\n OnDisposeException |\n OnMessageException<R> |\n SimulationIntervalException |\n TimedEventException;\n\nexport class OnCreateException<R extends Room = Room> extends Error {\n constructor(\n cause: Error,\n message: string,\n public options: Parameters<R['onCreate']>[0],\n ) {\n super(message, { cause });\n this.name = 'OnCreateException';\n }\n}\n\nexport class OnAuthException<R extends Room = Room> extends Error {\n constructor(\n cause: Error,\n message: string,\n public client: Parameters<R['onAuth']>[0],\n public options: Parameters<R['onAuth']>[1],\n ) {\n super(message, { cause });\n this.name = 'OnAuthException';\n }\n}\n\nexport class OnJoinException<R extends Room = Room> extends Error {\n constructor(\n cause: Error,\n message: string,\n public client: Parameters<R['onJoin']>[0],\n public options: Parameters<R['onJoin']>[1],\n public auth: Parameters<R['onJoin']>[2],\n ) {\n super(message, { cause });\n this.name = 'OnJoinException';\n }\n}\n\nexport class OnLeaveException<R extends Room = Room> extends Error {\n constructor(\n cause: Error,\n message: string,\n public client: Parameters<R['onLeave']>[0],\n public consented: Parameters<R['onLeave']>[1],\n ) {\n super(message, { cause });\n this.name = 'OnLeaveException';\n }\n}\n\nexport class OnDisposeException extends Error {\n constructor(\n cause: Error,\n message: string,\n ) {\n super(message, { cause });\n this.name = 'OnDisposeException';\n }\n}\n\nexport class OnMessageException<R extends Room = Room, MessagePayload = any> extends Error {\n constructor(\n cause: Error,\n message: string,\n public client: Client<ExtractUserData<R['clients']>, ExtractAuthData<R['clients']>>,\n public payload: MessagePayload,\n public type: string,\n ) {\n super(message, { cause });\n this.name = 'OnMessageException';\n }\n}\n\nexport class SimulationIntervalException extends Error {\n constructor(\n cause: Error,\n message: string,\n ) {\n super(message, { cause });\n this.name = 'SimulationIntervalException';\n }\n}\n\nexport class TimedEventException extends Error {\n public args: any[];\n constructor(\n cause: Error,\n message: string,\n ...args: any[]\n ) {\n super(message, { cause });\n this.name = 'TimedEventException';\n this.args = args;\n }\n}"],
5
+ "mappings": ";AAaO,IAAM,oBAAN,cAAuD,MAAM;AAAA,EAClE,YACE,OACA,SACO,SACP;AACA,UAAM,SAAS,EAAE,MAAM,CAAC;AAFjB;AAGP,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,kBAAN,cAAqD,MAAM;AAAA,EAChE,YACE,OACA,SACO,QACA,SACP;AACA,UAAM,SAAS,EAAE,MAAM,CAAC;AAHjB;AACA;AAGP,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,kBAAN,cAAqD,MAAM;AAAA,EAChE,YACE,OACA,SACO,QACA,SACA,MACP;AACA,UAAM,SAAS,EAAE,MAAM,CAAC;AAJjB;AACA;AACA;AAGP,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,mBAAN,cAAsD,MAAM;AAAA,EACjE,YACE,OACA,SACO,QACA,WACP;AACA,UAAM,SAAS,EAAE,MAAM,CAAC;AAHjB;AACA;AAGP,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,qBAAN,cAAiC,MAAM;AAAA,EAC5C,YACE,OACA,SACA;AACA,UAAM,SAAS,EAAE,MAAM,CAAC;AACxB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,qBAAN,cAA8E,MAAM;AAAA,EACzF,YACE,OACA,SACO,QACA,SACA,MACP;AACA,UAAM,SAAS,EAAE,MAAM,CAAC;AAJjB;AACA;AACA;AAGP,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,8BAAN,cAA0C,MAAM;AAAA,EACrD,YACE,OACA,SACA;AACA,UAAM,SAAS,EAAE,MAAM,CAAC;AACxB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,sBAAN,cAAkC,MAAM;AAAA,EAE7C,YACE,OACA,YACG,MACH;AACA,UAAM,SAAS,EAAE,MAAM,CAAC;AACxB,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACd;AACF;",
6
+ "names": []
7
+ }
package/build/index.d.ts CHANGED
@@ -4,11 +4,12 @@ export { Room, RoomInternalState } from './Room.js';
4
4
  export { Protocol, ErrorCode, getMessageBytes } from './Protocol.js';
5
5
  export { RegisteredHandler } from './matchmaker/RegisteredHandler.js';
6
6
  export { ServerError } from './errors/ServerError.js';
7
+ export { RoomException, OnCreateException, OnAuthException, OnJoinException, OnLeaveException, OnDisposeException, OnMessageException, SimulationIntervalException, TimedEventException, } from './errors/RoomExceptions';
7
8
  import * as matchMaker from './MatchMaker.js';
8
9
  export { matchMaker };
9
10
  export { updateLobby, subscribeLobby } from './matchmaker/Lobby.js';
10
11
  export * from './matchmaker/driver/local/LocalDriver.js';
11
- export { type Client, type ClientPrivate, ClientState, ClientArray, Transport, type ISendOptions } from './Transport.js';
12
+ export { type Client, type ClientPrivate, type AuthContext, ClientState, ClientArray, Transport, type ISendOptions } from './Transport.js';
12
13
  export { type Presence } from './presence/Presence.js';
13
14
  export { LocalPresence } from './presence/LocalPresence.js';
14
15
  export { type Serializer } from './serializer/Serializer.js';
package/build/index.js CHANGED
@@ -37,15 +37,24 @@ __export(src_exports, {
37
37
  HttpServerMock: () => import_Utils.HttpServerMock,
38
38
  LobbyRoom: () => import_LobbyRoom.LobbyRoom,
39
39
  LocalPresence: () => import_LocalPresence.LocalPresence,
40
+ OnAuthException: () => import_RoomExceptions.OnAuthException,
41
+ OnCreateException: () => import_RoomExceptions.OnCreateException,
42
+ OnDisposeException: () => import_RoomExceptions.OnDisposeException,
43
+ OnJoinException: () => import_RoomExceptions.OnJoinException,
44
+ OnLeaveException: () => import_RoomExceptions.OnLeaveException,
45
+ OnMessageException: () => import_RoomExceptions.OnMessageException,
40
46
  Protocol: () => import_Protocol.Protocol,
41
47
  RegisteredHandler: () => import_RegisteredHandler.RegisteredHandler,
42
48
  RelayRoom: () => import_RelayRoom.RelayRoom,
43
49
  Room: () => import_Room.Room,
50
+ RoomException: () => import_RoomExceptions.RoomException,
44
51
  RoomInternalState: () => import_Room.RoomInternalState,
45
52
  SchemaSerializer: () => import_SchemaSerializer.SchemaSerializer,
46
53
  SchemaSerializerDebug: () => import_SchemaSerializerDebug.SchemaSerializerDebug,
47
54
  Server: () => import_Server.Server,
48
55
  ServerError: () => import_ServerError.ServerError,
56
+ SimulationIntervalException: () => import_RoomExceptions.SimulationIntervalException,
57
+ TimedEventException: () => import_RoomExceptions.TimedEventException,
49
58
  Transport: () => import_Transport.Transport,
50
59
  debugAndPrintError: () => import_Debug.debugAndPrintError,
51
60
  debugConnection: () => import_Debug.debugConnection,
@@ -74,6 +83,7 @@ var import_Room = require("./Room.js");
74
83
  var import_Protocol = require("./Protocol.js");
75
84
  var import_RegisteredHandler = require("./matchmaker/RegisteredHandler.js");
76
85
  var import_ServerError = require("./errors/ServerError.js");
86
+ var import_RoomExceptions = require("./errors/RoomExceptions");
77
87
  var matchMaker = __toESM(require("./MatchMaker.js"));
78
88
  var import_Lobby = require("./matchmaker/Lobby.js");
79
89
  __reExport(src_exports, require("./matchmaker/driver/local/LocalDriver.js"), module.exports);
@@ -99,15 +109,24 @@ var import_Logger = require("./Logger.js");
99
109
  HttpServerMock,
100
110
  LobbyRoom,
101
111
  LocalPresence,
112
+ OnAuthException,
113
+ OnCreateException,
114
+ OnDisposeException,
115
+ OnJoinException,
116
+ OnLeaveException,
117
+ OnMessageException,
102
118
  Protocol,
103
119
  RegisteredHandler,
104
120
  RelayRoom,
105
121
  Room,
122
+ RoomException,
106
123
  RoomInternalState,
107
124
  SchemaSerializer,
108
125
  SchemaSerializerDebug,
109
126
  Server,
110
127
  ServerError,
128
+ SimulationIntervalException,
129
+ TimedEventException,
111
130
  Transport,
112
131
  debugAndPrintError,
113
132
  debugConnection,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["import Clock, { Delayed } from '@colyseus/timer';\n\n// Core classes\nexport { Server, type ServerOptions } from './Server.js';\nexport { Room, RoomInternalState } from './Room.js';\nexport { Protocol, ErrorCode, getMessageBytes } from './Protocol.js';\nexport { RegisteredHandler } from './matchmaker/RegisteredHandler.js';\nexport { ServerError } from './errors/ServerError.js';\n\n// MatchMaker\nimport * as matchMaker from './MatchMaker.js';\nexport { matchMaker };\nexport { updateLobby, subscribeLobby } from './matchmaker/Lobby.js';\n\n// Driver\nexport * from './matchmaker/driver/local/LocalDriver.js';\n\n// Transport\nexport { type Client, type ClientPrivate, ClientState, ClientArray, Transport, type ISendOptions } from './Transport.js';\n\n// Presence\nexport { type Presence } from './presence/Presence.js';\nexport { LocalPresence } from './presence/LocalPresence.js';\n\n// Serializers\nexport { type Serializer } from './serializer/Serializer.js';\nexport { SchemaSerializer } from './serializer/SchemaSerializer.js';\nexport { SchemaSerializerDebug } from './serializer/SchemaSerializerDebug.js';\n\n// Utilities\nexport { Clock, Delayed };\nexport { generateId, Deferred, HttpServerMock, spliceOne, getBearerToken } from './utils/Utils.js';\nexport { isDevMode } from './utils/DevMode.js';\n\n// IPC\nexport { subscribeIPC, requestFromIPC } from './IPC.js';\n\n// Debug\nexport {\n debugMatchMaking,\n debugMessage,\n debugPatch,\n debugError,\n debugConnection,\n debugDriver,\n debugPresence,\n debugAndPrintError,\n} from './Debug';\n\n// Default rooms\nexport { LobbyRoom } from './rooms/LobbyRoom.js';\nexport { RelayRoom } from './rooms/RelayRoom.js';\n\n// Abstract logging support\nexport { logger } from './Logger.js';\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA+B;AAG/B,oBAA2C;AAC3C,kBAAwC;AACxC,sBAAqD;AACrD,+BAAkC;AAClC,yBAA4B;AAG5B,iBAA4B;AAE5B,mBAA4C;AAG5C,wBAAc,qDAfd;AAkBA,uBAAwG;AAIxG,2BAA8B;AAI9B,8BAAiC;AACjC,mCAAsC;AAItC,mBAAgF;AAChF,qBAA0B;AAG1B,iBAA6C;AAG7C,mBASO;AAGP,uBAA0B;AAC1B,uBAA0B;AAG1B,oBAAuB;",
4
+ "sourcesContent": ["import Clock, { Delayed } from '@colyseus/timer';\n\n// Core classes\nexport { Server, type ServerOptions } from './Server.js';\nexport { Room, RoomInternalState } from './Room.js';\nexport { Protocol, ErrorCode, getMessageBytes } from './Protocol.js';\nexport { RegisteredHandler } from './matchmaker/RegisteredHandler.js';\nexport { ServerError } from './errors/ServerError.js';\n\nexport {\n RoomException,\n OnCreateException,\n OnAuthException,\n OnJoinException,\n OnLeaveException,\n OnDisposeException,\n OnMessageException,\n SimulationIntervalException,\n TimedEventException,\n} from './errors/RoomExceptions';\n\n// MatchMaker\nimport * as matchMaker from './MatchMaker.js';\nexport { matchMaker };\nexport { updateLobby, subscribeLobby } from './matchmaker/Lobby.js';\n\n// Driver\nexport * from './matchmaker/driver/local/LocalDriver.js';\n\n// Transport\nexport { type Client, type ClientPrivate, type AuthContext, ClientState, ClientArray, Transport, type ISendOptions } from './Transport.js';\n\n// Presence\nexport { type Presence } from './presence/Presence.js';\nexport { LocalPresence } from './presence/LocalPresence.js';\n\n// Serializers\nexport { type Serializer } from './serializer/Serializer.js';\nexport { SchemaSerializer } from './serializer/SchemaSerializer.js';\nexport { SchemaSerializerDebug } from './serializer/SchemaSerializerDebug.js';\n\n// Utilities\nexport { Clock, Delayed };\nexport { generateId, Deferred, HttpServerMock, spliceOne, getBearerToken } from './utils/Utils.js';\nexport { isDevMode } from './utils/DevMode.js';\n\n// IPC\nexport { subscribeIPC, requestFromIPC } from './IPC.js';\n\n// Debug\nexport {\n debugMatchMaking,\n debugMessage,\n debugPatch,\n debugError,\n debugConnection,\n debugDriver,\n debugPresence,\n debugAndPrintError,\n} from './Debug';\n\n// Default rooms\nexport { LobbyRoom } from './rooms/LobbyRoom.js';\nexport { RelayRoom } from './rooms/RelayRoom.js';\n\n// Abstract logging support\nexport { logger } from './Logger.js';\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA+B;AAG/B,oBAA2C;AAC3C,kBAAwC;AACxC,sBAAqD;AACrD,+BAAkC;AAClC,yBAA4B;AAE5B,4BAUO;AAGP,iBAA4B;AAE5B,mBAA4C;AAG5C,wBAAc,qDA3Bd;AA8BA,uBAA0H;AAI1H,2BAA8B;AAI9B,8BAAiC;AACjC,mCAAsC;AAItC,mBAAgF;AAChF,qBAA0B;AAG1B,iBAA6C;AAG7C,mBASO;AAGP,uBAA0B;AAC1B,uBAA0B;AAG1B,oBAAuB;",
6
6
  "names": ["Clock"]
7
7
  }