A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(recorder): a Douyin recording the host ends on its own keeps its video
esengine4a310db81209
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e35ac8a94..f3104acbf 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,6 +14,10 @@ published separately; it ships inside the editor.## [Unreleased]+### Fixed++- A Douyin recording the host ends on its own keeps its video, and an interruption is not counted as recorded time.+## [0.72.0] - 2026-09-24### Addeddiff --git a/sdk/src/platform/minigame/api.ts b/sdk/src/platform/minigame/api.tsindex 1689cd040..8321d96c6 100644--- a/sdk/src/platform/minigame/api.ts+++ b/sdk/src/platform/minigame/api.ts@@ -193,6 +193,9 @@ export interface MiniGameTtRecorder {onResume(cb: () => void): void;onStop(cb: (res: { videoPath: string }) => void): void;onError(cb: (res: { errMsg?: string }) => void): void;+ /** Base library 1.6.1+. */+ onInterruptionBegin?(cb: () => void): void;+ onInterruptionEnd?(cb: () => void): void;}/** The share card a host shows for an active or passive share. */diff --git a/sdk/src/platform/minigame/recorder.ts b/sdk/src/platform/minigame/recorder.tsindex e1b7a6cb9..4a5b6e95e 100644--- a/sdk/src/platform/minigame/recorder.ts+++ b/sdk/src/platform/minigame/recorder.ts@@ -65,12 +65,14 @@ class HostGate {});}- fire(event: string, payload?: unknown): void {+ /** False when no call was waiting for @p event — the host acted on its own. */+ fire(event: string, payload?: unknown): boolean {const w = this.waiting_;- if (!w || w.event !== event) return;+ if (!w || w.event !== event) return false;clearTimeout(w.timer);this.waiting_ = null;w.resolve(payload);+ return true;}fail(error: Error): void {@@ -249,11 +251,35 @@ export function createTtRecorder(g: MiniGameGlobal, now?: () => number): Platforif (!rec) return null;const session = new Session(now);const gate = new HostGate((e) => session.stray(e));+ // A stop nobody asked for still carries the only copy of the video path;+ // the next stop() answers with it instead of stopping a stopped recorder.+ let hostStopped: { videoPath?: string } | null = null;+ // Kept apart from the game's own pause, which an interruption's end must not undo.+ let pausedByGame = false;+ let interrupted = false;rec.onStart(() => gate.fire('start'));rec.onPause(() => gate.fire('pause'));rec.onResume(() => gate.fire('resume'));- rec.onStop((res) => gate.fire('stop', res));+ rec.onStop((res) => {+ if (!gate.fire('stop', res) && session.active) hostStopped = res ?? {};+ });rec.onError((res) => gate.fail(toError(res)));+ rec.onInterruptionBegin?.(() => {+ if (!session.active || interrupted) return;+ interrupted = true;+ session.clock.pause();+ });+ rec.onInterruptionEnd?.(() => {+ if (!interrupted) return;+ interrupted = false;+ if (!pausedByGame) session.clock.resume();+ });+ const hostStop = async (): Promise<{ videoPath?: string } | undefined> => {+ const done = hostStopped;+ hostStopped = null;+ if (done) return done;+ return await gate.wait('stop', () => rec.stop()) as { videoPath?: string } | undefined;+ };// `start` must be longer than 3s; the host counts whole seconds.const limits = { minSeconds: 4, maxSeconds: 300 };// `clipVideo` cuts a recording once; a second share reuses the first cut.@@ -282,20 +308,25 @@ export function createTtRecorder(g: MiniGameGlobal, now?: () => number): Platforget canShare() { return typeof g.shareAppMessage === 'function'; },async start(maxSeconds, onFailure) {session.begin(onFailure);+ hostStopped = null;+ pausedByGame = false;+ interrupted = false;await gate.wait('start', () => rec.start({ duration: clampSeconds(maxSeconds, limits) }));session.started();clipsThisRecording = 0;},async pause() {await gate.wait('pause', () => rec.pause());+ pausedByGame = true;session.clock.pause();},async resume() {await gate.wait('resume', () => rec.resume());- session.clock.resume();+ pausedByGame = false;+ if (!interrupted) session.clock.resume();},async stop() {- const res = await gate.wait('stop', () => rec.stop()) as { videoPath?: string } | undefined;+ const res = await hostStop();const durationMs = session.clock.elapsedMs();session.end();const recording = { durationMs, path: res?.videoPath, highlights: session.clock.highlights(durationMs) };@@ -304,7 +335,7 @@ export function createTtRecorder(g: MiniGameGlobal, now?: () => number): Platfor},// Douyin has no abort: stopping and dropping the file is the same outcome.async abort() {- await gate.wait('stop', () => rec.stop());+ await hostStop();session.end();},highlight(before, after) {diff --git a/sdk/tests/minigame-recorder.test.ts b/sdk/tests/minigame-recorder.test.tsindex c453707ae..b55b40db2 100644--- a/sdk/tests/minigame-recorder.test.ts+++ b/sdk/tests/minigame-recorder.test.ts@@ -45,12 +45,12 @@ function fakeWx(options: { frame?: boolean; share?: boolean; answer?: boolean }function fakeTt() {const on: Record<string, Listener> = {};const clock = { t: 0 };- const calls = { start: [] as unknown[], clip: [] as unknown[], cut: [] as unknown[], share: [] as unknown[] };+ const calls = { start: [] as unknown[], clip: [] as unknown[], cut: [] as unknown[], share: [] as unknown[], stop: 0 };const rec = {start(o: unknown) { calls.start.push(o); queueMicrotask(() => on.start?.()); },pause() { queueMicrotask(() => on.pause?.()); },resume() { queueMicrotask(() => on.resume?.()); },- stop() { queueMicrotask(() => on.stop?.({ videoPath: 'ttfile://tmp/run.mp4' })); },+ stop() { calls.stop++; queueMicrotask(() => on.stop?.({ videoPath: 'ttfile://tmp/run.mp4' })); },recordClip(o: unknown) { calls.clip.push(o); },clipVideo(o: { path: string; success?: (r: { videoPath: string }) => void }) {calls.cut.push(o);@@ -61,6 +61,8 @@ function fakeTt() {onResume: (cb: Listener) => { on.resume = cb; },onStop: (cb: Listener) => { on.stop = cb; },onError: (cb: Listener) => { on.error = cb; },+ onInterruptionBegin: (cb: Listener) => { on.interruptionBegin = cb; },+ onInterruptionEnd: (cb: Listener) => { on.interruptionEnd = cb; },};const g = {getGameRecorderManager: () => rec,@@ -238,6 +240,32 @@ describe('Douyin', () => {expect(host.calls.share[0]).toMatchObject({ extra: { videoPath: 'ttfile://tmp/run.mp4' } });});+ it('keeps the video of a stop the host made on its own, and stops with it', async () => {+ const host = fakeTt();+ const r = createTtRecorder(host.g)!;+ await r.start(60, () => {});+ host.on.stop({ videoPath: 'ttfile://tmp/interrupted.mp4' });+ expect((await r.stop()).path).toBe('ttfile://tmp/interrupted.mp4');+ expect(host.calls.stop).toBe(0);+ });++ it('does not count an interruption as recorded time, nor end the game\'s own pause', async () => {+ const host = fakeTt();+ const r = createTtRecorder(host.g, () => host.clock.t)!;+ await r.start(60, () => {});+ host.clock.t = 1000;+ host.on.interruptionBegin();+ host.clock.t = 5000;+ host.on.interruptionEnd();+ host.clock.t = 6000;+ await r.pause();+ host.on.interruptionBegin();+ host.clock.t = 9000;+ host.on.interruptionEnd();+ host.clock.t = 12000;+ expect((await r.stop()).durationMs).toBe(2000);+ });+it('carries the host refusal to the share', async () => {const host = fakeTt();(host.g as unknown as { shareAppMessage: unknown }).shareAppMessage =diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 069414fda..28c82cb44 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -1054,4 +1054,6 @@ export const NOTED = {{ note: "The agent drawer's History button shows it is open with a grey press again, not the accent colour 0.71 gave it." },'fix(bench): a locked screen is a question this machine cannot take':{ internal: 'a release criterion\'s own measuring conditions; the engine is unchanged' },+ 'fix(recorder): a Douyin recording the host ends on its own keeps its video':+ { note: 'A Douyin recording the host ends on its own keeps its video, and an interruption is not counted as recorded time.' },};