优化:公屏预加载叫号音频素材
需求:页面打开后缓存音频片段,叫号时避免临时下载造成延迟。 实现:页面挂载时预加载全部数字与提示语 WAV,后端继续返回叫号数据/文本,前端按文本映射片段播放。 验证:前端 66 项测试通过,生产构建通过。
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { announcementAudioQueue } from "./useAudioAnnouncements";
|
||||
import { renderHook } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { announcementAudioQueue, audioPreloadSources, useAudioAnnouncements } from "./useAudioAnnouncements";
|
||||
|
||||
afterEach(() => {
|
||||
document.head.querySelectorAll("link[data-queue-voice-preload]").forEach((link) => link.remove());
|
||||
});
|
||||
|
||||
describe("announcementAudioQueue", () => {
|
||||
it("忽略项目名并把单号码播报素材重复三遍", () => {
|
||||
@@ -34,4 +39,15 @@ describe("announcementAudioQueue", () => {
|
||||
"/audio/queue-voice/entrance.wav",
|
||||
]);
|
||||
});
|
||||
|
||||
it("打开页面时预加载全部声音素材", () => {
|
||||
const { unmount } = renderHook(() => useAudioAnnouncements());
|
||||
const links = Array.from(document.head.querySelectorAll<HTMLLinkElement>("link[data-queue-voice-preload]"));
|
||||
|
||||
expect(links.map((link) => link.getAttribute("href"))).toEqual(audioPreloadSources);
|
||||
expect(links.every((link) => link.rel === "preload" && link.getAttribute("as") === "audio")).toBe(true);
|
||||
|
||||
unmount();
|
||||
expect(document.head.querySelector("link[data-queue-voice-preload]")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user