dsh-watch-together 0.2.0 → 0.2.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/CHANGELOG.md +49 -0
- package/README.md +10 -2
- package/docs/INTERFACES.zh.md +73 -0
- package/dsh.plugin.json +1 -1
- package/examples/floating-chat/glass_window.py +7 -0
- package/examples/floating-chat/glass_window_gpu.py +502 -0
- package/examples/floating-chat/mic-dsh.png +0 -0
- package/examples/floating-chat/requirements-glass.txt +8 -9
- package/examples/floating-chat/window.py +1454 -3372
- package/examples/floating-chat/window_protocol.py +167 -0
- package/lib/client.js +306 -0
- package/package.json +100 -89
- package/src/chat-server.js +201 -198
- package/src/chat-store.js +10 -0
- package/src/handler.js +266 -261
- package/src/index.js +156 -130
- package/src/input-surface.js +156 -154
- package/src/interfaces.js +43 -0
- package/src/public-api.js +24 -0
- package/src/recognition-interface.js +43 -0
- package/src/register.js +7 -2
- package/src/settings/config.js +146 -0
- package/src/settings/deps.js +163 -0
- package/src/settings/page.html +233 -0
- package/src/settings/page.js +11 -0
- package/src/settings/server.js +195 -0
- package/src/tts-interface.js +59 -0
- package/src/wake-failure.js +67 -0
- package/src/watch-loop.js +37 -11
- package/src/watch-run.js +1007 -1002
- package/src/window-interface.js +81 -0
- package/src/window-protocol.js +122 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* interfaces.js — the plugin's public seams.
|
|
3
|
+
*
|
|
4
|
+
* The watch loop should be able to run with:
|
|
5
|
+
* - any recognition provider (storyboard / ASR / a test double),
|
|
6
|
+
* - any TTS bus (companion voice plugin / local adapter / none),
|
|
7
|
+
* - any floating-window transport (bundled Python / web / test double).
|
|
8
|
+
*
|
|
9
|
+
* These objects are the only things that cross those seams. Keep them small
|
|
10
|
+
* and versioned; adapters live in their own files.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { appendChat, readChat } from './chat-store.js';
|
|
14
|
+
import { createRecognitionInterface } from './recognition-interface.js';
|
|
15
|
+
import { createTtsInterface } from './tts-interface.js';
|
|
16
|
+
import { createWindowInterface } from './window-interface.js';
|
|
17
|
+
import * as speechBus from './speech-bus.js';
|
|
18
|
+
import { runStoryboard } from 'dsh-video-storyboard/pipeline';
|
|
19
|
+
import { formatManifest } from 'dsh-video-storyboard/format';
|
|
20
|
+
import { cachedCues } from './lines-util.js';
|
|
21
|
+
|
|
22
|
+
export const INTERFACE_VERSION = '1.0.0';
|
|
23
|
+
|
|
24
|
+
export function createWatchInterfaces(overrides = {}) {
|
|
25
|
+
const recognition = overrides.recognition ?? createRecognitionInterface({
|
|
26
|
+
runStoryboard,
|
|
27
|
+
formatManifest,
|
|
28
|
+
cues: cachedCues,
|
|
29
|
+
});
|
|
30
|
+
const tts = overrides.tts ?? createTtsInterface(speechBus);
|
|
31
|
+
const window = overrides.window ?? createWindowInterface();
|
|
32
|
+
const chat = overrides.chat ?? Object.freeze({
|
|
33
|
+
append: appendChat,
|
|
34
|
+
read: readChat,
|
|
35
|
+
});
|
|
36
|
+
return Object.freeze({
|
|
37
|
+
version: INTERFACE_VERSION,
|
|
38
|
+
recognition,
|
|
39
|
+
tts,
|
|
40
|
+
window,
|
|
41
|
+
chat,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* public-api.js — importable surface for companion plugins, tests and tools.
|
|
3
|
+
* The DSH plugin entry point remains src/index.js.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
INTERFACE_VERSION,
|
|
8
|
+
createWatchInterfaces,
|
|
9
|
+
} from './interfaces.js';
|
|
10
|
+
export { createRecognitionInterface } from './recognition-interface.js';
|
|
11
|
+
export { createTtsInterface } from './tts-interface.js';
|
|
12
|
+
export { createWindowInterface } from './window-interface.js';
|
|
13
|
+
export {
|
|
14
|
+
WINDOW_PROTOCOL_VERSION,
|
|
15
|
+
WINDOW_EVENT_TYPES,
|
|
16
|
+
WINDOW_ACTION_TYPES,
|
|
17
|
+
windowEventFile,
|
|
18
|
+
windowOutboxFile,
|
|
19
|
+
normalizeWindowEvent,
|
|
20
|
+
appendWindowEvent,
|
|
21
|
+
readWindowEvents,
|
|
22
|
+
appendWindowAction,
|
|
23
|
+
readWindowActions,
|
|
24
|
+
} from './window-protocol.js';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* recognition-interface.js — the **recognition** side of the plugin.
|
|
3
|
+
*
|
|
4
|
+
* The watch loop needs three things from recognition: build one segment's
|
|
5
|
+
* storyboard, format its manifest, and look up cached transcript sentences.
|
|
6
|
+
* It must not know whether those come from dsh-video-storyboard, a local ASR
|
|
7
|
+
* service, or a test double.
|
|
8
|
+
*
|
|
9
|
+
* This adapter is deliberately tiny; the important part is that callers depend
|
|
10
|
+
* on this object instead of importing the storyboard package directly.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const RECOGNITION_INTERFACE_VERSION = 1;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {{
|
|
17
|
+
* runStoryboard: (args: object) => Promise<object>,
|
|
18
|
+
* formatManifest: (result: object, options?: object) => string,
|
|
19
|
+
* cues?: (input: string) => Promise<object[]>|object[],
|
|
20
|
+
* }} impl
|
|
21
|
+
*/
|
|
22
|
+
export function createRecognitionInterface(impl = {}) {
|
|
23
|
+
const { runStoryboard, formatManifest, cues = async () => [] } = impl;
|
|
24
|
+
if (typeof runStoryboard !== 'function') {
|
|
25
|
+
throw new TypeError('recognition: runStoryboard(args) is required');
|
|
26
|
+
}
|
|
27
|
+
if (typeof formatManifest !== 'function') {
|
|
28
|
+
throw new TypeError('recognition: formatManifest(result, options) is required');
|
|
29
|
+
}
|
|
30
|
+
return Object.freeze({
|
|
31
|
+
kind: 'recognition',
|
|
32
|
+
version: RECOGNITION_INTERFACE_VERSION,
|
|
33
|
+
segment(args) {
|
|
34
|
+
return runStoryboard(args);
|
|
35
|
+
},
|
|
36
|
+
manifest(result, options) {
|
|
37
|
+
return formatManifest(result, options);
|
|
38
|
+
},
|
|
39
|
+
cues(input) {
|
|
40
|
+
return cues(input);
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
package/src/register.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import * as handler from './handler.js';
|
|
13
|
+
import { createWatchInterfaces } from './interfaces.js';
|
|
13
14
|
import { watchToolSpec } from './tool-spec.js';
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -20,14 +21,18 @@ import { watchToolSpec } from './tool-spec.js';
|
|
|
20
21
|
* 闭包里拿快照会让第一次之后的所有调用都用旧 id。
|
|
21
22
|
* @returns {object[]} 已经 `defineTool()` 好的工具,调用方负责 register + 收集 disposer
|
|
22
23
|
*/
|
|
23
|
-
export function watchTools(defineTool, ctx, {
|
|
24
|
+
export function watchTools(defineTool, ctx, {
|
|
25
|
+
getSessionId = () => null, cache = new Map(), interfaces = null,
|
|
26
|
+
} = {}) {
|
|
27
|
+
// 一次 apply 只造一套接口:识别、TTS、悬浮窗各有自己的适配器,handler 不再直接 import 实现。
|
|
28
|
+
const api = interfaces ?? createWatchInterfaces();
|
|
24
29
|
return [
|
|
25
30
|
defineTool({
|
|
26
31
|
...watchToolSpec(),
|
|
27
32
|
// 第二个参数是宿主的 `ToolRunContext`:`signal` 是"这一轮被取消了"的唯一通知。
|
|
28
33
|
// 丢掉它的话,用户按停止之后阻塞循环还会继续轮询浏览器(默认 2×段长,封顶 600s)。
|
|
29
34
|
execute: (args, run) => handler.execute(ctx, args, {
|
|
30
|
-
sessionId: getSessionId(), cache, signal: run?.signal ?? null,
|
|
35
|
+
sessionId: getSessionId(), cache, interfaces: api, signal: run?.signal ?? null,
|
|
31
36
|
}),
|
|
32
37
|
}),
|
|
33
38
|
];
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* settings/config.js — 陪看设置页读写的小 JSON。
|
|
3
|
+
*
|
|
4
|
+
* 复用已有约定:
|
|
5
|
+
* ~/.dsh/video.json { browserPort, launchBrowser } (与分镜插件共享)
|
|
6
|
+
* ~/.dsh/voice.json { adapter } (voice-adapter.js 已读)
|
|
7
|
+
* ~/.dsh/watch.json { chatPort } (本页新增,chat-server 读取)
|
|
8
|
+
*
|
|
9
|
+
* 这里不 import chat-server,避免 chat-server -> settings -> chat-server 的环。
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
13
|
+
import { homedir } from 'node:os';
|
|
14
|
+
import { dirname, join } from 'node:path';
|
|
15
|
+
|
|
16
|
+
export const DEFAULT_CHAT_PORT = 9377;
|
|
17
|
+
const MAX_TEXT = 300;
|
|
18
|
+
|
|
19
|
+
export function dshHome(env = process.env) {
|
|
20
|
+
return env.DSH_HOME || join(env.USERPROFILE || env.HOME || homedir(), '.dsh');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function videoConfigPath(env = process.env) { return join(dshHome(env), 'video.json'); }
|
|
24
|
+
export function voiceConfigPath(env = process.env) { return join(dshHome(env), 'voice.json'); }
|
|
25
|
+
export function watchConfigPath(env = process.env) { return join(dshHome(env), 'watch.json'); }
|
|
26
|
+
|
|
27
|
+
function readObject(path) {
|
|
28
|
+
if (!existsSync(path)) return { data: {}, error: null, exists: false };
|
|
29
|
+
try {
|
|
30
|
+
const raw = JSON.parse(readFileSync(path, 'utf8'));
|
|
31
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
32
|
+
return { data: {}, error: '配置文件不是 JSON 对象', exists: true };
|
|
33
|
+
}
|
|
34
|
+
return { data: raw, error: null, exists: true };
|
|
35
|
+
} catch (e) {
|
|
36
|
+
return { data: {}, error: 'JSON 解析失败:' + String(e?.message ?? e), exists: true };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function writeObject(path, data) {
|
|
41
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
42
|
+
const tmp = path + '.' + process.pid + '.tmp';
|
|
43
|
+
try {
|
|
44
|
+
writeFileSync(tmp, JSON.stringify(data, null, 2) + '\n', { mode: 0o600 });
|
|
45
|
+
renameSync(tmp, path);
|
|
46
|
+
} finally {
|
|
47
|
+
if (existsSync(tmp)) rmSync(tmp, { force: true });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function port(value, field) {
|
|
52
|
+
const n = Number(value);
|
|
53
|
+
if (!Number.isInteger(n) || n < 1 || n > 65535) throw new Error(field + ' 必须是 1-65535 的整数');
|
|
54
|
+
return n;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function readWatchSettings(env = process.env) {
|
|
58
|
+
const path = watchConfigPath(env);
|
|
59
|
+
const raw = readObject(path);
|
|
60
|
+
let chatPort = DEFAULT_CHAT_PORT;
|
|
61
|
+
if (raw.data.chatPort !== undefined) {
|
|
62
|
+
const n = Number(raw.data.chatPort);
|
|
63
|
+
if (Number.isInteger(n) && n > 0 && n <= 65535) chatPort = n;
|
|
64
|
+
}
|
|
65
|
+
return { path, exists: raw.exists, error: raw.error, chatPort };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function configuredChatPort(env = process.env) {
|
|
69
|
+
return readWatchSettings(env).chatPort;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function writeWatchSettings(patch = {}, env = process.env) {
|
|
73
|
+
const path = watchConfigPath(env);
|
|
74
|
+
const { data } = readObject(path);
|
|
75
|
+
const next = { ...data };
|
|
76
|
+
if (patch.chatPort !== undefined) next.chatPort = port(patch.chatPort, 'chatPort');
|
|
77
|
+
writeObject(path, next);
|
|
78
|
+
return readWatchSettings(env);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function readVideoSettings(env = process.env) {
|
|
82
|
+
const path = videoConfigPath(env);
|
|
83
|
+
const raw = readObject(path);
|
|
84
|
+
const n = Number(raw.data.browserPort);
|
|
85
|
+
return {
|
|
86
|
+
path,
|
|
87
|
+
exists: raw.exists,
|
|
88
|
+
error: raw.error,
|
|
89
|
+
browserPort: Number.isFinite(n) && n > 0 ? n : null,
|
|
90
|
+
launchBrowser: raw.data.launchBrowser === true,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function writeVideoSettings(patch = {}, env = process.env) {
|
|
95
|
+
const path = videoConfigPath(env);
|
|
96
|
+
const { data } = readObject(path);
|
|
97
|
+
const next = { ...data };
|
|
98
|
+
if (patch.browserPort !== undefined) {
|
|
99
|
+
if (patch.browserPort === false || patch.browserPort === 0 || patch.browserPort === null || patch.browserPort === '') {
|
|
100
|
+
next.browserPort = false;
|
|
101
|
+
} else {
|
|
102
|
+
next.browserPort = port(patch.browserPort, 'browserPort');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (patch.launchBrowser !== undefined) {
|
|
106
|
+
if (typeof patch.launchBrowser !== 'boolean') throw new Error('launchBrowser 必须是布尔值');
|
|
107
|
+
next.launchBrowser = patch.launchBrowser;
|
|
108
|
+
}
|
|
109
|
+
writeObject(path, next);
|
|
110
|
+
return readVideoSettings(env);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function readVoiceSettings(env = process.env) {
|
|
114
|
+
const path = voiceConfigPath(env);
|
|
115
|
+
const raw = readObject(path);
|
|
116
|
+
return {
|
|
117
|
+
path,
|
|
118
|
+
exists: raw.exists,
|
|
119
|
+
error: raw.error,
|
|
120
|
+
adapter: typeof raw.data.adapter === 'string' ? raw.data.adapter : '',
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function writeVoiceSettings(patch = {}, env = process.env) {
|
|
125
|
+
const path = voiceConfigPath(env);
|
|
126
|
+
const { data } = readObject(path);
|
|
127
|
+
const next = { ...data };
|
|
128
|
+
if (patch.adapter !== undefined) {
|
|
129
|
+
if (typeof patch.adapter !== 'string') throw new Error('adapter 必须是字符串');
|
|
130
|
+
const adapter = patch.adapter.trim();
|
|
131
|
+
if (adapter.length > MAX_TEXT) throw new Error('adapter 太长');
|
|
132
|
+
if (adapter) next.adapter = adapter;
|
|
133
|
+
else delete next.adapter;
|
|
134
|
+
}
|
|
135
|
+
writeObject(path, next);
|
|
136
|
+
return readVoiceSettings(env);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function configPaths(env = process.env) {
|
|
140
|
+
return {
|
|
141
|
+
home: dshHome(env),
|
|
142
|
+
video: videoConfigPath(env),
|
|
143
|
+
voice: voiceConfigPath(env),
|
|
144
|
+
watch: watchConfigPath(env),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* settings/deps.js — 陪看设置页的环境自检。只读,不安装。
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { execFile } from 'node:child_process';
|
|
6
|
+
import { existsSync } from 'node:fs';
|
|
7
|
+
import { createRequire } from 'node:module';
|
|
8
|
+
import { connect } from 'node:net';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
import { promisify } from 'node:util';
|
|
11
|
+
|
|
12
|
+
import { readVideoSettings, readVoiceSettings, readWatchSettings } from './config.js';
|
|
13
|
+
|
|
14
|
+
const run = promisify(execFile);
|
|
15
|
+
const TIMEOUT = 2500;
|
|
16
|
+
const require = createRequire(import.meta.url);
|
|
17
|
+
|
|
18
|
+
async function version(command, args) {
|
|
19
|
+
try {
|
|
20
|
+
const { stdout, stderr } = await run(command, args, { timeout: TIMEOUT, windowsHide: true, maxBuffer: 64 * 1024 });
|
|
21
|
+
const line = String(stdout || stderr).trim().split(/\r?\n/)[0].slice(0, 120);
|
|
22
|
+
return { ok: true, detail: line || '已安装' };
|
|
23
|
+
} catch (e) {
|
|
24
|
+
return { ok: false, detail: e?.code === 'ENOENT' ? '未找到' : String(e?.message ?? e).slice(0, 120) };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function firstOf(list) {
|
|
29
|
+
const errors = [];
|
|
30
|
+
for (const [command, args] of list) {
|
|
31
|
+
const r = await version(command, args);
|
|
32
|
+
if (r.ok) return r;
|
|
33
|
+
errors.push(r.detail);
|
|
34
|
+
}
|
|
35
|
+
return { ok: false, detail: errors[0] || '未找到' };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function portOpen(port, timeoutMs = 450) {
|
|
39
|
+
return new Promise((resolve) => {
|
|
40
|
+
const socket = connect({ host: '127.0.0.1', port });
|
|
41
|
+
const done = (value) => { socket.removeAllListeners(); socket.destroy(); resolve(value); };
|
|
42
|
+
socket.setTimeout(timeoutMs);
|
|
43
|
+
socket.once('connect', () => done(true));
|
|
44
|
+
socket.once('timeout', () => done(false));
|
|
45
|
+
socket.once('error', () => done(false));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function downloadFor(id, platform = process.platform) {
|
|
50
|
+
const win = platform === 'win32';
|
|
51
|
+
switch (id) {
|
|
52
|
+
case 'ffmpeg':
|
|
53
|
+
case 'ffprobe':
|
|
54
|
+
return {
|
|
55
|
+
downloadUrl: win
|
|
56
|
+
? 'https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.zip'
|
|
57
|
+
: 'https://ffmpeg.org/download.html',
|
|
58
|
+
downloadLabel: win ? '下载 FFmpeg zip' : '下载 FFmpeg',
|
|
59
|
+
};
|
|
60
|
+
case 'python':
|
|
61
|
+
return {
|
|
62
|
+
downloadUrl: win ? 'https://www.python.org/downloads/windows/' : 'https://www.python.org/downloads/',
|
|
63
|
+
downloadLabel: '下载 Python',
|
|
64
|
+
};
|
|
65
|
+
case 'core':
|
|
66
|
+
return {
|
|
67
|
+
downloadUrl: 'https://github.com/SAOS-3624/dsh-video-storyboard',
|
|
68
|
+
downloadLabel: '获取分镜插件',
|
|
69
|
+
};
|
|
70
|
+
case 'extension':
|
|
71
|
+
return {
|
|
72
|
+
downloadUrl: 'https://github.com/SAOS-3624/dsh-watch-together/tree/main/extension',
|
|
73
|
+
downloadLabel: '扩展目录',
|
|
74
|
+
};
|
|
75
|
+
case 'voice':
|
|
76
|
+
return {
|
|
77
|
+
downloadUrl: 'https://github.com/SAOS-3624/dsh-watch-together/tree/main/examples/voice-edge-tts',
|
|
78
|
+
downloadLabel: '语音示例',
|
|
79
|
+
};
|
|
80
|
+
case 'browser':
|
|
81
|
+
return {
|
|
82
|
+
downloadUrl: 'https://learn.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/remote-debugging/',
|
|
83
|
+
downloadLabel: '调试端口说明',
|
|
84
|
+
};
|
|
85
|
+
default:
|
|
86
|
+
return {};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function corePackage() {
|
|
91
|
+
try {
|
|
92
|
+
// package.json is intentionally absent from the core package exports map,
|
|
93
|
+
// so resolve an exported module face instead of the manifest.
|
|
94
|
+
return { ok: true, detail: require.resolve('dsh-video-storyboard/probe') };
|
|
95
|
+
} catch {
|
|
96
|
+
return { ok: false, detail: '未解析到 dsh-video-storyboard(陪看依赖它建段)' };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function extension() {
|
|
101
|
+
const path = fileURLToPath(new URL('../../extension/manifest.json', import.meta.url));
|
|
102
|
+
return {
|
|
103
|
+
ok: existsSync(path),
|
|
104
|
+
detail: existsSync(path) ? '扩展目录在 ' + path : '扩展目录缺失:' + path,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function floatingWindow() {
|
|
109
|
+
const path = fileURLToPath(new URL('../../examples/floating-chat/window.py', import.meta.url));
|
|
110
|
+
return {
|
|
111
|
+
ok: existsSync(path),
|
|
112
|
+
detail: existsSync(path) ? path : '悬浮窗脚本缺失:' + path,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function voice(env) {
|
|
117
|
+
const cfg = readVoiceSettings(env);
|
|
118
|
+
if (!cfg.adapter) return { ok: false, detail: '未配置(可选;只影响念台词)' };
|
|
119
|
+
if (/^[a-zA-Z]:[\\/]|^\\\\|^\.{1,2}[\\/]|^\//.test(cfg.adapter)) {
|
|
120
|
+
return { ok: existsSync(cfg.adapter), detail: existsSync(cfg.adapter) ? cfg.adapter : '文件不存在:' + cfg.adapter };
|
|
121
|
+
}
|
|
122
|
+
return { ok: true, detail: cfg.adapter + '(包名,挂载时才能校验)' };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** @returns {Promise<Array<{id:string,label:string,ok:boolean,detail:string}>>} */
|
|
126
|
+
export async function checkEnvironment(_ctx, env = process.env) {
|
|
127
|
+
const python = await firstOf([['python', ['--version']], ['py', ['--version']]]);
|
|
128
|
+
let ffmpegCmd = 'ffmpeg';
|
|
129
|
+
let ffprobeCmd = 'ffprobe';
|
|
130
|
+
try {
|
|
131
|
+
const core = await import('dsh-video-storyboard/probe');
|
|
132
|
+
ffmpegCmd = core.DEFAULT_FFMPEG || ffmpegCmd;
|
|
133
|
+
ffprobeCmd = core.DEFAULT_FFPROBE || ffprobeCmd;
|
|
134
|
+
} catch { /* 独立测试时可能没有核心包;退回 PATH */ }
|
|
135
|
+
const ffmpeg = await version(ffmpegCmd, ['-version']);
|
|
136
|
+
const ffprobe = await version(ffprobeCmd, ['-version']);
|
|
137
|
+
const core = corePackage();
|
|
138
|
+
const ext = extension();
|
|
139
|
+
const win = floatingWindow();
|
|
140
|
+
const voiceState = voice(env);
|
|
141
|
+
const video = readVideoSettings(env);
|
|
142
|
+
const watch = readWatchSettings(env);
|
|
143
|
+
const browserOpen = video.browserPort ? await portOpen(video.browserPort) : false;
|
|
144
|
+
const chatOpen = await portOpen(watch.chatPort);
|
|
145
|
+
const rows = [
|
|
146
|
+
{ id: 'ffmpeg', label: 'ffmpeg', ...ffmpeg },
|
|
147
|
+
{ id: 'ffprobe', label: 'ffprobe', ...ffprobe },
|
|
148
|
+
{ id: 'python', label: 'Python(悬浮窗)', ...python },
|
|
149
|
+
{ id: 'core', label: 'dsh-video-storyboard', ...core },
|
|
150
|
+
{ id: 'extension', label: '浏览器位置扩展', ...ext },
|
|
151
|
+
{ id: 'floating', label: 'Python 悬浮窗脚本', ...win },
|
|
152
|
+
{
|
|
153
|
+
id: 'browser', label: '浏览器调试端口 :' + (video.browserPort || '未配置'),
|
|
154
|
+
ok: browserOpen, detail: browserOpen ? '可连接' : '未连接(扩展/SMTC 仍可能提供位置)',
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
id: 'chat', label: '聊天服务 :' + watch.chatPort,
|
|
158
|
+
ok: true, detail: chatOpen ? '已有服务在监听' : '端口空闲;首次陪看会启动',
|
|
159
|
+
},
|
|
160
|
+
{ id: 'voice', label: '语音适配器', ...voiceState },
|
|
161
|
+
];
|
|
162
|
+
return rows.map((row) => ({ ...row, ...downloadFor(row.id) }));
|
|
163
|
+
}
|