@colyseus/core 0.15.1 → 0.15.2

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.
@@ -17,10 +17,12 @@ var __copyProps = (to, from, except, desc) => {
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
  var Transport_exports = {};
19
19
  __export(Transport_exports, {
20
+ ClientArray: () => ClientArray,
20
21
  ClientState: () => ClientState,
21
22
  Transport: () => Transport
22
23
  });
23
24
  module.exports = __toCommonJS(Transport_exports);
25
+ var import_Utils2 = require("./Utils");
24
26
  class Transport {
25
27
  server;
26
28
  }
@@ -31,8 +33,17 @@ var ClientState = /* @__PURE__ */ ((ClientState2) => {
31
33
  ClientState2[ClientState2["LEAVING"] = 3] = "LEAVING";
32
34
  return ClientState2;
33
35
  })(ClientState || {});
36
+ class ClientArray extends Array {
37
+ getById(sessionId) {
38
+ return this.find((client) => client.sessionId === sessionId);
39
+ }
40
+ delete(client) {
41
+ return (0, import_Utils2.spliceOne)(this, this.indexOf(client));
42
+ }
43
+ }
34
44
  // Annotate the CommonJS export names for ESM import in node:
35
45
  0 && (module.exports = {
46
+ ClientArray,
36
47
  ClientState,
37
48
  Transport
38
49
  });
@@ -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 } from '@colyseus/schema';\nimport { EventEmitter } from 'events';\nimport { DummyServer } from './utils/Utils';\n\nexport abstract class Transport {\n public server?: net.Server | http.Server | https.Server | DummyServer;\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 {\n readyState: number;\n\n id: string;\n /**\n * Unique id per session.\n */\n sessionId: string; // TODO: remove sessionId on version 1.0.0\n state: ClientState;\n\n ref: EventEmitter;\n\n upgradeReq?: http.IncomingMessage; // cross-compatibility for ws (v3.x+) and uws\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?: any;\n\n /**\n * auth data provided by your `onAuth`\n */\n auth?: any;\n pingCount?: number; // ping / pong\n\n _reconnectionToken: string;\n _enqueuedMessages?: any[];\n _afterNextPatchQueue: Array<[string | Client, IArguments]>;\n\n raw(data: ArrayLike<number>, options?: ISendOptions, cb?: (err?: Error) => void): void;\n enqueueRaw(data: ArrayLike<number>, 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: number[] | 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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQO,MAAe,UAAU;AAAA,EACrB;AAMX;AAMO,IAAK,cAAL,kBAAKA,iBAAL;AAAmB,EAAAA,0BAAA;AAAS,EAAAA,0BAAA;AAAQ,EAAAA,0BAAA;AAAa,EAAAA,0BAAA;AAA5C,SAAAA;AAAA,GAAA;",
6
- "names": ["ClientState"]
4
+ "sourcesContent": ["import * as http from 'http';\nimport * as https from 'https';\nimport * as net from 'net';\n\nimport { Schema } from '@colyseus/schema';\nimport { EventEmitter } from 'events';\nimport { DummyServer } from './utils/Utils';\nimport { spliceOne } from './Utils';\n\nexport abstract class Transport {\n public server?: net.Server | http.Server | https.Server | DummyServer;\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> {\n readyState: number;\n\n id: string;\n /**\n * Unique id per session.\n */\n sessionId: string; // TODO: remove sessionId on version 1.0.0\n state: ClientState;\n\n ref: EventEmitter;\n\n upgradeReq?: http.IncomingMessage; // cross-compatibility for ws (v3.x+) and uws\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?: any;\n pingCount?: number; // ping / pong\n\n _reconnectionToken: string;\n _enqueuedMessages?: any[];\n _afterNextPatchQueue: Array<[string | Client, IArguments]>;\n\n raw(data: ArrayLike<number>, options?: ISendOptions, cb?: (err?: Error) => void): void;\n enqueueRaw(data: ArrayLike<number>, 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: number[] | 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\nexport class ClientArray<UserData> extends Array<Client<UserData>> {\n public getById(sessionId: string): Client<UserData> | undefined {\n return this.find((client) => client.sessionId === sessionId);\n }\n\n public delete(client: Client<UserData>): boolean {\n return spliceOne(this, this.indexOf(client));\n }\n}"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,IAAAA,gBAA0B;AAEnB,MAAe,UAAU;AAAA,EACrB;AAMX;AAMO,IAAK,cAAL,kBAAKC,iBAAL;AAAmB,EAAAA,0BAAA;AAAS,EAAAA,0BAAA;AAAQ,EAAAA,0BAAA;AAAa,EAAAA,0BAAA;AAA5C,SAAAA;AAAA,GAAA;AAuFL,MAAM,oBAA8B,MAAwB;AAAA,EAC1D,QAAQ,WAAiD;AAC9D,WAAO,KAAK,KAAK,CAAC,WAAW,OAAO,cAAc,SAAS;AAAA,EAC7D;AAAA,EAEO,OAAO,QAAmC;AAC/C,eAAO,yBAAU,MAAM,KAAK,QAAQ,MAAM,CAAC;AAAA,EAC7C;AACF;",
6
+ "names": ["import_Utils", "ClientState"]
7
7
  }
@@ -1,3 +1,4 @@
1
+ import { spliceOne } from "./Utils";
1
2
  class Transport {
2
3
  server;
3
4
  }
@@ -8,7 +9,16 @@ var ClientState = /* @__PURE__ */ ((ClientState2) => {
8
9
  ClientState2[ClientState2["LEAVING"] = 3] = "LEAVING";
9
10
  return ClientState2;
10
11
  })(ClientState || {});
12
+ class ClientArray extends Array {
13
+ getById(sessionId) {
14
+ return this.find((client) => client.sessionId === sessionId);
15
+ }
16
+ delete(client) {
17
+ return spliceOne(this, this.indexOf(client));
18
+ }
19
+ }
11
20
  export {
21
+ ClientArray,
12
22
  ClientState,
13
23
  Transport
14
24
  };
@@ -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 } from '@colyseus/schema';\nimport { EventEmitter } from 'events';\nimport { DummyServer } from './utils/Utils';\n\nexport abstract class Transport {\n public server?: net.Server | http.Server | https.Server | DummyServer;\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 {\n readyState: number;\n\n id: string;\n /**\n * Unique id per session.\n */\n sessionId: string; // TODO: remove sessionId on version 1.0.0\n state: ClientState;\n\n ref: EventEmitter;\n\n upgradeReq?: http.IncomingMessage; // cross-compatibility for ws (v3.x+) and uws\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?: any;\n\n /**\n * auth data provided by your `onAuth`\n */\n auth?: any;\n pingCount?: number; // ping / pong\n\n _reconnectionToken: string;\n _enqueuedMessages?: any[];\n _afterNextPatchQueue: Array<[string | Client, IArguments]>;\n\n raw(data: ArrayLike<number>, options?: ISendOptions, cb?: (err?: Error) => void): void;\n enqueueRaw(data: ArrayLike<number>, 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: number[] | 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"],
5
- "mappings": "AAQO,MAAe,UAAU;AAAA,EACrB;AAMX;AAMO,IAAK,cAAL,kBAAKA,iBAAL;AAAmB,EAAAA,0BAAA;AAAS,EAAAA,0BAAA;AAAQ,EAAAA,0BAAA;AAAa,EAAAA,0BAAA;AAA5C,SAAAA;AAAA,GAAA;",
4
+ "sourcesContent": ["import * as http from 'http';\nimport * as https from 'https';\nimport * as net from 'net';\n\nimport { Schema } from '@colyseus/schema';\nimport { EventEmitter } from 'events';\nimport { DummyServer } from './utils/Utils';\nimport { spliceOne } from './Utils';\n\nexport abstract class Transport {\n public server?: net.Server | http.Server | https.Server | DummyServer;\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> {\n readyState: number;\n\n id: string;\n /**\n * Unique id per session.\n */\n sessionId: string; // TODO: remove sessionId on version 1.0.0\n state: ClientState;\n\n ref: EventEmitter;\n\n upgradeReq?: http.IncomingMessage; // cross-compatibility for ws (v3.x+) and uws\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?: any;\n pingCount?: number; // ping / pong\n\n _reconnectionToken: string;\n _enqueuedMessages?: any[];\n _afterNextPatchQueue: Array<[string | Client, IArguments]>;\n\n raw(data: ArrayLike<number>, options?: ISendOptions, cb?: (err?: Error) => void): void;\n enqueueRaw(data: ArrayLike<number>, 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: number[] | 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\nexport class ClientArray<UserData> extends Array<Client<UserData>> {\n public getById(sessionId: string): Client<UserData> | undefined {\n return this.find((client) => client.sessionId === sessionId);\n }\n\n public delete(client: Client<UserData>): boolean {\n return spliceOne(this, this.indexOf(client));\n }\n}"],
5
+ "mappings": "AAOA,SAAS,iBAAiB;AAEnB,MAAe,UAAU;AAAA,EACrB;AAMX;AAMO,IAAK,cAAL,kBAAKA,iBAAL;AAAmB,EAAAA,0BAAA;AAAS,EAAAA,0BAAA;AAAQ,EAAAA,0BAAA;AAAa,EAAAA,0BAAA;AAA5C,SAAAA;AAAA,GAAA;AAuFL,MAAM,oBAA8B,MAAwB;AAAA,EAC1D,QAAQ,WAAiD;AAC9D,WAAO,KAAK,KAAK,CAAC,WAAW,OAAO,cAAc,SAAS;AAAA,EAC7D;AAAA,EAEO,OAAO,QAAmC;AAC/C,WAAO,UAAU,MAAM,KAAK,QAAQ,MAAM,CAAC;AAAA,EAC7C;AACF;",
6
6
  "names": ["ClientState"]
7
7
  }
package/build/index.d.ts CHANGED
@@ -8,13 +8,13 @@ import * as matchMaker from './MatchMaker';
8
8
  export { matchMaker };
9
9
  export { updateLobby, subscribeLobby } from './matchmaker/Lobby';
10
10
  export * from './matchmaker/driver';
11
- export { Client, ClientState, Transport, ISendOptions } from './Transport';
11
+ export { Client, ClientState, ClientArray, Transport, ISendOptions } from './Transport';
12
12
  export { Presence } from './presence/Presence';
13
13
  export { LocalPresence } from './presence/LocalPresence';
14
14
  export { Serializer } from './serializer/Serializer';
15
15
  export { SchemaSerializer } from './serializer/SchemaSerializer';
16
16
  export { Clock, Delayed };
17
- export { generateId, Deferred, DummyServer, spliceOne, HybridArray } from './utils/Utils';
17
+ export { generateId, Deferred, DummyServer, spliceOne } from './utils/Utils';
18
18
  export { isDevMode } from './utils/DevMode';
19
19
  export { debugMatchMaking, debugMessage, debugPatch, debugError, debugConnection, debugDriver, debugPresence, debugAndPrintError, } from './Debug';
20
20
  export { LobbyRoom } from './rooms/LobbyRoom';
package/build/index.js CHANGED
@@ -25,13 +25,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
25
25
  var src_exports = {};
26
26
  __export(src_exports, {
27
27
  Client: () => import_Transport.Client,
28
+ ClientArray: () => import_Transport.ClientArray,
28
29
  ClientState: () => import_Transport.ClientState,
29
30
  Clock: () => import_timer.default,
30
31
  Deferred: () => import_Utils.Deferred,
31
32
  Delayed: () => import_timer.Delayed,
32
33
  DummyServer: () => import_Utils.DummyServer,
33
34
  ErrorCode: () => import_Protocol.ErrorCode,
34
- HybridArray: () => import_Utils.HybridArray,
35
35
  ISendOptions: () => import_Transport.ISendOptions,
36
36
  LobbyRoom: () => import_LobbyRoom.LobbyRoom,
37
37
  LocalPresence: () => import_LocalPresence.LocalPresence,
@@ -88,13 +88,13 @@ var import_Logger = require("./Logger");
88
88
  // Annotate the CommonJS export names for ESM import in node:
89
89
  0 && (module.exports = {
90
90
  Client,
91
+ ClientArray,
91
92
  ClientState,
92
93
  Clock,
93
94
  Deferred,
94
95
  Delayed,
95
96
  DummyServer,
96
97
  ErrorCode,
97
- HybridArray,
98
98
  ISendOptions,
99
99
  LobbyRoom,
100
100
  LocalPresence,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["import Clock, { Delayed } from '@gamestdio/timer';\n\n// Core classes\nexport { Server, ServerOptions } from './Server';\nexport { Room, RoomInternalState } from './Room';\nexport { Protocol, ErrorCode, getMessageBytes } from './Protocol';\nexport { RegisteredHandler } from './matchmaker/RegisteredHandler';\nexport { ServerError } from './errors/ServerError';\n\n// MatchMaker\nimport * as matchMaker from './MatchMaker';\nexport { matchMaker };\nexport { updateLobby, subscribeLobby } from './matchmaker/Lobby';\n\n// Driver\nexport * from './matchmaker/driver';\n\n// Transport\nexport { Client, ClientState, Transport, ISendOptions } from './Transport';\n\n// Presence\nexport { Presence } from './presence/Presence';\nexport { LocalPresence } from './presence/LocalPresence';\n\n// Serializers\nexport { Serializer } from './serializer/Serializer';\nexport { SchemaSerializer } from './serializer/SchemaSerializer';\n\n// Utilities\nexport { Clock, Delayed };\nexport { generateId, Deferred, DummyServer, spliceOne, HybridArray } from './utils/Utils';\nexport { isDevMode } from './utils/DevMode';\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';\nexport { RelayRoom } from './rooms/RelayRoom';\n\n// Abstract logging support\nexport { logger } from './Logger'\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,mBAA+B;AAG/B,oBAAsC;AACtC,kBAAwC;AACxC,sBAAqD;AACrD,+BAAkC;AAClC,yBAA4B;AAG5B,iBAA4B;AAE5B,mBAA4C;AAG5C,wBAAc,gCAfd;AAkBA,uBAA6D;AAG7D,sBAAyB;AACzB,2BAA8B;AAG9B,wBAA2B;AAC3B,8BAAiC;AAIjC,mBAA0E;AAC1E,qBAA0B;AAG1B,mBASO;AAGP,uBAA0B;AAC1B,uBAA0B;AAG1B,oBAAuB;",
4
+ "sourcesContent": ["import Clock, { Delayed } from '@gamestdio/timer';\n\n// Core classes\nexport { Server, ServerOptions } from './Server';\nexport { Room, RoomInternalState } from './Room';\nexport { Protocol, ErrorCode, getMessageBytes } from './Protocol';\nexport { RegisteredHandler } from './matchmaker/RegisteredHandler';\nexport { ServerError } from './errors/ServerError';\n\n// MatchMaker\nimport * as matchMaker from './MatchMaker';\nexport { matchMaker };\nexport { updateLobby, subscribeLobby } from './matchmaker/Lobby';\n\n// Driver\nexport * from './matchmaker/driver';\n\n// Transport\nexport { Client, ClientState, ClientArray, Transport, ISendOptions } from './Transport';\n\n// Presence\nexport { Presence } from './presence/Presence';\nexport { LocalPresence } from './presence/LocalPresence';\n\n// Serializers\nexport { Serializer } from './serializer/Serializer';\nexport { SchemaSerializer } from './serializer/SchemaSerializer';\n\n// Utilities\nexport { Clock, Delayed };\nexport { generateId, Deferred, DummyServer, spliceOne } from './utils/Utils';\nexport { isDevMode } from './utils/DevMode';\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';\nexport { RelayRoom } from './rooms/RelayRoom';\n\n// Abstract logging support\nexport { logger } from './Logger'\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;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,oBAAsC;AACtC,kBAAwC;AACxC,sBAAqD;AACrD,+BAAkC;AAClC,yBAA4B;AAG5B,iBAA4B;AAE5B,mBAA4C;AAG5C,wBAAc,gCAfd;AAkBA,uBAA0E;AAG1E,sBAAyB;AACzB,2BAA8B;AAG9B,wBAA2B;AAC3B,8BAAiC;AAIjC,mBAA6D;AAC7D,qBAA0B;AAG1B,mBASO;AAGP,uBAA0B;AAC1B,uBAA0B;AAG1B,oBAAuB;",
6
6
  "names": ["Clock"]
7
7
  }
package/build/index.mjs CHANGED
@@ -7,12 +7,12 @@ import { ServerError } from "./errors/ServerError";
7
7
  import * as matchMaker from "./MatchMaker";
8
8
  import { updateLobby, subscribeLobby } from "./matchmaker/Lobby";
9
9
  export * from "./matchmaker/driver";
10
- import { Client, ClientState, Transport, ISendOptions } from "./Transport";
10
+ import { Client, ClientState, ClientArray, Transport, ISendOptions } from "./Transport";
11
11
  import { Presence } from "./presence/Presence";
12
12
  import { LocalPresence } from "./presence/LocalPresence";
13
13
  import { Serializer } from "./serializer/Serializer";
14
14
  import { SchemaSerializer } from "./serializer/SchemaSerializer";
15
- import { generateId, Deferred, DummyServer, spliceOne, HybridArray } from "./utils/Utils";
15
+ import { generateId, Deferred, DummyServer, spliceOne } from "./utils/Utils";
16
16
  import { isDevMode } from "./utils/DevMode";
17
17
  import {
18
18
  debugMatchMaking,
@@ -29,13 +29,13 @@ import { RelayRoom } from "./rooms/RelayRoom";
29
29
  import { logger } from "./Logger";
30
30
  export {
31
31
  Client,
32
+ ClientArray,
32
33
  ClientState,
33
34
  Clock,
34
35
  Deferred,
35
36
  Delayed,
36
37
  DummyServer,
37
38
  ErrorCode,
38
- HybridArray,
39
39
  ISendOptions,
40
40
  LobbyRoom,
41
41
  LocalPresence,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["import Clock, { Delayed } from '@gamestdio/timer';\n\n// Core classes\nexport { Server, ServerOptions } from './Server';\nexport { Room, RoomInternalState } from './Room';\nexport { Protocol, ErrorCode, getMessageBytes } from './Protocol';\nexport { RegisteredHandler } from './matchmaker/RegisteredHandler';\nexport { ServerError } from './errors/ServerError';\n\n// MatchMaker\nimport * as matchMaker from './MatchMaker';\nexport { matchMaker };\nexport { updateLobby, subscribeLobby } from './matchmaker/Lobby';\n\n// Driver\nexport * from './matchmaker/driver';\n\n// Transport\nexport { Client, ClientState, Transport, ISendOptions } from './Transport';\n\n// Presence\nexport { Presence } from './presence/Presence';\nexport { LocalPresence } from './presence/LocalPresence';\n\n// Serializers\nexport { Serializer } from './serializer/Serializer';\nexport { SchemaSerializer } from './serializer/SchemaSerializer';\n\n// Utilities\nexport { Clock, Delayed };\nexport { generateId, Deferred, DummyServer, spliceOne, HybridArray } from './utils/Utils';\nexport { isDevMode } from './utils/DevMode';\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';\nexport { RelayRoom } from './rooms/RelayRoom';\n\n// Abstract logging support\nexport { logger } from './Logger'\n"],
5
- "mappings": "AAAA,OAAO,SAAS,eAAe;AAG/B,SAAS,QAAQ,qBAAqB;AACtC,SAAS,MAAM,yBAAyB;AACxC,SAAS,UAAU,WAAW,uBAAuB;AACrD,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAG5B,YAAY,gBAAgB;AAE5B,SAAS,aAAa,sBAAsB;AAG5C,cAAc;AAGd,SAAS,QAAQ,aAAa,WAAW,oBAAoB;AAG7D,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAG9B,SAAS,kBAAkB;AAC3B,SAAS,wBAAwB;AAIjC,SAAS,YAAY,UAAU,aAAa,WAAW,mBAAmB;AAC1E,SAAS,iBAAiB;AAG1B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAG1B,SAAS,cAAc;",
4
+ "sourcesContent": ["import Clock, { Delayed } from '@gamestdio/timer';\n\n// Core classes\nexport { Server, ServerOptions } from './Server';\nexport { Room, RoomInternalState } from './Room';\nexport { Protocol, ErrorCode, getMessageBytes } from './Protocol';\nexport { RegisteredHandler } from './matchmaker/RegisteredHandler';\nexport { ServerError } from './errors/ServerError';\n\n// MatchMaker\nimport * as matchMaker from './MatchMaker';\nexport { matchMaker };\nexport { updateLobby, subscribeLobby } from './matchmaker/Lobby';\n\n// Driver\nexport * from './matchmaker/driver';\n\n// Transport\nexport { Client, ClientState, ClientArray, Transport, ISendOptions } from './Transport';\n\n// Presence\nexport { Presence } from './presence/Presence';\nexport { LocalPresence } from './presence/LocalPresence';\n\n// Serializers\nexport { Serializer } from './serializer/Serializer';\nexport { SchemaSerializer } from './serializer/SchemaSerializer';\n\n// Utilities\nexport { Clock, Delayed };\nexport { generateId, Deferred, DummyServer, spliceOne } from './utils/Utils';\nexport { isDevMode } from './utils/DevMode';\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';\nexport { RelayRoom } from './rooms/RelayRoom';\n\n// Abstract logging support\nexport { logger } from './Logger'\n"],
5
+ "mappings": "AAAA,OAAO,SAAS,eAAe;AAG/B,SAAS,QAAQ,qBAAqB;AACtC,SAAS,MAAM,yBAAyB;AACxC,SAAS,UAAU,WAAW,uBAAuB;AACrD,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAG5B,YAAY,gBAAgB;AAE5B,SAAS,aAAa,sBAAsB;AAG5C,cAAc;AAGd,SAAS,QAAQ,aAAa,aAAa,WAAW,oBAAoB;AAG1E,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAG9B,SAAS,kBAAkB;AAC3B,SAAS,wBAAwB;AAIjC,SAAS,YAAY,UAAU,aAAa,iBAAiB;AAC7D,SAAS,iBAAiB;AAG1B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAG1B,SAAS,cAAc;",
6
6
  "names": []
7
7
  }
@@ -16,31 +16,6 @@ export declare class Deferred<T = any> {
16
16
  catch(func: (value: any) => any): Promise<any>;
17
17
  }
18
18
  export declare function merge(a: any, ...objs: any[]): any;
19
- export declare class HybridArray<T> {
20
- uniqueProperty: string;
21
- hashedArray: {
22
- [key: string]: T;
23
- };
24
- array: T[];
25
- constructor(uniquePropertyName: string, items?: T[]);
26
- get length(): number;
27
- add(item: T): void;
28
- at(index: number): T | undefined;
29
- concat(items: T[]): this;
30
- find<S extends T>(predicate: (this: void, value: T, index: number, obj: T[]) => value is S, thisArg?: any): S;
31
- find(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): T;
32
- filter(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): T[];
33
- forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void;
34
- get(key: string): T | undefined;
35
- includes(element: T): boolean;
36
- indexOf(element: T): number;
37
- map<U>(callback: (value: T, index: number, array: T[]) => U): U[];
38
- deleteAt(index: number): T;
39
- deleteByKey(key: string): T;
40
- delete(obj: T): T;
41
- private _badIndexWarning;
42
- private spliceOne;
43
- }
44
19
  export declare interface DummyServer {
45
20
  constructor(options?: ServerOpts, connectionListener?: (socket: Socket) => void): any;
46
21
  listen(port?: number, hostname?: string, backlog?: number, listeningListener?: () => void): this;
@@ -25,7 +25,6 @@ var Utils_exports = {};
25
25
  __export(Utils_exports, {
26
26
  Deferred: () => Deferred,
27
27
  DummyServer: () => DummyServer,
28
- HybridArray: () => HybridArray,
29
28
  REMOTE_ROOM_SHORT_TIMEOUT: () => REMOTE_ROOM_SHORT_TIMEOUT,
30
29
  generateId: () => generateId,
31
30
  merge: () => merge,
@@ -38,7 +37,6 @@ var import_nanoid = __toESM(require("nanoid"));
38
37
  var import_msgpackr = require("msgpackr");
39
38
  var import_Debug = require("../Debug");
40
39
  var import_events = require("events");
41
- var import_Logger = require("../Logger");
42
40
  var import_schema = require("@colyseus/schema");
43
41
  const REMOTE_ROOM_SHORT_TIMEOUT = Number(process.env.COLYSEUS_PRESENCE_SHORT_TIMEOUT || 2e3);
44
42
  function generateId(length = 9) {
@@ -104,117 +102,6 @@ function merge(a, ...objs) {
104
102
  }
105
103
  return a;
106
104
  }
107
- class HybridArray {
108
- uniqueProperty;
109
- hashedArray = {};
110
- array = [];
111
- constructor(uniquePropertyName, items) {
112
- this.uniqueProperty = uniquePropertyName;
113
- if (items) {
114
- this.array = this.array.concat(items);
115
- for (const element of items) {
116
- this.hashedArray[element[this.uniqueProperty]] = element;
117
- }
118
- }
119
- }
120
- get length() {
121
- return this.array.length;
122
- }
123
- add(item) {
124
- if (!this.hashedArray[item[this.uniqueProperty]]) {
125
- this.array.push(item);
126
- this.hashedArray[item[this.uniqueProperty]] = item;
127
- } else {
128
- import_Logger.logger.warn(`.add(): element already exists:`, item[this.uniqueProperty]);
129
- }
130
- }
131
- at(index) {
132
- if (index >= this.array.length) {
133
- this._badIndexWarning(index);
134
- } else {
135
- return this.array[index];
136
- }
137
- }
138
- concat(items) {
139
- if (items) {
140
- for (const item of items) {
141
- this.hashedArray[item[this.uniqueProperty]] = item;
142
- }
143
- this.array.concat(items);
144
- }
145
- return this;
146
- }
147
- find(predicate, thisArg) {
148
- return this.array.find(predicate, thisArg);
149
- }
150
- filter(predicate, thisArg) {
151
- return this.array.filter(predicate, thisArg);
152
- }
153
- forEach(callbackfn, thisArg) {
154
- Array.prototype.forEach.call(this.array, callbackfn);
155
- }
156
- get(key) {
157
- return this.hashedArray[key];
158
- }
159
- includes(element) {
160
- return this.hashedArray[element[this.uniqueProperty]] !== void 0;
161
- }
162
- indexOf(element) {
163
- return this.array.indexOf(element);
164
- }
165
- map(callback) {
166
- const result = [];
167
- for (let index = 0; index < this.array.length; index++) {
168
- result.push(callback(this.array[index], index, this.array));
169
- }
170
- return result;
171
- }
172
- deleteAt(index) {
173
- if (index >= this.array.length) {
174
- this._badIndexWarning(index);
175
- return void 0;
176
- } else {
177
- const removable = this.spliceOne(index);
178
- delete this.hashedArray[removable[this.uniqueProperty]];
179
- return removable;
180
- }
181
- }
182
- deleteByKey(key) {
183
- if (!this.hashedArray[key]) {
184
- import_Logger.logger.error(`deleteByKey(): no such element for '${key}'.`);
185
- return void 0;
186
- } else {
187
- const removable = this.spliceOne(this.indexOf(this.hashedArray[key]));
188
- delete this.hashedArray[key];
189
- return removable;
190
- }
191
- }
192
- delete(obj) {
193
- if (this.hashedArray[obj[this.uniqueProperty]]) {
194
- return this.deleteByKey(obj[this.uniqueProperty]);
195
- } else if (this.indexOf(obj) != -1) {
196
- return this.deleteAt(this.indexOf(obj));
197
- } else {
198
- return void 0;
199
- }
200
- }
201
- _badIndexWarning(index) {
202
- import_Logger.logger.warn(`Index out of range, index: ${index}`);
203
- }
204
- spliceOne(index) {
205
- if (index === -1 || index >= this.array.length) {
206
- this._badIndexWarning(index);
207
- return void 0;
208
- }
209
- const itemRemoved = this.array[index];
210
- const len = this.array.length - 1;
211
- for (let i = index; i < len; i++) {
212
- this.array[i] = this.array[i + 1];
213
- }
214
- this.array.length = len;
215
- return itemRemoved;
216
- }
217
- }
218
105
  class DummyServer extends import_events.EventEmitter {
219
106
  }
220
107
  (0, import_msgpackr.addExtension)({
@@ -231,7 +118,6 @@ class DummyServer extends import_events.EventEmitter {
231
118
  0 && (module.exports = {
232
119
  Deferred,
233
120
  DummyServer,
234
- HybridArray,
235
121
  REMOTE_ROOM_SHORT_TIMEOUT,
236
122
  generateId,
237
123
  merge,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/Utils.ts"],
4
- "sourcesContent": ["import nanoid from 'nanoid';\nimport { addExtension } from 'msgpackr';\n\nimport { debugAndPrintError } from '../Debug';\nimport { EventEmitter } from \"events\";\nimport { ServerOpts, Socket } from \"net\";\nimport { logger } from '../Logger';\nimport { Schema } from \"@colyseus/schema\";\n\n// remote room call timeouts\nexport const REMOTE_ROOM_SHORT_TIMEOUT = Number(process.env.COLYSEUS_PRESENCE_SHORT_TIMEOUT || 2000);\n\nexport function generateId(length: number = 9) {\n return nanoid(length);\n}\n\n//\n// nodemon sends SIGUSR2 before reloading\n// (https://github.com/remy/nodemon#controlling-shutdown-of-your-script)\n//\nconst signals: NodeJS.Signals[] = ['SIGINT', 'SIGTERM', 'SIGUSR2'];\n\nexport function registerGracefulShutdown(callback: (err?: Error) => void) {\n /**\n * Gracefully shutdown on uncaught errors\n */\n process.on('uncaughtException', (err) => {\n debugAndPrintError(err);\n callback(err);\n });\n\n signals.forEach((signal) =>\n process.once(signal, () => callback()));\n}\n\nexport function retry<T = any>(\n cb: Function,\n maxRetries: number = 3,\n errorWhiteList: any[] = [],\n retries: number = 0,\n) {\n return new Promise<T>((resolve, reject) => {\n cb()\n .then(resolve)\n .catch((e) => {\n if (\n errorWhiteList.indexOf(e.constructor) !== -1 &&\n retries++ < maxRetries\n ) {\n setTimeout(() => {\n retry<T>(cb, maxRetries, errorWhiteList, retries).\n then(resolve).\n catch((e2) => reject(e2));\n }, Math.floor(Math.random() * Math.pow(2, retries) * 400));\n\n } else {\n reject(e);\n }\n });\n });\n}\n\nexport function spliceOne(arr: any[], index: number): boolean {\n // manually splice availableRooms array\n // http://jsperf.com/manual-splice\n if (index === -1 || index >= arr.length) {\n return false;\n }\n\n const len = arr.length - 1;\n for (let i = index; i < len; i++) {\n arr[i] = arr[i + 1];\n }\n\n arr.length = len;\n return true;\n}\n\nexport class Deferred<T= any> {\n public promise: Promise<T>;\n\n public resolve: Function;\n public reject: Function;\n\n constructor() {\n this.promise = new Promise<T>((resolve, reject) => {\n this.resolve = resolve;\n this.reject = reject;\n });\n }\n\n public then(func: (value: T) => any) {\n return this.promise.then.apply(this.promise, arguments);\n }\n\n public catch(func: (value: any) => any) {\n return this.promise.catch(func);\n }\n\n}\n\nexport function merge(a: any, ...objs: any[]): any {\n for (let i = 0, len = objs.length; i < len; i++) {\n const b = objs[i];\n for (const key in b) {\n if (b.hasOwnProperty(key)) {\n a[key] = b[key];\n }\n }\n }\n return a;\n}\n\nexport class HybridArray<T> {\n public uniqueProperty: string;\n public hashedArray: { [key: string]: T } = {};\n public array: T[] = [];\n\n constructor(uniquePropertyName: string, items?: T[]) {\n this.uniqueProperty = uniquePropertyName;\n if (items) {\n this.array = this.array.concat(items);\n for (const element of items) {\n this.hashedArray[element[this.uniqueProperty]] = element;\n }\n }\n }\n\n public get length(): number {\n return this.array.length;\n }\n\n public add(item: T) {\n if (!this.hashedArray[item[this.uniqueProperty]]) {\n this.array.push(item);\n this.hashedArray[item[this.uniqueProperty]] = item;\n\n } else {\n logger.warn(`.add(): element already exists:`, item[this.uniqueProperty]);\n }\n }\n\n public at(index: number): T | undefined {\n if (index >= this.array.length) {\n this._badIndexWarning(index);\n\n } else {\n return this.array[index];\n }\n }\n\n public concat(items: T[]) {\n if (items) {\n for (const item of items) {\n this.hashedArray[item[this.uniqueProperty]] = item;\n }\n this.array.concat(items);\n }\n return this;\n }\n\n public find<S extends T>(predicate: (this: void, value: T, index: number, obj: T[]) => value is S, thisArg?: any): S;\n public find(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): T;\n public find(predicate: any, thisArg?: any): T | undefined {\n return this.array.find(predicate, thisArg);\n }\n\n public filter(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): T[]\n public filter<S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[] {\n return this.array.filter(predicate, thisArg);\n }\n\n public forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void {\n Array.prototype.forEach.call(this.array, callbackfn);\n }\n\n public get(key: string): T | undefined {\n return this.hashedArray[key];\n }\n\n public includes(element: T) {\n return this.hashedArray[element[this.uniqueProperty]] !== undefined;\n }\n\n public indexOf(element: T): number {\n return this.array.indexOf(element);\n }\n\n public map<U>(callback: (value: T, index: number, array: T[]) => U) {\n const result: U[] = [];\n for (let index = 0; index < this.array.length; index++) {\n result.push(callback(this.array[index], index, this.array));\n }\n return result;\n }\n\n public deleteAt(index: number) {\n if (index >= this.array.length) {\n this._badIndexWarning(index);\n return undefined;\n\n } else {\n const removable = this.spliceOne(index);\n delete this.hashedArray[removable[this.uniqueProperty]];\n return removable;\n }\n }\n\n public deleteByKey(key: string): T {\n if (!this.hashedArray[key]) {\n logger.error(`deleteByKey(): no such element for '${key}'.`);\n return undefined;\n } else {\n const removable = this.spliceOne(this.indexOf(this.hashedArray[key]));\n delete this.hashedArray[key];\n return removable;\n }\n }\n\n public delete(obj: T): T {\n if (this.hashedArray[obj[this.uniqueProperty]]) {\n return this.deleteByKey(obj[this.uniqueProperty]);\n\n } else if (this.indexOf(obj) != -1) {\n return this.deleteAt(this.indexOf(obj));\n\n } else {\n return undefined;\n }\n }\n\n private _badIndexWarning(index) {\n logger.warn(`Index out of range, index: ${index}`);\n }\n\n private spliceOne(index: number): T {\n // manually splice availableRooms array\n // http://jsperf.com/manual-splice\n if (index === -1 || index >= this.array.length) {\n this._badIndexWarning(index);\n return undefined;\n }\n\n const itemRemoved = this.array[index];\n\n const len = this.array.length - 1;\n for (let i = index; i < len; i++) {\n this.array[i] = this.array[i + 1];\n }\n this.array.length = len;\n\n return itemRemoved;\n }\n}\n\nexport declare interface DummyServer {\n constructor(options?: ServerOpts, connectionListener?: (socket: Socket) => void);\n\n listen(port?: number, hostname?: string, backlog?: number, listeningListener?: () => void): this;\n close(callback?: (err?: Error) => void): this;\n}\n\nexport class DummyServer extends EventEmitter {}\n\n// Add msgpackr extension to avoid circular references when encoding\n// https://github.com/kriszyp/msgpackr#custom-extensions\naddExtension({\n Class: Schema,\n type: 0,\n\n read(datum: any): any {\n return datum;\n },\n\n write(instance: any): any {\n return instance.toJSON();\n }\n});\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmB;AACnB,sBAA6B;AAE7B,mBAAmC;AACnC,oBAA6B;AAE7B,oBAAuB;AACvB,oBAAuB;AAGhB,MAAM,4BAA4B,OAAO,QAAQ,IAAI,mCAAmC,GAAI;AAE5F,SAAS,WAAW,SAAiB,GAAG;AAC7C,aAAO,cAAAA,SAAO,MAAM;AACtB;AAMA,MAAM,UAA4B,CAAC,UAAU,WAAW,SAAS;AAE1D,SAAS,yBAAyB,UAAiC;AAIxE,UAAQ,GAAG,qBAAqB,CAAC,QAAQ;AACvC,yCAAmB,GAAG;AACtB,aAAS,GAAG;AAAA,EACd,CAAC;AAED,UAAQ,QAAQ,CAAC,WACf,QAAQ,KAAK,QAAQ,MAAM,SAAS,CAAC,CAAC;AAC1C;AAEO,SAAS,MACd,IACA,aAAqB,GACrB,iBAAwB,CAAC,GACzB,UAAkB,GAClB;AACA,SAAO,IAAI,QAAW,CAAC,SAAS,WAAW;AACzC,OAAG,EACA,KAAK,OAAO,EACZ,MAAM,CAAC,MAAM;AACZ,UACE,eAAe,QAAQ,EAAE,WAAW,MAAM,MAC1C,YAAY,YACZ;AACA,mBAAW,MAAM;AACf,gBAAS,IAAI,YAA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K,MAAM;AAE/B,UAAM,MAAM,KAAK,MAAM,SAAS;AAChC,aAAS,IAAI,OAAO,IAAI,KAAK,KAAK;AAChC,WAAK,MAAM,KAAK,KAAK,MAAM,IAAI;AAAA,IACjC;AACA,SAAK,MAAM,SAAS;AAEpB,WAAO;AAAA,EACT;AACF;AASO,MAAM,oBAAoB,2BAAa;AAAC;AAAA,IAI/C,8BAAa;AAAA,EACX,OAAO;AAAA,EACP,MAAM;AAAA,EAEN,KAAK,OAAiB;AACpB,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,UAAoB;AACxB,WAAO,SAAS,OAAO;AAAA,EACzB;AACF,CAAC;",
4
+ "sourcesContent": ["import nanoid from 'nanoid';\nimport { addExtension } from 'msgpackr';\n\nimport { debugAndPrintError } from '../Debug';\nimport { EventEmitter } from \"events\";\nimport { ServerOpts, Socket } from \"net\";\nimport { logger } from '../Logger';\nimport { Schema } from \"@colyseus/schema\";\n\n// remote room call timeouts\nexport const REMOTE_ROOM_SHORT_TIMEOUT = Number(process.env.COLYSEUS_PRESENCE_SHORT_TIMEOUT || 2000);\n\nexport function generateId(length: number = 9) {\n return nanoid(length);\n}\n\n//\n// nodemon sends SIGUSR2 before reloading\n// (https://github.com/remy/nodemon#controlling-shutdown-of-your-script)\n//\nconst signals: NodeJS.Signals[] = ['SIGINT', 'SIGTERM', 'SIGUSR2'];\n\nexport function registerGracefulShutdown(callback: (err?: Error) => void) {\n /**\n * Gracefully shutdown on uncaught errors\n */\n process.on('uncaughtException', (err) => {\n debugAndPrintError(err);\n callback(err);\n });\n\n signals.forEach((signal) =>\n process.once(signal, () => callback()));\n}\n\nexport function retry<T = any>(\n cb: Function,\n maxRetries: number = 3,\n errorWhiteList: any[] = [],\n retries: number = 0,\n) {\n return new Promise<T>((resolve, reject) => {\n cb()\n .then(resolve)\n .catch((e) => {\n if (\n errorWhiteList.indexOf(e.constructor) !== -1 &&\n retries++ < maxRetries\n ) {\n setTimeout(() => {\n retry<T>(cb, maxRetries, errorWhiteList, retries).\n then(resolve).\n catch((e2) => reject(e2));\n }, Math.floor(Math.random() * Math.pow(2, retries) * 400));\n\n } else {\n reject(e);\n }\n });\n });\n}\n\nexport function spliceOne(arr: any[], index: number): boolean {\n // manually splice availableRooms array\n // http://jsperf.com/manual-splice\n if (index === -1 || index >= arr.length) {\n return false;\n }\n\n const len = arr.length - 1;\n for (let i = index; i < len; i++) {\n arr[i] = arr[i + 1];\n }\n\n arr.length = len;\n return true;\n}\n\nexport class Deferred<T= any> {\n public promise: Promise<T>;\n\n public resolve: Function;\n public reject: Function;\n\n constructor() {\n this.promise = new Promise<T>((resolve, reject) => {\n this.resolve = resolve;\n this.reject = reject;\n });\n }\n\n public then(func: (value: T) => any) {\n return this.promise.then.apply(this.promise, arguments);\n }\n\n public catch(func: (value: any) => any) {\n return this.promise.catch(func);\n }\n\n}\n\nexport function merge(a: any, ...objs: any[]): any {\n for (let i = 0, len = objs.length; i < len; i++) {\n const b = objs[i];\n for (const key in b) {\n if (b.hasOwnProperty(key)) {\n a[key] = b[key];\n }\n }\n }\n return a;\n}\n\nexport declare interface DummyServer {\n constructor(options?: ServerOpts, connectionListener?: (socket: Socket) => void);\n\n listen(port?: number, hostname?: string, backlog?: number, listeningListener?: () => void): this;\n close(callback?: (err?: Error) => void): this;\n}\n\nexport class DummyServer extends EventEmitter {}\n\n// Add msgpackr extension to avoid circular references when encoding\n// https://github.com/kriszyp/msgpackr#custom-extensions\naddExtension({\n Class: Schema,\n type: 0,\n\n read(datum: any): any {\n return datum;\n },\n\n write(instance: any): any {\n return instance.toJSON();\n }\n});\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmB;AACnB,sBAA6B;AAE7B,mBAAmC;AACnC,oBAA6B;AAG7B,oBAAuB;AAGhB,MAAM,4BAA4B,OAAO,QAAQ,IAAI,mCAAmC,GAAI;A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AK,SAAS;AAAA,IAChB,CAAC;AAAA,EACH;AAAA,EAEO,KAAK,MAAyB;AACnC,WAAO,KAAK,QAAQ,KAAK,MAAM,KAAK,SAAS,SAAS;AAAA,EACxD;AAAA,EAEO,MAAM,MAA2B;AACtC,WAAO,KAAK,QAAQ,MAAM,IAAI;AAAA,EAChC;AAEF;AAEO,SAAS,MAAM,MAAW,MAAkB;AACjD,WAAS,IAAI,GAAG,MAAM,KAAK,QAAQ,IAAI,KAAK,KAAK;AAC/C,UAAM,IAAI,KAAK;AACf,eAAW,OAAO,GAAG;AACnB,UAAI,EAAE,eAAe,GAAG,GAAG;AACzB,UAAE,OAAO,EAAE;AAAA,MACb;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AASO,MAAM,oBAAoB,2BAAa;AAAC;AAAA,IAI/C,8BAAa;AAAA,EACX,OAAO;AAAA,EACP,MAAM;AAAA,EAEN,KAAK,OAAiB;AACpB,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,UAAoB;AACxB,WAAO,SAAS,OAAO;AAAA,EACzB;AACF,CAAC;",
6
6
  "names": ["nanoid"]
7
7
  }
@@ -2,7 +2,6 @@ import nanoid from "nanoid";
2
2
  import { addExtension } from "msgpackr";
3
3
  import { debugAndPrintError } from "../Debug";
4
4
  import { EventEmitter } from "events";
5
- import { logger } from "../Logger";
6
5
  import { Schema } from "@colyseus/schema";
7
6
  const REMOTE_ROOM_SHORT_TIMEOUT = Number(process.env.COLYSEUS_PRESENCE_SHORT_TIMEOUT || 2e3);
8
7
  function generateId(length = 9) {
@@ -68,117 +67,6 @@ function merge(a, ...objs) {
68
67
  }
69
68
  return a;
70
69
  }
71
- class HybridArray {
72
- uniqueProperty;
73
- hashedArray = {};
74
- array = [];
75
- constructor(uniquePropertyName, items) {
76
- this.uniqueProperty = uniquePropertyName;
77
- if (items) {
78
- this.array = this.array.concat(items);
79
- for (const element of items) {
80
- this.hashedArray[element[this.uniqueProperty]] = element;
81
- }
82
- }
83
- }
84
- get length() {
85
- return this.array.length;
86
- }
87
- add(item) {
88
- if (!this.hashedArray[item[this.uniqueProperty]]) {
89
- this.array.push(item);
90
- this.hashedArray[item[this.uniqueProperty]] = item;
91
- } else {
92
- logger.warn(`.add(): element already exists:`, item[this.uniqueProperty]);
93
- }
94
- }
95
- at(index) {
96
- if (index >= this.array.length) {
97
- this._badIndexWarning(index);
98
- } else {
99
- return this.array[index];
100
- }
101
- }
102
- concat(items) {
103
- if (items) {
104
- for (const item of items) {
105
- this.hashedArray[item[this.uniqueProperty]] = item;
106
- }
107
- this.array.concat(items);
108
- }
109
- return this;
110
- }
111
- find(predicate, thisArg) {
112
- return this.array.find(predicate, thisArg);
113
- }
114
- filter(predicate, thisArg) {
115
- return this.array.filter(predicate, thisArg);
116
- }
117
- forEach(callbackfn, thisArg) {
118
- Array.prototype.forEach.call(this.array, callbackfn);
119
- }
120
- get(key) {
121
- return this.hashedArray[key];
122
- }
123
- includes(element) {
124
- return this.hashedArray[element[this.uniqueProperty]] !== void 0;
125
- }
126
- indexOf(element) {
127
- return this.array.indexOf(element);
128
- }
129
- map(callback) {
130
- const result = [];
131
- for (let index = 0; index < this.array.length; index++) {
132
- result.push(callback(this.array[index], index, this.array));
133
- }
134
- return result;
135
- }
136
- deleteAt(index) {
137
- if (index >= this.array.length) {
138
- this._badIndexWarning(index);
139
- return void 0;
140
- } else {
141
- const removable = this.spliceOne(index);
142
- delete this.hashedArray[removable[this.uniqueProperty]];
143
- return removable;
144
- }
145
- }
146
- deleteByKey(key) {
147
- if (!this.hashedArray[key]) {
148
- logger.error(`deleteByKey(): no such element for '${key}'.`);
149
- return void 0;
150
- } else {
151
- const removable = this.spliceOne(this.indexOf(this.hashedArray[key]));
152
- delete this.hashedArray[key];
153
- return removable;
154
- }
155
- }
156
- delete(obj) {
157
- if (this.hashedArray[obj[this.uniqueProperty]]) {
158
- return this.deleteByKey(obj[this.uniqueProperty]);
159
- } else if (this.indexOf(obj) != -1) {
160
- return this.deleteAt(this.indexOf(obj));
161
- } else {
162
- return void 0;
163
- }
164
- }
165
- _badIndexWarning(index) {
166
- logger.warn(`Index out of range, index: ${index}`);
167
- }
168
- spliceOne(index) {
169
- if (index === -1 || index >= this.array.length) {
170
- this._badIndexWarning(index);
171
- return void 0;
172
- }
173
- const itemRemoved = this.array[index];
174
- const len = this.array.length - 1;
175
- for (let i = index; i < len; i++) {
176
- this.array[i] = this.array[i + 1];
177
- }
178
- this.array.length = len;
179
- return itemRemoved;
180
- }
181
- }
182
70
  class DummyServer extends EventEmitter {
183
71
  }
184
72
  addExtension({
@@ -194,7 +82,6 @@ addExtension({
194
82
  export {
195
83
  Deferred,
196
84
  DummyServer,
197
- HybridArray,
198
85
  REMOTE_ROOM_SHORT_TIMEOUT,
199
86
  generateId,
200
87
  merge,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/Utils.ts"],
4
- "sourcesContent": ["import nanoid from 'nanoid';\nimport { addExtension } from 'msgpackr';\n\nimport { debugAndPrintError } from '../Debug';\nimport { EventEmitter } from \"events\";\nimport { ServerOpts, Socket } from \"net\";\nimport { logger } from '../Logger';\nimport { Schema } from \"@colyseus/schema\";\n\n// remote room call timeouts\nexport const REMOTE_ROOM_SHORT_TIMEOUT = Number(process.env.COLYSEUS_PRESENCE_SHORT_TIMEOUT || 2000);\n\nexport function generateId(length: number = 9) {\n return nanoid(length);\n}\n\n//\n// nodemon sends SIGUSR2 before reloading\n// (https://github.com/remy/nodemon#controlling-shutdown-of-your-script)\n//\nconst signals: NodeJS.Signals[] = ['SIGINT', 'SIGTERM', 'SIGUSR2'];\n\nexport function registerGracefulShutdown(callback: (err?: Error) => void) {\n /**\n * Gracefully shutdown on uncaught errors\n */\n process.on('uncaughtException', (err) => {\n debugAndPrintError(err);\n callback(err);\n });\n\n signals.forEach((signal) =>\n process.once(signal, () => callback()));\n}\n\nexport function retry<T = any>(\n cb: Function,\n maxRetries: number = 3,\n errorWhiteList: any[] = [],\n retries: number = 0,\n) {\n return new Promise<T>((resolve, reject) => {\n cb()\n .then(resolve)\n .catch((e) => {\n if (\n errorWhiteList.indexOf(e.constructor) !== -1 &&\n retries++ < maxRetries\n ) {\n setTimeout(() => {\n retry<T>(cb, maxRetries, errorWhiteList, retries).\n then(resolve).\n catch((e2) => reject(e2));\n }, Math.floor(Math.random() * Math.pow(2, retries) * 400));\n\n } else {\n reject(e);\n }\n });\n });\n}\n\nexport function spliceOne(arr: any[], index: number): boolean {\n // manually splice availableRooms array\n // http://jsperf.com/manual-splice\n if (index === -1 || index >= arr.length) {\n return false;\n }\n\n const len = arr.length - 1;\n for (let i = index; i < len; i++) {\n arr[i] = arr[i + 1];\n }\n\n arr.length = len;\n return true;\n}\n\nexport class Deferred<T= any> {\n public promise: Promise<T>;\n\n public resolve: Function;\n public reject: Function;\n\n constructor() {\n this.promise = new Promise<T>((resolve, reject) => {\n this.resolve = resolve;\n this.reject = reject;\n });\n }\n\n public then(func: (value: T) => any) {\n return this.promise.then.apply(this.promise, arguments);\n }\n\n public catch(func: (value: any) => any) {\n return this.promise.catch(func);\n }\n\n}\n\nexport function merge(a: any, ...objs: any[]): any {\n for (let i = 0, len = objs.length; i < len; i++) {\n const b = objs[i];\n for (const key in b) {\n if (b.hasOwnProperty(key)) {\n a[key] = b[key];\n }\n }\n }\n return a;\n}\n\nexport class HybridArray<T> {\n public uniqueProperty: string;\n public hashedArray: { [key: string]: T } = {};\n public array: T[] = [];\n\n constructor(uniquePropertyName: string, items?: T[]) {\n this.uniqueProperty = uniquePropertyName;\n if (items) {\n this.array = this.array.concat(items);\n for (const element of items) {\n this.hashedArray[element[this.uniqueProperty]] = element;\n }\n }\n }\n\n public get length(): number {\n return this.array.length;\n }\n\n public add(item: T) {\n if (!this.hashedArray[item[this.uniqueProperty]]) {\n this.array.push(item);\n this.hashedArray[item[this.uniqueProperty]] = item;\n\n } else {\n logger.warn(`.add(): element already exists:`, item[this.uniqueProperty]);\n }\n }\n\n public at(index: number): T | undefined {\n if (index >= this.array.length) {\n this._badIndexWarning(index);\n\n } else {\n return this.array[index];\n }\n }\n\n public concat(items: T[]) {\n if (items) {\n for (const item of items) {\n this.hashedArray[item[this.uniqueProperty]] = item;\n }\n this.array.concat(items);\n }\n return this;\n }\n\n public find<S extends T>(predicate: (this: void, value: T, index: number, obj: T[]) => value is S, thisArg?: any): S;\n public find(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): T;\n public find(predicate: any, thisArg?: any): T | undefined {\n return this.array.find(predicate, thisArg);\n }\n\n public filter(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): T[]\n public filter<S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[] {\n return this.array.filter(predicate, thisArg);\n }\n\n public forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void {\n Array.prototype.forEach.call(this.array, callbackfn);\n }\n\n public get(key: string): T | undefined {\n return this.hashedArray[key];\n }\n\n public includes(element: T) {\n return this.hashedArray[element[this.uniqueProperty]] !== undefined;\n }\n\n public indexOf(element: T): number {\n return this.array.indexOf(element);\n }\n\n public map<U>(callback: (value: T, index: number, array: T[]) => U) {\n const result: U[] = [];\n for (let index = 0; index < this.array.length; index++) {\n result.push(callback(this.array[index], index, this.array));\n }\n return result;\n }\n\n public deleteAt(index: number) {\n if (index >= this.array.length) {\n this._badIndexWarning(index);\n return undefined;\n\n } else {\n const removable = this.spliceOne(index);\n delete this.hashedArray[removable[this.uniqueProperty]];\n return removable;\n }\n }\n\n public deleteByKey(key: string): T {\n if (!this.hashedArray[key]) {\n logger.error(`deleteByKey(): no such element for '${key}'.`);\n return undefined;\n } else {\n const removable = this.spliceOne(this.indexOf(this.hashedArray[key]));\n delete this.hashedArray[key];\n return removable;\n }\n }\n\n public delete(obj: T): T {\n if (this.hashedArray[obj[this.uniqueProperty]]) {\n return this.deleteByKey(obj[this.uniqueProperty]);\n\n } else if (this.indexOf(obj) != -1) {\n return this.deleteAt(this.indexOf(obj));\n\n } else {\n return undefined;\n }\n }\n\n private _badIndexWarning(index) {\n logger.warn(`Index out of range, index: ${index}`);\n }\n\n private spliceOne(index: number): T {\n // manually splice availableRooms array\n // http://jsperf.com/manual-splice\n if (index === -1 || index >= this.array.length) {\n this._badIndexWarning(index);\n return undefined;\n }\n\n const itemRemoved = this.array[index];\n\n const len = this.array.length - 1;\n for (let i = index; i < len; i++) {\n this.array[i] = this.array[i + 1];\n }\n this.array.length = len;\n\n return itemRemoved;\n }\n}\n\nexport declare interface DummyServer {\n constructor(options?: ServerOpts, connectionListener?: (socket: Socket) => void);\n\n listen(port?: number, hostname?: string, backlog?: number, listeningListener?: () => void): this;\n close(callback?: (err?: Error) => void): this;\n}\n\nexport class DummyServer extends EventEmitter {}\n\n// Add msgpackr extension to avoid circular references when encoding\n// https://github.com/kriszyp/msgpackr#custom-extensions\naddExtension({\n Class: Schema,\n type: 0,\n\n read(datum: any): any {\n return datum;\n },\n\n write(instance: any): any {\n return instance.toJSON();\n }\n});\n"],
5
- "mappings": "AAAA,OAAO,YAAY;AACnB,SAAS,oBAAoB;AAE7B,SAAS,0BAA0B;AACnC,SAAS,oBAAoB;AAE7B,SAAS,cAAc;AACvB,SAAS,cAAc;AAGhB,MAAM,4BAA4B,OAAO,QAAQ,IAAI,mCAAmC,GAAI;AAE5F,SAAS,WAAW,SAAiB,GAAG;AAC7C,SAAO,OAAO,MAAM;AACtB;AAMA,MAAM,UAA4B,CAAC,UAAU,WAAW,SAAS;AAE1D,SAAS,yBAAyB,UAAiC;AAIxE,UAAQ,GAAG,qBAAqB,CAAC,QAAQ;AACvC,uBAAmB,GAAG;AACtB,aAAS,GAAG;AAAA,EACd,CAAC;AAED,UAAQ,QAAQ,CAAC,WACf,QAAQ,KAAK,QAAQ,MAAM,SAAS,CAAC,CAAC;AAC1C;AAEO,SAAS,MACd,IACA,aAAqB,GACrB,iBAAwB,CAAC,GACzB,UAAkB,GAClB;AACA,SAAO,IAAI,QAAW,CAAC,SAAS,WAAW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;AAAA,EAEQ,UAAU,OAAkB;AAGlC,QAAI,UAAU,MAAM,SAAS,KAAK,MAAM,QAAQ;AAC9C,WAAK,iBAAiB,KAAK;AAC3B,aAAO;AAAA,IACT;AAEA,UAAM,cAAc,KAAK,MAAM;AAE/B,UAAM,MAAM,KAAK,MAAM,SAAS;AAChC,aAAS,IAAI,OAAO,IAAI,KAAK,KAAK;AAChC,WAAK,MAAM,KAAK,KAAK,MAAM,IAAI;AAAA,IACjC;AACA,SAAK,MAAM,SAAS;AAEpB,WAAO;AAAA,EACT;AACF;AASO,MAAM,oBAAoB,aAAa;AAAC;AAI/C,aAAa;AAAA,EACX,OAAO;AAAA,EACP,MAAM;AAAA,EAEN,KAAK,OAAiB;AACpB,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,UAAoB;AACxB,WAAO,SAAS,OAAO;AAAA,EACzB;AACF,CAAC;",
4
+ "sourcesContent": ["import nanoid from 'nanoid';\nimport { addExtension } from 'msgpackr';\n\nimport { debugAndPrintError } from '../Debug';\nimport { EventEmitter } from \"events\";\nimport { ServerOpts, Socket } from \"net\";\nimport { logger } from '../Logger';\nimport { Schema } from \"@colyseus/schema\";\n\n// remote room call timeouts\nexport const REMOTE_ROOM_SHORT_TIMEOUT = Number(process.env.COLYSEUS_PRESENCE_SHORT_TIMEOUT || 2000);\n\nexport function generateId(length: number = 9) {\n return nanoid(length);\n}\n\n//\n// nodemon sends SIGUSR2 before reloading\n// (https://github.com/remy/nodemon#controlling-shutdown-of-your-script)\n//\nconst signals: NodeJS.Signals[] = ['SIGINT', 'SIGTERM', 'SIGUSR2'];\n\nexport function registerGracefulShutdown(callback: (err?: Error) => void) {\n /**\n * Gracefully shutdown on uncaught errors\n */\n process.on('uncaughtException', (err) => {\n debugAndPrintError(err);\n callback(err);\n });\n\n signals.forEach((signal) =>\n process.once(signal, () => callback()));\n}\n\nexport function retry<T = any>(\n cb: Function,\n maxRetries: number = 3,\n errorWhiteList: any[] = [],\n retries: number = 0,\n) {\n return new Promise<T>((resolve, reject) => {\n cb()\n .then(resolve)\n .catch((e) => {\n if (\n errorWhiteList.indexOf(e.constructor) !== -1 &&\n retries++ < maxRetries\n ) {\n setTimeout(() => {\n retry<T>(cb, maxRetries, errorWhiteList, retries).\n then(resolve).\n catch((e2) => reject(e2));\n }, Math.floor(Math.random() * Math.pow(2, retries) * 400));\n\n } else {\n reject(e);\n }\n });\n });\n}\n\nexport function spliceOne(arr: any[], index: number): boolean {\n // manually splice availableRooms array\n // http://jsperf.com/manual-splice\n if (index === -1 || index >= arr.length) {\n return false;\n }\n\n const len = arr.length - 1;\n for (let i = index; i < len; i++) {\n arr[i] = arr[i + 1];\n }\n\n arr.length = len;\n return true;\n}\n\nexport class Deferred<T= any> {\n public promise: Promise<T>;\n\n public resolve: Function;\n public reject: Function;\n\n constructor() {\n this.promise = new Promise<T>((resolve, reject) => {\n this.resolve = resolve;\n this.reject = reject;\n });\n }\n\n public then(func: (value: T) => any) {\n return this.promise.then.apply(this.promise, arguments);\n }\n\n public catch(func: (value: any) => any) {\n return this.promise.catch(func);\n }\n\n}\n\nexport function merge(a: any, ...objs: any[]): any {\n for (let i = 0, len = objs.length; i < len; i++) {\n const b = objs[i];\n for (const key in b) {\n if (b.hasOwnProperty(key)) {\n a[key] = b[key];\n }\n }\n }\n return a;\n}\n\nexport declare interface DummyServer {\n constructor(options?: ServerOpts, connectionListener?: (socket: Socket) => void);\n\n listen(port?: number, hostname?: string, backlog?: number, listeningListener?: () => void): this;\n close(callback?: (err?: Error) => void): this;\n}\n\nexport class DummyServer extends EventEmitter {}\n\n// Add msgpackr extension to avoid circular references when encoding\n// https://github.com/kriszyp/msgpackr#custom-extensions\naddExtension({\n Class: Schema,\n type: 0,\n\n read(datum: any): any {\n return datum;\n },\n\n write(instance: any): any {\n return instance.toJSON();\n }\n});\n"],
5
+ "mappings": "AAAA,OAAO,YAAY;AACnB,SAAS,oBAAoB;AAE7B,SAAS,0BAA0B;AACnC,SAAS,oBAAoB;AAG7B,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UAAU,IAAI,QAAW,CAAC,SAAS,WAAW;AACjD,WAAK,UAAU;AACf,WAAK,SAAS;AAAA,IAChB,CAAC;AAAA,EACH;AAAA,EAEO,KAAK,MAAyB;AACnC,WAAO,KAAK,QAAQ,KAAK,MAAM,KAAK,SAAS,SAAS;AAAA,EACxD;AAAA,EAEO,MAAM,MAA2B;AACtC,WAAO,KAAK,QAAQ,MAAM,IAAI;AAAA,EAChC;AAEF;AAEO,SAAS,MAAM,MAAW,MAAkB;AACjD,WAAS,IAAI,GAAG,MAAM,KAAK,QAAQ,IAAI,KAAK,KAAK;AAC/C,UAAM,IAAI,KAAK;AACf,eAAW,OAAO,GAAG;AACnB,UAAI,EAAE,eAAe,GAAG,GAAG;AACzB,UAAE,OAAO,EAAE;AAAA,MACb;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AASO,MAAM,oBAAoB,aAAa;AAAC;AAI/C,aAAa;AAAA,EACX,OAAO;AAAA,EACP,MAAM;AAAA,EAEN,KAAK,OAAiB;AACpB,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,UAAoB;AACxB,WAAO,SAAS,OAAO;AAAA,EACzB;AACF,CAAC;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colyseus/core",
3
- "version": "0.15.1",
3
+ "version": "0.15.2",
4
4
  "description": "Multiplayer Framework for Node.js.",
5
5
  "input": "./src/index.ts",
6
6
  "main": "./build/index.js",
@@ -46,5 +46,5 @@
46
46
  "publishConfig": {
47
47
  "access": "public"
48
48
  },
49
- "gitHead": "59b0541879c5480ea76c1f0cc6c5e40cbcda9cb5"
49
+ "gitHead": "1258ab821f90724892b68f70b74068158dd79ef6"
50
50
  }