impl media interactions recording

close #159
close #72
listen to HTMLMediaElement's play/pause events, and replay them
by programmatically play and pause the target element.
This commit is contained in:
Yanzhen Yu
2026-04-01 12:00:00 +08:00
parent d0c31bb4cf
commit 5bfc2c704a
5 changed files with 89 additions and 4 deletions

View File

@@ -20,6 +20,7 @@ import {
ReplayerEvents,
Handler,
Emitter,
MediaInteractions,
} from '../types';
import { mirror, polyfill } from '../utils';
import getInjectStyleRules from './styles/inject-style';
@@ -587,6 +588,26 @@ export class Replayer {
}
break;
}
case IncrementalSource.MediaInteraction: {
const target = mirror.getNode(d.id);
if (!target) {
return this.debugNodeNotFound(d, d.id);
}
const mediaEl = (target as Node) as HTMLMediaElement;
if (d.type === MediaInteractions.Pause) {
mediaEl.pause();
}
if (d.type === MediaInteractions.Play) {
if (mediaEl.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA) {
mediaEl.play();
} else {
mediaEl.addEventListener('canplay', () => {
mediaEl.play();
});
}
}
break;
}
default:
}
}