@colyseus/core 0.15.24 → 0.15.25
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.
- package/build/IPC.js +11 -2
- package/build/IPC.js.map +2 -2
- package/build/IPC.mjs +11 -2
- package/build/IPC.mjs.map +2 -2
- package/package.json +1 -1
package/build/IPC.js
CHANGED
|
@@ -38,7 +38,15 @@ async function requestFromIPC(presence, publishToChannel, method, args, rejectio
|
|
|
38
38
|
if (code === import_Protocol.IpcProtocol.SUCCESS) {
|
|
39
39
|
resolve(data);
|
|
40
40
|
} else if (code === import_Protocol.IpcProtocol.ERROR) {
|
|
41
|
-
|
|
41
|
+
let error = data;
|
|
42
|
+
try {
|
|
43
|
+
error = JSON.parse(data);
|
|
44
|
+
} catch (e) {
|
|
45
|
+
}
|
|
46
|
+
if (typeof error === "string") {
|
|
47
|
+
error = new Error(error);
|
|
48
|
+
}
|
|
49
|
+
reject(error);
|
|
42
50
|
}
|
|
43
51
|
unsubscribe();
|
|
44
52
|
});
|
|
@@ -60,7 +68,8 @@ async function subscribeIPC(presence, processId, channel, replyCallback) {
|
|
|
60
68
|
response = replyCallback(method, args);
|
|
61
69
|
} catch (e) {
|
|
62
70
|
(0, import_Debug.debugAndPrintError)(e);
|
|
63
|
-
|
|
71
|
+
const error = typeof e.code !== "undefined" ? { code: e.code, message: e.message } : e.message;
|
|
72
|
+
return reply(import_Protocol.IpcProtocol.ERROR, JSON.stringify(error));
|
|
64
73
|
}
|
|
65
74
|
if (!(response instanceof Promise)) {
|
|
66
75
|
return reply(import_Protocol.IpcProtocol.SUCCESS, response);
|
package/build/IPC.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/IPC.ts"],
|
|
4
|
-
"sourcesContent": ["import { debugAndPrintError } from './Debug';\nimport { Presence } from './presence/Presence';\nimport { IpcProtocol } from './Protocol';\nimport { generateId, REMOTE_ROOM_SHORT_TIMEOUT } from './utils/Utils';\n\nexport async function requestFromIPC<T>(\n presence: Presence,\n publishToChannel: string,\n method: string,\n args: any[],\n rejectionTimeout: number = REMOTE_ROOM_SHORT_TIMEOUT,\n): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n let unsubscribeTimeout: NodeJS.Timer;\n\n const requestId = generateId();\n const channel = `ipc:${requestId}`;\n\n const unsubscribe = () => {\n presence.unsubscribe(channel);\n clearTimeout(unsubscribeTimeout);\n };\n\n presence.subscribe(channel, (message) => {\n const [code, data] = message;\n if (code === IpcProtocol.SUCCESS) {\n resolve(data);\n } else if (code === IpcProtocol.ERROR) {\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAmC;
|
|
4
|
+
"sourcesContent": ["import { debugAndPrintError } from './Debug';\nimport { ServerError } from './errors/ServerError';\nimport { Presence } from './presence/Presence';\nimport { IpcProtocol } from './Protocol';\nimport { generateId, REMOTE_ROOM_SHORT_TIMEOUT } from './utils/Utils';\n\nexport async function requestFromIPC<T>(\n presence: Presence,\n publishToChannel: string,\n method: string,\n args: any[],\n rejectionTimeout: number = REMOTE_ROOM_SHORT_TIMEOUT,\n): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n let unsubscribeTimeout: NodeJS.Timer;\n\n const requestId = generateId();\n const channel = `ipc:${requestId}`;\n\n const unsubscribe = () => {\n presence.unsubscribe(channel);\n clearTimeout(unsubscribeTimeout);\n };\n\n presence.subscribe(channel, (message) => {\n const [code, data] = message;\n if (code === IpcProtocol.SUCCESS) {\n resolve(data);\n\n } else if (code === IpcProtocol.ERROR) {\n let error: any = data;\n\n // parse error message + code\n try { error = JSON.parse(data) } catch (e) {}\n\n // turn string message into Error instance\n if (typeof(error) === \"string\") {\n error = new Error(error);\n }\n\n reject(error);\n }\n unsubscribe();\n });\n\n presence.publish(publishToChannel, [method, requestId, args]);\n\n unsubscribeTimeout = setTimeout(() => {\n unsubscribe();\n reject(new Error(\"ipc_timeout\"));\n }, rejectionTimeout);\n });\n}\n\nexport async function subscribeIPC(\n presence: Presence,\n processId: string,\n channel: string,\n replyCallback: (method: string, args: any[]) => any,\n) {\n await presence.subscribe(channel, (message) => {\n const [method, requestId, args] = message;\n\n const reply = (code, data) => {\n presence.publish(`ipc:${requestId}`, [code, data]);\n };\n\n // reply with method result\n let response: any;\n try {\n response = replyCallback(method, args);\n\n } catch (e) {\n debugAndPrintError(e);\n const error = (typeof(e.code) !== \"undefined\")\n ? { code: e.code, message: e.message }\n : e.message;\n return reply(IpcProtocol.ERROR, JSON.stringify(error));\n }\n\n if (!(response instanceof Promise)) {\n return reply(IpcProtocol.SUCCESS, response);\n }\n\n response.\n then((result) => reply(IpcProtocol.SUCCESS, result)).\n catch((e) => {\n // user might have called `reject()` without arguments.\n const err = e && e.message || e;\n reply(IpcProtocol.ERROR, err);\n });\n });\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAmC;AAGnC,sBAA4B;AAC5B,mBAAsD;AAEtD,eAAsB,eACpB,UACA,kBACA,QACA,MACA,mBAA2B,wCACf;AACZ,SAAO,IAAI,QAAW,CAAC,SAAS,WAAW;AACzC,QAAI;AAEJ,UAAM,gBAAY,yBAAW;AAC7B,UAAM,UAAU,OAAO;AAEvB,UAAM,cAAc,MAAM;AACxB,eAAS,YAAY,OAAO;AAC5B,mBAAa,kBAAkB;AAAA,IACjC;AAEA,aAAS,UAAU,SAAS,CAAC,YAAY;AACvC,YAAM,CAAC,MAAM,IAAI,IAAI;AACrB,UAAI,SAAS,4BAAY,SAAS;AAChC,gBAAQ,IAAI;AAAA,MAEd,WAAW,SAAS,4BAAY,OAAO;AACrC,YAAI,QAAa;AAGjB,YAAI;AAAE,kBAAQ,KAAK,MAAM,IAAI;AAAA,QAAE,SAAS,GAAP;AAAA,QAAW;AAG5C,YAAI,OAAO,UAAW,UAAU;AAC9B,kBAAQ,IAAI,MAAM,KAAK;AAAA,QACzB;AAEA,eAAO,KAAK;AAAA,MACd;AACA,kBAAY;AAAA,IACd,CAAC;AAED,aAAS,QAAQ,kBAAkB,CAAC,QAAQ,WAAW,IAAI,CAAC;AAE5D,yBAAqB,WAAW,MAAM;AACpC,kBAAY;AACZ,aAAO,IAAI,MAAM,aAAa,CAAC;AAAA,IACjC,GAAG,gBAAgB;AAAA,EACrB,CAAC;AACH;AAEA,eAAsB,aACpB,UACA,WACA,SACA,eACA;AACA,QAAM,SAAS,UAAU,SAAS,CAAC,YAAY;AAC7C,UAAM,CAAC,QAAQ,WAAW,IAAI,IAAI;AAElC,UAAM,QAAQ,CAAC,MAAM,SAAS;AAC5B,eAAS,QAAQ,OAAO,aAAa,CAAC,MAAM,IAAI,CAAC;AAAA,IACnD;AAGA,QAAI;AACJ,QAAI;AACF,iBAAW,cAAc,QAAQ,IAAI;AAAA,IAEvC,SAAS,GAAP;AACA,2CAAmB,CAAC;AACpB,YAAM,QAAS,OAAO,EAAE,SAAU,cAC9B,EAAE,MAAM,EAAE,MAAM,SAAS,EAAE,QAAQ,IACnC,EAAE;AACN,aAAO,MAAM,4BAAY,OAAO,KAAK,UAAU,KAAK,CAAC;AAAA,IACvD;AAEA,QAAI,EAAE,oBAAoB,UAAU;AAClC,aAAO,MAAM,4BAAY,SAAS,QAAQ;AAAA,IAC5C;AAEA,aACE,KAAK,CAAC,WAAW,MAAM,4BAAY,SAAS,MAAM,CAAC,EACnD,MAAM,CAAC,MAAM;AAEX,YAAM,MAAM,KAAK,EAAE,WAAW;AAC9B,YAAM,4BAAY,OAAO,GAAG;AAAA,IAC9B,CAAC;AAAA,EACL,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/IPC.mjs
CHANGED
|
@@ -15,7 +15,15 @@ async function requestFromIPC(presence, publishToChannel, method, args, rejectio
|
|
|
15
15
|
if (code === IpcProtocol.SUCCESS) {
|
|
16
16
|
resolve(data);
|
|
17
17
|
} else if (code === IpcProtocol.ERROR) {
|
|
18
|
-
|
|
18
|
+
let error = data;
|
|
19
|
+
try {
|
|
20
|
+
error = JSON.parse(data);
|
|
21
|
+
} catch (e) {
|
|
22
|
+
}
|
|
23
|
+
if (typeof error === "string") {
|
|
24
|
+
error = new Error(error);
|
|
25
|
+
}
|
|
26
|
+
reject(error);
|
|
19
27
|
}
|
|
20
28
|
unsubscribe();
|
|
21
29
|
});
|
|
@@ -37,7 +45,8 @@ async function subscribeIPC(presence, processId, channel, replyCallback) {
|
|
|
37
45
|
response = replyCallback(method, args);
|
|
38
46
|
} catch (e) {
|
|
39
47
|
debugAndPrintError(e);
|
|
40
|
-
|
|
48
|
+
const error = typeof e.code !== "undefined" ? { code: e.code, message: e.message } : e.message;
|
|
49
|
+
return reply(IpcProtocol.ERROR, JSON.stringify(error));
|
|
41
50
|
}
|
|
42
51
|
if (!(response instanceof Promise)) {
|
|
43
52
|
return reply(IpcProtocol.SUCCESS, response);
|
package/build/IPC.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/IPC.ts"],
|
|
4
|
-
"sourcesContent": ["import { debugAndPrintError } from './Debug';\nimport { Presence } from './presence/Presence';\nimport { IpcProtocol } from './Protocol';\nimport { generateId, REMOTE_ROOM_SHORT_TIMEOUT } from './utils/Utils';\n\nexport async function requestFromIPC<T>(\n presence: Presence,\n publishToChannel: string,\n method: string,\n args: any[],\n rejectionTimeout: number = REMOTE_ROOM_SHORT_TIMEOUT,\n): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n let unsubscribeTimeout: NodeJS.Timer;\n\n const requestId = generateId();\n const channel = `ipc:${requestId}`;\n\n const unsubscribe = () => {\n presence.unsubscribe(channel);\n clearTimeout(unsubscribeTimeout);\n };\n\n presence.subscribe(channel, (message) => {\n const [code, data] = message;\n if (code === IpcProtocol.SUCCESS) {\n resolve(data);\n } else if (code === IpcProtocol.ERROR) {\n
|
|
5
|
-
"mappings": "AAAA,SAAS,0BAA0B;
|
|
4
|
+
"sourcesContent": ["import { debugAndPrintError } from './Debug';\nimport { ServerError } from './errors/ServerError';\nimport { Presence } from './presence/Presence';\nimport { IpcProtocol } from './Protocol';\nimport { generateId, REMOTE_ROOM_SHORT_TIMEOUT } from './utils/Utils';\n\nexport async function requestFromIPC<T>(\n presence: Presence,\n publishToChannel: string,\n method: string,\n args: any[],\n rejectionTimeout: number = REMOTE_ROOM_SHORT_TIMEOUT,\n): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n let unsubscribeTimeout: NodeJS.Timer;\n\n const requestId = generateId();\n const channel = `ipc:${requestId}`;\n\n const unsubscribe = () => {\n presence.unsubscribe(channel);\n clearTimeout(unsubscribeTimeout);\n };\n\n presence.subscribe(channel, (message) => {\n const [code, data] = message;\n if (code === IpcProtocol.SUCCESS) {\n resolve(data);\n\n } else if (code === IpcProtocol.ERROR) {\n let error: any = data;\n\n // parse error message + code\n try { error = JSON.parse(data) } catch (e) {}\n\n // turn string message into Error instance\n if (typeof(error) === \"string\") {\n error = new Error(error);\n }\n\n reject(error);\n }\n unsubscribe();\n });\n\n presence.publish(publishToChannel, [method, requestId, args]);\n\n unsubscribeTimeout = setTimeout(() => {\n unsubscribe();\n reject(new Error(\"ipc_timeout\"));\n }, rejectionTimeout);\n });\n}\n\nexport async function subscribeIPC(\n presence: Presence,\n processId: string,\n channel: string,\n replyCallback: (method: string, args: any[]) => any,\n) {\n await presence.subscribe(channel, (message) => {\n const [method, requestId, args] = message;\n\n const reply = (code, data) => {\n presence.publish(`ipc:${requestId}`, [code, data]);\n };\n\n // reply with method result\n let response: any;\n try {\n response = replyCallback(method, args);\n\n } catch (e) {\n debugAndPrintError(e);\n const error = (typeof(e.code) !== \"undefined\")\n ? { code: e.code, message: e.message }\n : e.message;\n return reply(IpcProtocol.ERROR, JSON.stringify(error));\n }\n\n if (!(response instanceof Promise)) {\n return reply(IpcProtocol.SUCCESS, response);\n }\n\n response.\n then((result) => reply(IpcProtocol.SUCCESS, result)).\n catch((e) => {\n // user might have called `reject()` without arguments.\n const err = e && e.message || e;\n reply(IpcProtocol.ERROR, err);\n });\n });\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,0BAA0B;AAGnC,SAAS,mBAAmB;AAC5B,SAAS,YAAY,iCAAiC;AAEtD,eAAsB,eACpB,UACA,kBACA,QACA,MACA,mBAA2B,2BACf;AACZ,SAAO,IAAI,QAAW,CAAC,SAAS,WAAW;AACzC,QAAI;AAEJ,UAAM,YAAY,WAAW;AAC7B,UAAM,UAAU,OAAO;AAEvB,UAAM,cAAc,MAAM;AACxB,eAAS,YAAY,OAAO;AAC5B,mBAAa,kBAAkB;AAAA,IACjC;AAEA,aAAS,UAAU,SAAS,CAAC,YAAY;AACvC,YAAM,CAAC,MAAM,IAAI,IAAI;AACrB,UAAI,SAAS,YAAY,SAAS;AAChC,gBAAQ,IAAI;AAAA,MAEd,WAAW,SAAS,YAAY,OAAO;AACrC,YAAI,QAAa;AAGjB,YAAI;AAAE,kBAAQ,KAAK,MAAM,IAAI;AAAA,QAAE,SAAS,GAAP;AAAA,QAAW;AAG5C,YAAI,OAAO,UAAW,UAAU;AAC9B,kBAAQ,IAAI,MAAM,KAAK;AAAA,QACzB;AAEA,eAAO,KAAK;AAAA,MACd;AACA,kBAAY;AAAA,IACd,CAAC;AAED,aAAS,QAAQ,kBAAkB,CAAC,QAAQ,WAAW,IAAI,CAAC;AAE5D,yBAAqB,WAAW,MAAM;AACpC,kBAAY;AACZ,aAAO,IAAI,MAAM,aAAa,CAAC;AAAA,IACjC,GAAG,gBAAgB;AAAA,EACrB,CAAC;AACH;AAEA,eAAsB,aACpB,UACA,WACA,SACA,eACA;AACA,QAAM,SAAS,UAAU,SAAS,CAAC,YAAY;AAC7C,UAAM,CAAC,QAAQ,WAAW,IAAI,IAAI;AAElC,UAAM,QAAQ,CAAC,MAAM,SAAS;AAC5B,eAAS,QAAQ,OAAO,aAAa,CAAC,MAAM,IAAI,CAAC;AAAA,IACnD;AAGA,QAAI;AACJ,QAAI;AACF,iBAAW,cAAc,QAAQ,IAAI;AAAA,IAEvC,SAAS,GAAP;AACA,yBAAmB,CAAC;AACpB,YAAM,QAAS,OAAO,EAAE,SAAU,cAC9B,EAAE,MAAM,EAAE,MAAM,SAAS,EAAE,QAAQ,IACnC,EAAE;AACN,aAAO,MAAM,YAAY,OAAO,KAAK,UAAU,KAAK,CAAC;AAAA,IACvD;AAEA,QAAI,EAAE,oBAAoB,UAAU;AAClC,aAAO,MAAM,YAAY,SAAS,QAAQ;AAAA,IAC5C;AAEA,aACE,KAAK,CAAC,WAAW,MAAM,YAAY,SAAS,MAAM,CAAC,EACnD,MAAM,CAAC,MAAM;AAEX,YAAM,MAAM,KAAK,EAAE,WAAW;AAC9B,YAAM,YAAY,OAAO,GAAG;AAAA,IAC9B,CAAC;AAAA,EACL,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|