@flow-player/test-streams 0.6.0 → 0.6.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.
Files changed (40) hide show
  1. package/{src/cli/extend-vod.ts → dist/cli/extend-vod.js} +39 -61
  2. package/dist/cli/generate.js +473 -0
  3. package/dist/cli/serve.js +644 -0
  4. package/dist/config.d.ts +29 -0
  5. package/dist/fixtures/catalog.d.ts +37 -0
  6. package/dist/fixtures/catalog.js +63 -0
  7. package/dist/fixtures/codec.d.ts +10 -0
  8. package/dist/fixtures/format.d.ts +13 -0
  9. package/dist/fixtures/generate.d.ts +11 -0
  10. package/dist/fixtures/generate.js +361 -0
  11. package/dist/fixtures/matrix.d.ts +18 -0
  12. package/dist/index.d.ts +8 -0
  13. package/dist/index.js +894 -0
  14. package/dist/server/live.d.ts +14 -0
  15. package/dist/server/routes.d.ts +18 -0
  16. package/dist/server/server.d.ts +18 -0
  17. package/dist/server/server.js +534 -0
  18. package/dist/server/static.d.ts +13 -0
  19. package/dist/vite-plugin.d.ts +12 -0
  20. package/dist/vite-plugin.js +58 -0
  21. package/package.json +24 -11
  22. package/src/cli/generate.ts +0 -138
  23. package/src/cli/serve.ts +0 -112
  24. package/src/config.ts +0 -34
  25. package/src/fixtures/catalog.ts +0 -99
  26. package/src/fixtures/codec.ts +0 -43
  27. package/src/fixtures/format.ts +0 -118
  28. package/src/fixtures/generate.ts +0 -209
  29. package/src/fixtures/matrix.ts +0 -94
  30. package/src/index.ts +0 -41
  31. package/src/server/live.ts +0 -220
  32. package/src/server/routes.ts +0 -141
  33. package/src/server/server.ts +0 -193
  34. package/src/server/static.ts +0 -83
  35. package/src/visual/analyze.ts +0 -234
  36. package/src/visual/dhash.ts +0 -76
  37. package/src/visual/index.ts +0 -18
  38. package/src/visual/report.ts +0 -80
  39. package/src/vite-plugin.d.ts +0 -10
  40. package/src/vite-plugin.ts +0 -76
@@ -1,76 +0,0 @@
1
- // 本地测试流服务的 dev 自准备插件(仅 serve 生效):vite dev 启动时探测
2
- // streams server 健康状态,未就绪则后台拉起 `src/cli/serve.ts`(detached,
3
- // 日志写 /tmp/test-streams.log)。demo 等本地 consumer 无需再在 package.json
4
- // 里编排 streams 启动命令。
5
- import { spawn } from "node:child_process";
6
- import { openSync } from "node:fs";
7
- import https from "node:https";
8
- import { dirname, resolve } from "node:path";
9
- import { fileURLToPath } from "node:url";
10
- import type { Plugin } from "vite";
11
-
12
- export interface TestStreamsVitePluginOptions {
13
- /** TLS 证书路径,传给 streams serve(默认 /tmp/flow-player-local.pem)。 */
14
- cert?: string;
15
- /** TLS 私钥路径,传给 streams serve(默认 /tmp/flow-player-local-key.pem)。 */
16
- key?: string;
17
- /** streams server 健康检查 URL(默认 https://127.0.0.1:4177/streams/health)。 */
18
- healthUrl?: string;
19
- /** streams server 日志文件(默认 /tmp/test-streams.log)。 */
20
- logPath?: string;
21
- }
22
-
23
- const DEFAULT_CERT = "/tmp/flow-player-local.pem";
24
- const DEFAULT_KEY = "/tmp/flow-player-local-key.pem";
25
- const DEFAULT_HEALTH_URL = "https://127.0.0.1:4177/streams/health";
26
- const DEFAULT_LOG_PATH = "/tmp/test-streams.log";
27
-
28
- function streamsHealthy(healthUrl: string): Promise<boolean> {
29
- return new Promise((resolveHealthy) => {
30
- const req = https.get(
31
- healthUrl,
32
- { rejectUnauthorized: false, timeout: 2000 },
33
- (res) => {
34
- res.resume();
35
- resolveHealthy(
36
- res.statusCode !== undefined && res.statusCode >= 200 && res.statusCode < 300,
37
- );
38
- },
39
- );
40
- req.on("timeout", () => {
41
- req.destroy();
42
- resolveHealthy(false);
43
- });
44
- req.on("error", () => resolveHealthy(false));
45
- });
46
- }
47
-
48
- export function testStreamsVitePlugin(options: TestStreamsVitePluginOptions = {}): Plugin {
49
- const {
50
- cert = DEFAULT_CERT,
51
- key = DEFAULT_KEY,
52
- healthUrl = DEFAULT_HEALTH_URL,
53
- logPath = DEFAULT_LOG_PATH,
54
- } = options;
55
- const serveScript = resolve(dirname(fileURLToPath(import.meta.url)), "cli/serve.ts");
56
-
57
- return {
58
- name: "flow-player-test-streams",
59
- apply: "serve",
60
- configureServer() {
61
- void (async () => {
62
- if (await streamsHealthy(healthUrl)) {
63
- return;
64
- }
65
- const logFd = openSync(logPath, "w");
66
- const child = spawn(process.execPath, [serveScript, "--cert", cert, "--key", key], {
67
- detached: true,
68
- windowsHide: true,
69
- stdio: ["ignore", logFd, logFd],
70
- });
71
- child.unref();
72
- console.log(`[test-streams] 未就绪,已在后台启动,日志: ${logPath}`);
73
- })();
74
- },
75
- };
76
- }