@mirage-x/server 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/LICENSE +21 -0
  2. package/README.ja.md +28 -0
  3. package/README.md +27 -2
  4. package/dist/hooks/useBoundCallback.d.ts +7 -0
  5. package/dist/hooks/useBoundCallback.d.ts.map +1 -0
  6. package/dist/hooks/useBoundCallback.js +10 -0
  7. package/dist/hooks/useBoundCallback.js.map +1 -0
  8. package/dist/hooks/useMirrorRef.d.ts +5 -0
  9. package/dist/hooks/useMirrorRef.d.ts.map +1 -0
  10. package/dist/hooks/useMirrorRef.js +15 -0
  11. package/dist/hooks/useMirrorRef.js.map +1 -0
  12. package/dist/index.d.ts +10 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +8 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/logger/context.d.ts +12 -0
  17. package/dist/logger/context.d.ts.map +1 -0
  18. package/dist/logger/context.js +17 -0
  19. package/dist/logger/context.js.map +1 -0
  20. package/dist/logger/index.d.ts +35 -0
  21. package/dist/logger/index.d.ts.map +1 -0
  22. package/dist/logger/index.js +88 -0
  23. package/dist/logger/index.js.map +1 -0
  24. package/dist/main/index.d.ts +49 -0
  25. package/dist/main/index.d.ts.map +1 -0
  26. package/dist/main/index.js +37 -0
  27. package/dist/main/index.js.map +1 -0
  28. package/dist/main/mainRootProps.d.ts +6 -0
  29. package/dist/main/mainRootProps.d.ts.map +1 -0
  30. package/dist/main/mainRootProps.js +2 -0
  31. package/dist/main/mainRootProps.js.map +1 -0
  32. package/dist/server/connection.d.ts +33 -0
  33. package/dist/server/connection.d.ts.map +1 -0
  34. package/dist/server/connection.js +120 -0
  35. package/dist/server/connection.js.map +1 -0
  36. package/dist/server/dummyReactRenderer.d.ts +5 -0
  37. package/dist/server/dummyReactRenderer.d.ts.map +1 -0
  38. package/dist/server/dummyReactRenderer.js +85 -0
  39. package/dist/server/dummyReactRenderer.js.map +1 -0
  40. package/dist/server/index.d.ts +54 -0
  41. package/dist/server/index.d.ts.map +1 -0
  42. package/dist/server/index.js +214 -0
  43. package/dist/server/index.js.map +1 -0
  44. package/dist/server/logicManager.d.ts +42 -0
  45. package/dist/server/logicManager.d.ts.map +1 -0
  46. package/dist/server/logicManager.js +172 -0
  47. package/dist/server/logicManager.js.map +1 -0
  48. package/dist/server/render.d.ts +16 -0
  49. package/dist/server/render.d.ts.map +1 -0
  50. package/dist/server/render.js +31 -0
  51. package/dist/server/render.js.map +1 -0
  52. package/dist/unit/generateMain.d.ts +9 -0
  53. package/dist/unit/generateMain.d.ts.map +1 -0
  54. package/dist/unit/generateMain.js +165 -0
  55. package/dist/unit/generateMain.js.map +1 -0
  56. package/package.json +64 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 rheniumNV
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.ja.md ADDED
@@ -0,0 +1,28 @@
1
+ [English](https://github.com/rheniumNV/mirage-x/blob/master/packages/server/README.md) | [日本語](https://github.com/rheniumNV/mirage-x/blob/master/packages/server/README.ja.md)
2
+
3
+ # @mirage-x/server
4
+
5
+ [MirageX](https://github.com/rheniumNV/mirage-x/blob/master/README.ja.md) の実行時の部分です。MirageX は、WebSocket を介して Unit のツリーを Resonite 側のミラーと同期させるサーバーサイド React フレームワークです。
6
+
7
+ - `MirageXServer`: サーバーで React アプリを描画し、その変更を Resonite のミラーに送ります(express + WebSocket)
8
+ - `generateMain`: Unit を React のコンポーネントにします
9
+ - フック: `useMirrorRef`、`useBoundCallback`、`useMainRootContext`
10
+ - `Logger`
11
+
12
+ `react` 19(19.3 以降)は peerDependency です。コンポーネントとランタイムが同じ React を使う必要があるためです。
13
+
14
+ MirageX は 3 つのパッケージで公開していて、一緒に使います。[`@mirage-x/core`](https://www.npmjs.com/package/@mirage-x/core)(共有する Unit の定義)、[`@mirage-x/server`](https://www.npmjs.com/package/@mirage-x/server)(実行時)、[`@mirage-x/mirror`](https://www.npmjs.com/package/@mirage-x/mirror)(ビルド時)です。**使い方は [MirageX の README](https://github.com/rheniumNV/mirage-x/blob/master/README.ja.md) を見てください**。完成したアプリの例は [`examples/basic`](https://github.com/rheniumNV/mirage-x/tree/master/examples/basic) にあります。
15
+
16
+ ```bash
17
+ npm install @mirage-x/core @mirage-x/server @mirage-x/mirror react@19
18
+ ```
19
+
20
+ Node.js 22 以上、ESM のみです。3 つのパッケージはバージョンを揃えてください。
21
+
22
+ ## ライセンス
23
+
24
+ MIT
25
+
26
+ ## 生成 AI を使った開発
27
+
28
+ このプロジェクトは、生成 AI のコーディングツールを使って開発しています。変更はメンテナーが確認し、Resonite での動作も含めてテストしています。
package/README.md CHANGED
@@ -1,3 +1,28 @@
1
- # Temporary Holding Version
1
+ [English](https://github.com/rheniumNV/mirage-x/blob/master/packages/server/README.md) | [日本語](https://github.com/rheniumNV/mirage-x/blob/master/packages/server/README.ja.md)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # @mirage-x/server
4
+
5
+ The run-time part of [MirageX](https://github.com/rheniumNV/mirage-x#readme), a server-side React framework that syncs a Unit tree to a Resonite-side mirror over WebSocket.
6
+
7
+ - `MirageXServer`: renders your React app on the server and sends its changes to the mirror in Resonite (express + WebSocket)
8
+ - `generateMain`: a Unit as a React component
9
+ - Hooks: `useMirrorRef`, `useBoundCallback`, `useMainRootContext`
10
+ - `Logger`
11
+
12
+ `react` 19 (19.3 or later) is a peer dependency: your components and the runtime must share one React.
13
+
14
+ MirageX is published as three packages, used together: [`@mirage-x/core`](https://www.npmjs.com/package/@mirage-x/core) (shared Unit definitions), [`@mirage-x/server`](https://www.npmjs.com/package/@mirage-x/server) (run time) and [`@mirage-x/mirror`](https://www.npmjs.com/package/@mirage-x/mirror) (build time). **See the [MirageX README](https://github.com/rheniumNV/mirage-x#readme) for how to use them**, and [`examples/basic`](https://github.com/rheniumNV/mirage-x/tree/master/examples/basic) for a complete app.
15
+
16
+ ```bash
17
+ npm install @mirage-x/core @mirage-x/server @mirage-x/mirror react@19
18
+ ```
19
+
20
+ Node.js 22 or later, ESM only. Keep the three packages at the same version.
21
+
22
+ ## License
23
+
24
+ MIT
25
+
26
+ ## Development with generative AI
27
+
28
+ This project is developed with generative AI coding tools. Changes are reviewed and tested by the maintainer, including in Resonite.
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Stable callback that invokes `fn` with bound `args`.
3
+ * Prefer this over ad-hoc `useCallback(() => fn(x), [fn, x])` for list item
4
+ * handlers so MirageX handler-id sync stays stable.
5
+ */
6
+ export declare function useBoundCallback<A extends unknown[]>(fn: (...args: A) => void, ...args: A): () => void;
7
+ //# sourceMappingURL=useBoundCallback.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBoundCallback.d.ts","sourceRoot":"","sources":["../../src/hooks/useBoundCallback.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,OAAO,EAAE,EAClD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,IAAI,EACxB,GAAG,IAAI,EAAE,CAAC,GACT,MAAM,IAAI,CAEZ"}
@@ -0,0 +1,10 @@
1
+ import { useCallback } from "react";
2
+ /**
3
+ * Stable callback that invokes `fn` with bound `args`.
4
+ * Prefer this over ad-hoc `useCallback(() => fn(x), [fn, x])` for list item
5
+ * handlers so MirageX handler-id sync stays stable.
6
+ */
7
+ export function useBoundCallback(fn, ...args) {
8
+ return useCallback(() => fn(...args), [fn, ...args]);
9
+ }
10
+ //# sourceMappingURL=useBoundCallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBoundCallback.js","sourceRoot":"","sources":["../../src/hooks/useBoundCallback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEpC;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC9B,EAAwB,EACxB,GAAG,IAAO;IAEV,OAAO,WAAW,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;AACvD,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { type MirrorRef } from "@mirage-x/core";
2
+ export declare const useMirrorRef: () => MirrorRef;
3
+ /** Subscribe to a MirrorRef and return a snapshot string (unitId + ref option). */
4
+ export declare const useMirrorRefSnapshot: (ref: MirrorRef | null | undefined) => string;
5
+ //# sourceMappingURL=useMirrorRef.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMirrorRef.d.ts","sourceRoot":"","sources":["../../src/hooks/useMirrorRef.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEjE,eAAO,MAAM,YAAY,QAAO,SAE/B,CAAC;AAEF,mFAAmF;AACnF,eAAO,MAAM,oBAAoB,GAC/B,KAAK,SAAS,GAAG,IAAI,GAAG,SAAS,KAChC,MAWF,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { useMemo, useSyncExternalStore } from "react";
2
+ import { createMirrorRef } from "@mirage-x/core";
3
+ export const useMirrorRef = () => {
4
+ return useMemo(() => createMirrorRef(), []);
5
+ };
6
+ /** Subscribe to a MirrorRef and return a snapshot string (unitId + ref option). */
7
+ export const useMirrorRefSnapshot = (ref) => {
8
+ return useSyncExternalStore((onStoreChange) => {
9
+ if (!ref) {
10
+ return () => { };
11
+ }
12
+ return ref.subscribe(onStoreChange);
13
+ }, () => (ref ? ref.getSnapshot() : ""), () => (ref ? ref.getSnapshot() : ""));
14
+ };
15
+ //# sourceMappingURL=useMirrorRef.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMirrorRef.js","sourceRoot":"","sources":["../../src/hooks/useMirrorRef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAEtD,OAAO,EAAE,eAAe,EAAkB,MAAM,gBAAgB,CAAC;AAEjE,MAAM,CAAC,MAAM,YAAY,GAAG,GAAc,EAAE;IAC1C,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,eAAe,EAAE,EAAE,EAAE,CAAC,CAAC;AAC9C,CAAC,CAAC;AAEF,mFAAmF;AACnF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,GAAiC,EACzB,EAAE;IACV,OAAO,oBAAoB,CACzB,CAAC,aAAa,EAAE,EAAE;QAChB,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;QAClB,CAAC;QACD,OAAO,GAAG,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IACtC,CAAC,EACD,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EACpC,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CACrC,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ export { MirageXServer } from "./server/index.js";
2
+ export type { MirageXServerConfig } from "./server/index.js";
3
+ export { generateMain } from "./unit/generateMain.js";
4
+ export { useMirrorRef } from "./hooks/useMirrorRef.js";
5
+ export { useBoundCallback } from "./hooks/useBoundCallback.js";
6
+ export { useMainRootContext } from "./main/index.js";
7
+ export type { Authentication, MainRootContextValue } from "./main/index.js";
8
+ export { Logger } from "./logger/index.js";
9
+ export type { LogLevel } from "./logger/index.js";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,YAAY,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE7D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,YAAY,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAE5E,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,YAAY,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ // Run time: renders your React app and syncs it to the mirror in Resonite.
2
+ export { MirageXServer } from "./server/index.js";
3
+ export { generateMain } from "./unit/generateMain.js";
4
+ export { useMirrorRef } from "./hooks/useMirrorRef.js";
5
+ export { useBoundCallback } from "./hooks/useBoundCallback.js";
6
+ export { useMainRootContext } from "./main/index.js";
7
+ export { Logger } from "./logger/index.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAGrD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { type ReactNode } from "react";
2
+ import type { Logger } from "./index.js";
3
+ export declare const LoggerProvider: ({ logger, children, }: {
4
+ logger: Logger;
5
+ children: ReactNode;
6
+ }) => import("react").JSX.Element;
7
+ export declare const LogContext: ({ contextName, children, }: {
8
+ contextName: string;
9
+ children: ReactNode;
10
+ }) => import("react").JSX.Element;
11
+ export declare const useLogger: () => Logger;
12
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/logger/context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAIzC,eAAO,MAAM,cAAc,GAAI,uBAG5B;IACD,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,SAAS,CAAC;CACrB,gCAEA,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,4BAGxB;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,SAAS,CAAC;CACrB,gCAOA,CAAC;AAEF,eAAO,MAAM,SAAS,cAMrB,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useMemo } from "react";
3
+ const LoggerContext = createContext(undefined);
4
+ export const LoggerProvider = ({ logger, children, }) => (_jsx(LoggerContext.Provider, { value: logger, children: children }));
5
+ export const LogContext = ({ contextName, children, }) => {
6
+ const logger = useLogger();
7
+ const childLogger = useMemo(() => logger.generateChildLogger({ contextName }), [logger, contextName]);
8
+ return _jsx(LoggerProvider, { logger: childLogger, children: children });
9
+ };
10
+ export const useLogger = () => {
11
+ const logger = useContext(LoggerContext);
12
+ if (!logger) {
13
+ throw new Error("Logger is not provided");
14
+ }
15
+ return logger;
16
+ };
17
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/logger/context.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAkB,MAAM,OAAO,CAAC;AAG3E,MAAM,aAAa,GAAG,aAAa,CAAqB,SAAS,CAAC,CAAC;AAEnE,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAC7B,MAAM,EACN,QAAQ,GAIT,EAAE,EAAE,CAAC,CACJ,KAAC,aAAa,CAAC,QAAQ,IAAC,KAAK,EAAE,MAAM,YAAG,QAAQ,GAA0B,CAC3E,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EACzB,WAAW,EACX,QAAQ,GAIT,EAAE,EAAE;IACH,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,MAAM,WAAW,GAAG,OAAO,CACzB,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,EAAE,WAAW,EAAE,CAAC,EACjD,CAAC,MAAM,EAAE,WAAW,CAAC,CACtB,CAAC;IACF,OAAO,KAAC,cAAc,IAAC,MAAM,EAAE,WAAW,YAAG,QAAQ,GAAkB,CAAC;AAC1E,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,EAAE;IAC5B,MAAM,MAAM,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;IACzC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
@@ -0,0 +1,35 @@
1
+ export declare const LOG_LEVELS: readonly ["debug", "info", "warn", "error", "fatal"];
2
+ export type LogLevel = (typeof LOG_LEVELS)[number];
3
+ export declare class Logger {
4
+ private parent?;
5
+ private contextName?;
6
+ private extraInfo?;
7
+ private logLevel?;
8
+ private shouldOutputFatal?;
9
+ private shouldOutputError?;
10
+ private shouldOutputWarn?;
11
+ private shouldOutputInfo?;
12
+ private shouldOutputDebug?;
13
+ constructor(option: {
14
+ contextName: string;
15
+ parent?: Logger;
16
+ extraInfo?: Record<string, string>;
17
+ logLevel?: LogLevel;
18
+ });
19
+ generateChildLogger({ contextName, extraInfo, }: {
20
+ contextName: string;
21
+ extraInfo?: Record<string, string>;
22
+ }): Logger;
23
+ private getContextPath;
24
+ private getExtraInfo;
25
+ private getPrefix;
26
+ private getSuffix;
27
+ fatal(...args: string[]): void;
28
+ error(...args: string[]): void;
29
+ warn(...args: string[]): void;
30
+ info(...args: string[]): void;
31
+ debug(...args: string[]): void;
32
+ /** Debug-only helper that accepts non-string values. */
33
+ debugUnknown(...args: unknown[]): void;
34
+ }
35
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,sDAAuD,CAAC;AAC/E,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnD,qBAAa,MA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LEVELS = ["debug", "info", "warn", "error", "fatal"];
2
+ export class Logger {
3
+ parent;
4
+ contextName;
5
+ extraInfo;
6
+ logLevel;
7
+ shouldOutputFatal;
8
+ shouldOutputError;
9
+ shouldOutputWarn;
10
+ shouldOutputInfo;
11
+ shouldOutputDebug;
12
+ constructor(option) {
13
+ this.contextName = option.contextName;
14
+ this.parent = option.parent;
15
+ this.extraInfo = option.extraInfo;
16
+ this.logLevel = option.logLevel ?? "debug";
17
+ this.shouldOutputDebug = this.logLevel === "debug";
18
+ this.shouldOutputInfo = this.shouldOutputDebug || this.logLevel === "info";
19
+ this.shouldOutputWarn = this.shouldOutputInfo || this.logLevel === "warn";
20
+ this.shouldOutputError = this.shouldOutputWarn || this.logLevel === "error";
21
+ this.shouldOutputFatal =
22
+ this.shouldOutputError || this.logLevel === "fatal";
23
+ if (!this.parent) {
24
+ this.info("start root logger");
25
+ }
26
+ }
27
+ generateChildLogger({ contextName, extraInfo, }) {
28
+ return new Logger({
29
+ contextName,
30
+ parent: this,
31
+ extraInfo,
32
+ logLevel: this.logLevel,
33
+ });
34
+ }
35
+ getContextPath() {
36
+ return [
37
+ ...(this.parent?.getContextPath() ?? []),
38
+ ...(this.contextName ? [this.contextName] : []),
39
+ ];
40
+ }
41
+ getExtraInfo() {
42
+ return [
43
+ ...(this.parent?.getExtraInfo() ?? []),
44
+ ...(this.extraInfo ? [this.extraInfo] : []),
45
+ ];
46
+ }
47
+ getPrefix() {
48
+ const date = new Date();
49
+ return `${date.toISOString()} [${this.getContextPath().join(" > ")}]`;
50
+ }
51
+ getSuffix() {
52
+ return this.getExtraInfo()
53
+ .flatMap((info) => Object.entries(info).map(([key, value]) => `${key}: ${value}`))
54
+ .join(". ");
55
+ }
56
+ fatal(...args) {
57
+ if (this.shouldOutputFatal) {
58
+ console.error("[FATAL]", this.getPrefix(), ...args, this.getSuffix());
59
+ }
60
+ }
61
+ error(...args) {
62
+ if (this.shouldOutputError) {
63
+ console.error("[ERROR]", this.getPrefix(), ...args, this.getSuffix());
64
+ }
65
+ }
66
+ warn(...args) {
67
+ if (this.shouldOutputWarn) {
68
+ console.warn("[WARN]", this.getPrefix(), ...args, this.getSuffix());
69
+ }
70
+ }
71
+ info(...args) {
72
+ if (this.shouldOutputInfo) {
73
+ console.info("[INFO]", this.getPrefix(), ...args, this.getSuffix());
74
+ }
75
+ }
76
+ debug(...args) {
77
+ if (this.shouldOutputDebug) {
78
+ console.debug("[DEBUG]", this.getPrefix(), ...args, this.getSuffix());
79
+ }
80
+ }
81
+ /** Debug-only helper that accepts non-string values. */
82
+ debugUnknown(...args) {
83
+ if (this.shouldOutputDebug) {
84
+ console.debug("[DEBUG]", this.getPrefix(), ...args, this.getSuffix());
85
+ }
86
+ }
87
+ }
88
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAU,CAAC;AAG/E,MAAM,OAAO,MAAM;IACT,MAAM,CAAU;IAChB,WAAW,CAAU;IACrB,SAAS,CAA0B;IACnC,QAAQ,CAAY;IAEpB,iBAAiB,CAAW;IAC5B,iBAAiB,CAAW;IAC5B,gBAAgB,CAAW;IAC3B,gBAAgB,CAAW;IAC3B,iBAAiB,CAAW;IAEpC,YAAY,MAKX;QACC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,OAAO,CAAC;QAC3C,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,QAAQ,KAAK,OAAO,CAAC;QACnD,IAAI,CAAC,gBAA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AAI,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,GAAG,IAAc;QAC5B,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC3B,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,EAAE,GAAG,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;IAED,wDAAwD;IACjD,YAAY,CAAC,GAAG,IAAe;QACpC,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC3B,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,EAAE,GAAG,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,49 @@
1
+ import { type ReactNode } from "react";
2
+ import type { UnitChangeServerEvent } from "@mirage-x/core";
3
+ export type Authentication = {
4
+ token: string;
5
+ clearAuth: () => Promise<void>;
6
+ };
7
+ export type MainRootContextValue = {
8
+ connectionId: string;
9
+ ownerUser?: {
10
+ id: string;
11
+ username: string;
12
+ };
13
+ ownerId: string;
14
+ lang: string;
15
+ eventEmitter: (unitChangeEvent: UnitChangeServerEvent) => void;
16
+ functionMap: Map<string, (...args: unknown[]) => unknown>;
17
+ authentication?: Authentication;
18
+ };
19
+ export declare const MainRootContextProvider: (props: {
20
+ value: MainRootContextValue;
21
+ children: ReactNode;
22
+ }) => import("react").JSX.Element;
23
+ export declare const useMainRootContext: () => MainRootContextValue;
24
+ type Response<T> = {
25
+ status: "success";
26
+ data: T;
27
+ } | {
28
+ status: "loading";
29
+ } | {
30
+ status: "error";
31
+ reason: "NotFound" | "Unknown";
32
+ };
33
+ type ResoniteUser = {
34
+ id: string;
35
+ username: string;
36
+ normalizedUsername: string;
37
+ registrationDate: string;
38
+ isVerified: boolean;
39
+ isLocked: boolean;
40
+ supressBanEvasion: boolean;
41
+ "2fa_login": boolean;
42
+ tags: string[];
43
+ profile?: {
44
+ iconUrl?: string;
45
+ };
46
+ };
47
+ export declare const useResoniteUser: (platformUrl: string, userId: string) => Response<ResoniteUser>;
48
+ export {};
49
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/main/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,SAAS,EAGf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAE5D,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,CAAC,eAAe,EAAE,qBAAqB,KAAK,IAAI,CAAC;IAC/D,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,CAAC;IAC1D,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC,CAAC;AAIF,eAAO,MAAM,uBAAuB,GAAI,OAAO;IAC7C,KAAK,EAAE,oBAAoB,CAAC;IAC5B,QAAQ,EAAE,SAAS,CAAC;CACrB,gCAIA,CAAC;AAEF,eAAO,MAAM,kBAAkB,4BAM9B,CAAC;AAEF,KAAK,QAAQ,CAAC,CAAC,IACX;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GAC9B;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,GACrB;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,UAAU,GAAG,SAAS,CAAA;CAAE,CAAC;AAExD,KAAK,YAAY,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,WAAW,EAAE,OAAO,CAAC;IACrB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,aAAa,MAAM,EAAE,QAAQ,MAAM,2BAyBlE,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import axios from "axios";
3
+ import { createContext, useContext, useState, useEffect, } from "react";
4
+ const MainRootContext = createContext(null);
5
+ export const MainRootContextProvider = (props) => (_jsx(MainRootContext.Provider, { value: props.value, children: props.children }));
6
+ export const useMainRootContext = () => {
7
+ const context = useContext(MainRootContext);
8
+ if (context === null) {
9
+ throw new Error("MainRootContext is not provided");
10
+ }
11
+ return context;
12
+ };
13
+ export const useResoniteUser = (platformUrl, userId) => {
14
+ const [userResponse, setUserResponse] = useState({
15
+ status: "loading",
16
+ });
17
+ useEffect(() => {
18
+ axios
19
+ .get(`${platformUrl}users/${userId}`)
20
+ .then((res) => {
21
+ switch (res.status) {
22
+ case 200:
23
+ setUserResponse({ status: "success", data: res.data });
24
+ break;
25
+ case 404:
26
+ setUserResponse({ status: "error", reason: "NotFound" });
27
+ break;
28
+ default:
29
+ setUserResponse({ status: "error", reason: "Unknown" });
30
+ break;
31
+ }
32
+ })
33
+ .catch(() => setUserResponse({ status: "error", reason: "Unknown" }));
34
+ }, [platformUrl, userId]);
35
+ return userResponse;
36
+ };
37
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/main/index.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACL,aAAa,EACb,UAAU,EAEV,QAAQ,EACR,SAAS,GACV,MAAM,OAAO,CAAC;AAkBf,MAAM,eAAe,GAAG,aAAa,CAA8B,IAAI,CAAC,CAAC;AAEzE,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,KAGvC,EAAE,EAAE,CAAC,CACJ,KAAC,eAAe,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,CAAC,KAAK,YACzC,KAAK,CAAC,QAAQ,GACU,CAC5B,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,EAAE;IACrC,MAAM,OAAO,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IAC5C,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAsBF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,WAAmB,EAAE,MAAc,EAAE,EAAE;IACrE,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAyB;QACvE,MAAM,EAAE,SAAS;KAClB,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,KAAK;aACF,GAAG,CAAC,GAAG,WAAW,SAAS,MAAM,EAAE,CAAC;aACpC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;YACZ,QAAQ,GAAG,CAAC,MAAM,EAAE,CAAC;gBACnB,KAAK,GAAG;oBACN,eAAe,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;oBACvD,MAAM;gBACR,KAAK,GAAG;oBACN,eAAe,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;oBACzD,MAAM;gBACR;oBACE,eAAe,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;oBACxD,MAAM;YACV,CAAC;QACH,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,EAAE,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;IAC1E,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IAE1B,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { Authentication } from "./index.js";
2
+ export type MainRootProps = {
3
+ authentication?: Authentication;
4
+ closed: boolean;
5
+ };
6
+ //# sourceMappingURL=mainRootProps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mainRootProps.d.ts","sourceRoot":"","sources":["../../src/main/mainRootProps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,MAAM,aAAa,GAAG;IAC1B,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=mainRootProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mainRootProps.js","sourceRoot":"","sources":["../../src/main/mainRootProps.ts"],"names":[],"mappings":""}
@@ -0,0 +1,33 @@
1
+ import type { WebSocket } from "ws";
2
+ import type { ReactElement } from "react";
3
+ import type { Logger } from "../logger/index.js";
4
+ import type { UnitChangeClientEvent } from "@mirage-x/core";
5
+ import { LogicManager } from "./logicManager.js";
6
+ export declare class Connection {
7
+ id: string;
8
+ logger: Logger;
9
+ ws: WebSocket;
10
+ ownerIp: string;
11
+ logicManager: LogicManager | undefined;
12
+ version: string;
13
+ serverId: string;
14
+ authUrl: string;
15
+ event_count: number;
16
+ events: UnitChangeClientEvent[];
17
+ eventSendInterval: ReturnType<typeof setInterval> | undefined;
18
+ addEventCount: () => void;
19
+ constructor(init: {
20
+ ws: WebSocket;
21
+ logger: Logger;
22
+ onClose: (connection: Connection) => void;
23
+ ownerIp: string;
24
+ version: string;
25
+ serverId: string;
26
+ authUrl: string;
27
+ app: () => ReactElement;
28
+ platformApiUrl: string;
29
+ defaultAuthenticationToken?: string;
30
+ eventCountSolver?: (eventCount: number) => number;
31
+ });
32
+ }
33
+ //# sourceMappingURL=connection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/server/connection.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAgBjD,qBAAa,UAAU;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,SAAS,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,YAAY,GAAG,SAAS,CAAC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAEhB,WAAW,SAAK;IAChB,MAAM,EAAE,qBAAqB,EAAE,CAAM;IACrC,iBAAiB,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,GAAG,SAAS,CAAC;IAE9D,aAAa,aAEX;gBAEU,IAAI,EAAE;QAChB,EAAE,EAAE,SAAS,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;QAC1C,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,GAAG,EAAE,MAAM,YAAY,CAAC;QACxB,cAAc,EAAE,MAAM,CAAC;QACvB,0BAA0B,CAAC,EAAE,MAAM,CAAC;QACpC,gBAAgB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,MAAM,CAAC;KACnD;CAgHF"}
@@ -0,0 +1,120 @@
1
+ import json2emap from "json2emap";
2
+ import { randomUUID } from "node:crypto";
3
+ import { LogicManager } from "./logicManager.js";
4
+ export class Connection {
5
+ id;
6
+ logger;
7
+ ws;
8
+ ownerIp;
9
+ logicManager;
10
+ version;
11
+ serverId;
12
+ authUrl;
13
+ event_count = 0;
14
+ events = [];
15
+ eventSendInterval;
16
+ addEventCount = () => {
17
+ this.event_count += 1;
18
+ };
19
+ constructor(init) {
20
+ this.id = randomUUID();
21
+ this.logger = init.logger.generateChildLogger({
22
+ contextName: "connection",
23
+ extraInfo: { connectionId: this.id },
24
+ });
25
+ this.ws = init.ws;
26
+ this.ownerIp = init.ownerIp;
27
+ this.version = init.version;
28
+ this.serverId = init.serverId;
29
+ this.authUrl = init.authUrl;
30
+ this.ws.on("message", (message) => {
31
+ try {
32
+ const data = JSON.parse(message.toString());
33
+ console.debug("received", data);
34
+ const addEventCount = this.addEventCount.bind(this);
35
+ switch (data.type) {
36
+ case "init": {
37
+ const eventType = data.data.eventType ?? "sync";
38
+ if (eventType !== "sync") {
39
+ console.warn("unsupported eventType", eventType);
40
+ this.ws.close();
41
+ return;
42
+ }
43
+ this.ws.send(json2emap({ type: "version", data: { version: this.version } }));
44
+ this.ws.send(json2emap({
45
+ type: "initialData",
46
+ data: {
47
+ id: this.id,
48
+ version: this.version,
49
+ serverId: init.serverId,
50
+ },
51
+ }));
52
+ if (this.version !== data.data.version) {
53
+ this.ws.close();
54
+ console.info("version mismatch", this.version, data.data.version);
55
+ return;
56
+ }
57
+ if (init.eventCountSolver) {
58
+ this.eventSendInterval = setInterval(() => {
59
+ if (this.events.length > 0 && init.eventCountSolver) {
60
+ const count = init.eventCountSolver(this.events.length);
61
+ for (let i = 0; i < count; i++) {
62
+ if (this.events.length > 0) {
63
+ const [sendEvent, ...rest] = this.events;
64
+ this.events = rest;
65
+ if (sendEvent) {
66
+ this.ws.send(json2emap({ type: "sync", data: sendEvent }));
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }, 10);
72
+ }
73
+ this.logicManager = new LogicManager(init.app, init.logger, {
74
+ connectionId: this.id,
75
+ ownerId: data.data.ownerId,
76
+ lang: data.data.lang,
77
+ authUrl: this.authUrl,
78
+ platformApiUrl: init.platformApiUrl,
79
+ defaultAuthenticationToken: init.defaultAuthenticationToken,
80
+ });
81
+ this.logicManager.syncEventCallback = (event) => {
82
+ if (init.eventCountSolver) {
83
+ this.events.push(event);
84
+ }
85
+ else {
86
+ this.ws.send(json2emap({ type: "sync", data: event }));
87
+ }
88
+ addEventCount();
89
+ };
90
+ break;
91
+ }
92
+ default:
93
+ break;
94
+ }
95
+ }
96
+ catch (e) {
97
+ console.error(e);
98
+ }
99
+ });
100
+ const clean = () => {
101
+ this.logicManager?.close();
102
+ this.logicManager = undefined;
103
+ init.onClose(this);
104
+ if (this.eventSendInterval) {
105
+ clearInterval(this.eventSendInterval);
106
+ this.eventSendInterval = undefined;
107
+ }
108
+ console.log("close", this.id);
109
+ };
110
+ this.ws.on("close", clean);
111
+ setTimeout(() => {
112
+ if (!this.logicManager) {
113
+ console.warn("initialize timeout");
114
+ clean();
115
+ this.ws.close();
116
+ }
117
+ }, 5000);
118
+ }
119
+ }
120
+ //# sourceMappingURL=connection.js.map