yansu 0.0.0-beta.1
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/README.md +1 -0
- package/bin.mjs +18 -0
- package/dist/cli.d.mts +2 -0
- package/dist/cli.mjs +68 -0
- package/dist/dirs.d.mts +4 -0
- package/dist/dirs.mjs +6 -0
- package/dist/index.d.mts +78 -0
- package/dist/index.mjs +121 -0
- package/dist/nitro.json +15 -0
- package/dist/public/_nuxt/BHIHUtPz.js +4 -0
- package/dist/public/_nuxt/CCgOhniq.js +1 -0
- package/dist/public/_nuxt/CR6vfq1R.js +1 -0
- package/dist/public/_nuxt/DmxzK6E8.js +1 -0
- package/dist/public/_nuxt/builds/latest.json +1 -0
- package/dist/public/_nuxt/builds/meta/e9079134-f314-434b-b3a7-092c4a1e187d.json +1 -0
- package/dist/public/_nuxt/entry.DJ3VOi_0.css +1 -0
- package/dist/public/_nuxt/error-404.lC6KBLNm.css +1 -0
- package/dist/public/_nuxt/error-500.NtBcR2wE.css +1 -0
- package/dist/server/chunks/_/error-500.mjs +9 -0
- package/dist/server/chunks/build/_plugin-vue_export-helper-DjsbPc54.mjs +29 -0
- package/dist/server/chunks/build/client.precomputed.mjs +3 -0
- package/dist/server/chunks/build/error-404-Du0ot2hm.mjs +369 -0
- package/dist/server/chunks/build/error-500-Y3RUV6n2.mjs +73 -0
- package/dist/server/chunks/build/server.mjs +727 -0
- package/dist/server/chunks/nitro/nitro.mjs +5176 -0
- package/dist/server/chunks/routes/api/metadata.json.mjs +147 -0
- package/dist/server/chunks/routes/api/platform.json.mjs +20 -0
- package/dist/server/chunks/routes/renderer.mjs +408 -0
- package/dist/server/chunks/virtual/_virtual_spa-template.mjs +3 -0
- package/dist/server/index.mjs +9 -0
- package/dist/server/node_modules/.nitro/@vue/shared@3.5.25/dist/shared.cjs.prod.js +604 -0
- package/dist/server/node_modules/.nitro/@vue/shared@3.5.25/package.json +47 -0
- package/dist/server/node_modules/.nitro/@vue/shared@3.5.26/dist/shared.cjs.prod.js +604 -0
- package/dist/server/node_modules/.nitro/@vue/shared@3.5.26/package.json +47 -0
- package/dist/server/node_modules/@babel/parser/lib/index.js +14662 -0
- package/dist/server/node_modules/@babel/parser/package.json +50 -0
- package/dist/server/node_modules/@vue/compiler-core/dist/compiler-core.cjs.prod.js +6763 -0
- package/dist/server/node_modules/@vue/compiler-core/package.json +58 -0
- package/dist/server/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +689 -0
- package/dist/server/node_modules/@vue/compiler-dom/package.json +57 -0
- package/dist/server/node_modules/@vue/compiler-ssr/dist/compiler-ssr.cjs.js +1413 -0
- package/dist/server/node_modules/@vue/compiler-ssr/package.json +34 -0
- package/dist/server/node_modules/@vue/reactivity/dist/reactivity.cjs.prod.js +1853 -0
- package/dist/server/node_modules/@vue/reactivity/package.json +55 -0
- package/dist/server/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js +6770 -0
- package/dist/server/node_modules/@vue/runtime-core/package.json +52 -0
- package/dist/server/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.prod.js +1732 -0
- package/dist/server/node_modules/@vue/runtime-dom/package.json +60 -0
- package/dist/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js +879 -0
- package/dist/server/node_modules/@vue/server-renderer/package.json +55 -0
- package/dist/server/node_modules/ansis/index.cjs +1 -0
- package/dist/server/node_modules/ansis/index.mjs +1 -0
- package/dist/server/node_modules/ansis/package.json +25 -0
- package/dist/server/node_modules/birpc/dist/index.mjs +173 -0
- package/dist/server/node_modules/birpc/package.json +56 -0
- package/dist/server/node_modules/consola/dist/chunks/prompt.mjs +280 -0
- package/dist/server/node_modules/consola/dist/core.mjs +512 -0
- package/dist/server/node_modules/consola/dist/index.mjs +651 -0
- package/dist/server/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs +72 -0
- package/dist/server/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs +288 -0
- package/dist/server/node_modules/consola/package.json +136 -0
- package/dist/server/node_modules/devalue/index.js +4 -0
- package/dist/server/node_modules/devalue/package.json +37 -0
- package/dist/server/node_modules/devalue/src/base64.js +110 -0
- package/dist/server/node_modules/devalue/src/constants.js +6 -0
- package/dist/server/node_modules/devalue/src/parse.js +205 -0
- package/dist/server/node_modules/devalue/src/stringify.js +265 -0
- package/dist/server/node_modules/devalue/src/uneval.js +407 -0
- package/dist/server/node_modules/devalue/src/utils.js +118 -0
- package/dist/server/node_modules/entities/dist/commonjs/decode-codepoint.js +77 -0
- package/dist/server/node_modules/entities/dist/commonjs/decode.js +568 -0
- package/dist/server/node_modules/entities/dist/commonjs/generated/decode-data-html.js +7 -0
- package/dist/server/node_modules/entities/dist/commonjs/generated/decode-data-xml.js +7 -0
- package/dist/server/node_modules/entities/dist/commonjs/internal/bin-trie-flags.js +21 -0
- package/dist/server/node_modules/entities/dist/commonjs/internal/decode-shared.js +31 -0
- package/dist/server/node_modules/entities/dist/commonjs/package.json +3 -0
- package/dist/server/node_modules/entities/package.json +113 -0
- package/dist/server/node_modules/estree-walker/dist/umd/estree-walker.js +344 -0
- package/dist/server/node_modules/estree-walker/package.json +37 -0
- package/dist/server/node_modules/get-port-please/dist/index.mjs +430 -0
- package/dist/server/node_modules/get-port-please/package.json +39 -0
- package/dist/server/node_modules/hookable/dist/index.mjs +290 -0
- package/dist/server/node_modules/hookable/package.json +49 -0
- package/dist/server/node_modules/source-map-js/lib/array-set.js +121 -0
- package/dist/server/node_modules/source-map-js/lib/base64-vlq.js +140 -0
- package/dist/server/node_modules/source-map-js/lib/base64.js +67 -0
- package/dist/server/node_modules/source-map-js/lib/binary-search.js +111 -0
- package/dist/server/node_modules/source-map-js/lib/mapping-list.js +79 -0
- package/dist/server/node_modules/source-map-js/lib/quick-sort.js +132 -0
- package/dist/server/node_modules/source-map-js/lib/source-map-consumer.js +1188 -0
- package/dist/server/node_modules/source-map-js/lib/source-map-generator.js +444 -0
- package/dist/server/node_modules/source-map-js/lib/source-node.js +413 -0
- package/dist/server/node_modules/source-map-js/lib/util.js +594 -0
- package/dist/server/node_modules/source-map-js/package.json +71 -0
- package/dist/server/node_modules/source-map-js/source-map.js +8 -0
- package/dist/server/node_modules/structured-clone-es/dist/index.mjs +285 -0
- package/dist/server/node_modules/structured-clone-es/package.json +56 -0
- package/dist/server/node_modules/ufo/dist/index.mjs +638 -0
- package/dist/server/node_modules/ufo/package.json +47 -0
- package/dist/server/node_modules/unhead/dist/index.mjs +9 -0
- package/dist/server/node_modules/unhead/dist/parser.mjs +508 -0
- package/dist/server/node_modules/unhead/dist/plugins.mjs +101 -0
- package/dist/server/node_modules/unhead/dist/scripts.mjs +30 -0
- package/dist/server/node_modules/unhead/dist/server.mjs +182 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.B578PsDV.mjs +266 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.BPM0-cfG.mjs +44 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.BYvz9V1x.mjs +43 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.BpRRHAhY.mjs +194 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.CApf5sj3.mjs +148 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.DH45uomy.mjs +180 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.DQc16pHI.mjs +196 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.DZbvapt-.mjs +70 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.Djo8ep_Y.mjs +166 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.yem5I2v_.mjs +38 -0
- package/dist/server/node_modules/unhead/dist/utils.mjs +5 -0
- package/dist/server/node_modules/unhead/package.json +105 -0
- package/dist/server/node_modules/vue/dist/vue.cjs.js +80 -0
- package/dist/server/node_modules/vue/dist/vue.cjs.prod.js +66 -0
- package/dist/server/node_modules/vue/index.js +7 -0
- package/dist/server/node_modules/vue/index.mjs +1 -0
- package/dist/server/node_modules/vue/package.json +112 -0
- package/dist/server/node_modules/vue/server-renderer/index.mjs +1 -0
- package/dist/server/node_modules/vue-bundle-renderer/dist/runtime.mjs +301 -0
- package/dist/server/node_modules/vue-bundle-renderer/package.json +55 -0
- package/dist/server/node_modules/ws/lib/buffer-util.js +131 -0
- package/dist/server/node_modules/ws/lib/constants.js +19 -0
- package/dist/server/node_modules/ws/lib/event-target.js +292 -0
- package/dist/server/node_modules/ws/lib/extension.js +203 -0
- package/dist/server/node_modules/ws/lib/limiter.js +55 -0
- package/dist/server/node_modules/ws/lib/permessage-deflate.js +528 -0
- package/dist/server/node_modules/ws/lib/receiver.js +706 -0
- package/dist/server/node_modules/ws/lib/sender.js +602 -0
- package/dist/server/node_modules/ws/lib/stream.js +161 -0
- package/dist/server/node_modules/ws/lib/subprotocol.js +62 -0
- package/dist/server/node_modules/ws/lib/validation.js +152 -0
- package/dist/server/node_modules/ws/lib/websocket-server.js +554 -0
- package/dist/server/node_modules/ws/lib/websocket.js +1393 -0
- package/dist/server/node_modules/ws/package.json +69 -0
- package/dist/server/node_modules/ws/wrapper.mjs +8 -0
- package/dist/server/package.json +32 -0
- package/dist/shared/yansu.DmdNF4qf.mjs +151 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# YanSu WEB
|
package/bin.mjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { execFileSync } from 'node:child_process'
|
|
4
|
+
import { createRequire } from 'node:module'
|
|
5
|
+
import { dirname, resolve } from 'node:path'
|
|
6
|
+
import process from 'node:process'
|
|
7
|
+
import { fileURLToPath } from 'node:url'
|
|
8
|
+
|
|
9
|
+
const require = createRequire(import.meta.url)
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
11
|
+
const __dirname = dirname(__filename)
|
|
12
|
+
|
|
13
|
+
const args = [
|
|
14
|
+
resolve(__dirname, 'dist', 'cli.mjs'),
|
|
15
|
+
...process.argv.slice(2),
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
execFileSync(String(require('electron')), args, { stdio: 'inherit' })
|
package/dist/cli.d.mts
ADDED
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { fork } from 'node:child_process';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import process from 'node:process';
|
|
5
|
+
import c from 'ansis';
|
|
6
|
+
import { cac } from 'cac';
|
|
7
|
+
import consola from 'consola';
|
|
8
|
+
import { getPort } from 'get-port-please';
|
|
9
|
+
import { serverDir } from './dirs.mjs';
|
|
10
|
+
import { b as MARK_GIT, c as createMainWindow } from './shared/yansu.DmdNF4qf.mjs';
|
|
11
|
+
import 'node:url';
|
|
12
|
+
|
|
13
|
+
const name = "yansu";
|
|
14
|
+
const version = "0.0.0-beta.1";
|
|
15
|
+
|
|
16
|
+
const require$1 = createRequire(import.meta.url);
|
|
17
|
+
const cli = cac(name);
|
|
18
|
+
cli.version(version).option("--host <host>", "Host to listen on", { default: "127.0.0.1" }).option("--port <port>", "Port to listen on", { default: "7777" }).option("--width <width>", "Window width").option("--height <height>", "Window height");
|
|
19
|
+
cli.command("[...args]", "Start YanSu IDE").action(async (args, options) => {
|
|
20
|
+
const { app } = require$1("electron");
|
|
21
|
+
const host = options.host;
|
|
22
|
+
const port = await getPort({
|
|
23
|
+
port: Number.parseInt(options.port),
|
|
24
|
+
portRange: [7777, 9e3],
|
|
25
|
+
host
|
|
26
|
+
});
|
|
27
|
+
const url = `http://${host === "127.0.0.1" ? "localhost" : host}:${port}`;
|
|
28
|
+
consola.log(c.green`${MARK_GIT} Starting YanSu IDE at`, c.green(url), "\n");
|
|
29
|
+
const serverEntry = join(serverDir, "index.mjs");
|
|
30
|
+
const child = fork(serverEntry, [], {
|
|
31
|
+
env: {
|
|
32
|
+
...process.env,
|
|
33
|
+
HOST: host,
|
|
34
|
+
PORT: String(port),
|
|
35
|
+
NITRO_HOST: host,
|
|
36
|
+
NITRO_PORT: String(port)
|
|
37
|
+
},
|
|
38
|
+
stdio: "inherit"
|
|
39
|
+
});
|
|
40
|
+
child.on("error", (error) => {
|
|
41
|
+
console.error(c.red`Failed to start server:`, error);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
});
|
|
44
|
+
child.on("exit", (code) => {
|
|
45
|
+
process.exit(code ?? 0);
|
|
46
|
+
});
|
|
47
|
+
app.setName("YanSu");
|
|
48
|
+
app.on("window-all-closed", () => {
|
|
49
|
+
child.kill();
|
|
50
|
+
app.quit();
|
|
51
|
+
});
|
|
52
|
+
try {
|
|
53
|
+
await app.whenReady();
|
|
54
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
55
|
+
const mainWindow = createMainWindow({
|
|
56
|
+
url,
|
|
57
|
+
width: options.width ? Number.parseInt(options.width) : void 0,
|
|
58
|
+
height: options.height ? Number.parseInt(options.height) : void 0
|
|
59
|
+
});
|
|
60
|
+
await mainWindow.loadURL(url);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error(c.red`Failed to start:`, error);
|
|
63
|
+
child.kill();
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
cli.help();
|
|
68
|
+
cli.parse();
|
package/dist/dirs.d.mts
ADDED
package/dist/dirs.mjs
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { BrowserWindow } from 'electron';
|
|
2
|
+
import { createBirpcGroup } from 'birpc';
|
|
3
|
+
import { WebSocketServer } from 'ws';
|
|
4
|
+
|
|
5
|
+
interface Metadata {
|
|
6
|
+
cwd: string;
|
|
7
|
+
}
|
|
8
|
+
interface PlatformInfo {
|
|
9
|
+
platform: string;
|
|
10
|
+
isMacOS: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface YanSuPayload {
|
|
13
|
+
hash: string;
|
|
14
|
+
timestamp: number;
|
|
15
|
+
metadata: Metadata;
|
|
16
|
+
platform: PlatformInfo;
|
|
17
|
+
}
|
|
18
|
+
interface ClientFunctions {
|
|
19
|
+
onHeartbeat?: (message: string, timestamp: number) => void;
|
|
20
|
+
}
|
|
21
|
+
interface ServerFunctions {
|
|
22
|
+
getPayload: (force?: boolean) => Promise<YanSuPayload>;
|
|
23
|
+
getMetadata: () => Promise<Metadata>;
|
|
24
|
+
getPlatformInfo: () => Promise<PlatformInfo>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface CreateServerFunctionsOptions {
|
|
28
|
+
/**
|
|
29
|
+
* 工作目录
|
|
30
|
+
*/
|
|
31
|
+
cwd?: string;
|
|
32
|
+
/**
|
|
33
|
+
* 运行模式
|
|
34
|
+
*/
|
|
35
|
+
mode: 'dev' | 'build';
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 创建 YanSu IDE 的服务端函数
|
|
39
|
+
*/
|
|
40
|
+
declare function createServerFunctions(options: CreateServerFunctionsOptions): ServerFunctions;
|
|
41
|
+
|
|
42
|
+
interface WindowOptions {
|
|
43
|
+
url: string;
|
|
44
|
+
width?: number;
|
|
45
|
+
height?: number;
|
|
46
|
+
alwaysOnTop?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 创建 Electron 主窗口
|
|
50
|
+
*/
|
|
51
|
+
declare function createMainWindow(options: WindowOptions): BrowserWindow;
|
|
52
|
+
|
|
53
|
+
interface CreateWsServerOptions extends CreateServerFunctionsOptions {
|
|
54
|
+
/**
|
|
55
|
+
* WebSocket 端口
|
|
56
|
+
*/
|
|
57
|
+
port?: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* WebSocket 服务器返回值
|
|
61
|
+
*/
|
|
62
|
+
interface WsServerReturn {
|
|
63
|
+
port: number;
|
|
64
|
+
wss: WebSocketServer;
|
|
65
|
+
rpc: ReturnType<typeof createBirpcGroup<ClientFunctions, ServerFunctions>>;
|
|
66
|
+
serverFunctions: ServerFunctions;
|
|
67
|
+
/**
|
|
68
|
+
* 向所有连接的客户端广播消息
|
|
69
|
+
*/
|
|
70
|
+
broadcast: (fn: keyof ClientFunctions, ...args: any[]) => void;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 创建 WebSocket 服务器用于 RPC 通信(支持双向 RPC)
|
|
74
|
+
*/
|
|
75
|
+
declare function createWsServer(options: CreateWsServerOptions): Promise<WsServerReturn>;
|
|
76
|
+
|
|
77
|
+
export { createMainWindow, createServerFunctions, createWsServer };
|
|
78
|
+
export type { CreateServerFunctionsOptions, CreateWsServerOptions, WindowOptions, WsServerReturn };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import c from 'ansis';
|
|
3
|
+
import consola from 'consola';
|
|
4
|
+
import { hash } from 'ohash';
|
|
5
|
+
import { M as MARK_INFO, a as MARK_CHECK } from './shared/yansu.DmdNF4qf.mjs';
|
|
6
|
+
export { c as createMainWindow } from './shared/yansu.DmdNF4qf.mjs';
|
|
7
|
+
import { createBirpcGroup } from 'birpc';
|
|
8
|
+
import { getPort } from 'get-port-please';
|
|
9
|
+
import { parse, stringify } from 'structured-clone-es';
|
|
10
|
+
import { WebSocketServer } from 'ws';
|
|
11
|
+
import 'node:module';
|
|
12
|
+
import 'node:path';
|
|
13
|
+
|
|
14
|
+
function createServerFunctions(options) {
|
|
15
|
+
const cwd = options.cwd || process.cwd();
|
|
16
|
+
let _payload = null;
|
|
17
|
+
async function getMetadata() {
|
|
18
|
+
return {
|
|
19
|
+
cwd
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
async function getPlatformInfo() {
|
|
23
|
+
const platform = process.platform;
|
|
24
|
+
return {
|
|
25
|
+
platform,
|
|
26
|
+
isMacOS: platform === "darwin"
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
async function getPayload(force = false) {
|
|
30
|
+
if (force)
|
|
31
|
+
_payload = null;
|
|
32
|
+
if (!_payload)
|
|
33
|
+
_payload = _getPayload();
|
|
34
|
+
return _payload;
|
|
35
|
+
}
|
|
36
|
+
async function _getPayload() {
|
|
37
|
+
consola.log(c.cyan`${MARK_INFO} 正在加载 YanSu IDE 数据...`);
|
|
38
|
+
const metadata = await getMetadata();
|
|
39
|
+
const platform = await getPlatformInfo();
|
|
40
|
+
const hash$1 = hash({
|
|
41
|
+
cwd,
|
|
42
|
+
timestamp: Date.now()
|
|
43
|
+
});
|
|
44
|
+
consola.log(c.green`${MARK_CHECK} YanSu IDE 数据加载完成`);
|
|
45
|
+
return {
|
|
46
|
+
hash: hash$1,
|
|
47
|
+
timestamp: Date.now(),
|
|
48
|
+
metadata,
|
|
49
|
+
platform
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
getPayload,
|
|
54
|
+
getMetadata,
|
|
55
|
+
getPlatformInfo
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const serverEventNames = ["onHeartbeat"];
|
|
60
|
+
|
|
61
|
+
async function createWsServer(options) {
|
|
62
|
+
const port = options.port ?? await getPort({ port: 7812, random: true });
|
|
63
|
+
const wss = new WebSocketServer({
|
|
64
|
+
port
|
|
65
|
+
});
|
|
66
|
+
const wsClients = /* @__PURE__ */ new Set();
|
|
67
|
+
const serverFunctions = createServerFunctions(options);
|
|
68
|
+
const rpc = createBirpcGroup(
|
|
69
|
+
serverFunctions,
|
|
70
|
+
[],
|
|
71
|
+
{
|
|
72
|
+
eventNames: serverEventNames,
|
|
73
|
+
onError(error, name) {
|
|
74
|
+
console.error(c.red`⬢ RPC 错误 "${c.bold(name)}":`);
|
|
75
|
+
console.error(error);
|
|
76
|
+
throw error;
|
|
77
|
+
},
|
|
78
|
+
timeout: 12e4
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
wss.on("connection", (ws) => {
|
|
82
|
+
wsClients.add(ws);
|
|
83
|
+
const channel = {
|
|
84
|
+
post: (d) => ws.send(d),
|
|
85
|
+
on: (fn) => {
|
|
86
|
+
ws.on("message", (data) => {
|
|
87
|
+
fn(data);
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
serialize: stringify,
|
|
91
|
+
deserialize: parse
|
|
92
|
+
};
|
|
93
|
+
rpc.updateChannels((c2) => {
|
|
94
|
+
c2.push(channel);
|
|
95
|
+
});
|
|
96
|
+
ws.on("close", () => {
|
|
97
|
+
wsClients.delete(ws);
|
|
98
|
+
rpc.updateChannels((c2) => {
|
|
99
|
+
const index = c2.indexOf(channel);
|
|
100
|
+
if (index >= 0)
|
|
101
|
+
c2.splice(index, 1);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
console.log(c.green`${MARK_CHECK} WebSocket 客户端已连接 (当前连接数: ${wsClients.size})`);
|
|
105
|
+
});
|
|
106
|
+
function broadcast(fn, ...args) {
|
|
107
|
+
const broadcastFn = rpc.broadcast[fn];
|
|
108
|
+
if (broadcastFn) {
|
|
109
|
+
broadcastFn(...args);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
port,
|
|
114
|
+
wss,
|
|
115
|
+
rpc,
|
|
116
|
+
serverFunctions,
|
|
117
|
+
broadcast
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export { createServerFunctions, createWsServer };
|
package/dist/nitro.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"date": "2026-01-06T05:26:18.673Z",
|
|
3
|
+
"preset": "node-server",
|
|
4
|
+
"framework": {
|
|
5
|
+
"name": "nuxt",
|
|
6
|
+
"version": "4.2.2"
|
|
7
|
+
},
|
|
8
|
+
"versions": {
|
|
9
|
+
"nitro": "2.12.8"
|
|
10
|
+
},
|
|
11
|
+
"commands": {
|
|
12
|
+
"preview": "node server/index.mjs"
|
|
13
|
+
},
|
|
14
|
+
"config": {}
|
|
15
|
+
}
|