impl #81 custom event

This is the record side impl of custom event, according to the
issue, we may also add first-class support for the custom event
tag like display color labels in the replayer-ui.
This commit is contained in:
Yanzhen Yu
2026-04-01 12:00:00 +08:00
parent 469dbd5dee
commit d92a946926
5 changed files with 139 additions and 5 deletions

View File

@@ -17,6 +17,23 @@ function wrapEvent(e: event): eventWithTime {
};
}
let wrappedEmit!: (e: eventWithTime, isCheckout?: boolean) => void;
export function addCustomEvent<T>(tag: string, payload: T) {
if (!wrappedEmit) {
throw new Error('please add custom event after start recording');
}
wrappedEmit(
wrapEvent({
type: EventType.Custom,
data: {
tag,
payload,
},
}),
);
}
function record(options: recordOptions = {}): listenerHandler | undefined {
const {
emit,
@@ -34,7 +51,7 @@ function record(options: recordOptions = {}): listenerHandler | undefined {
let lastFullSnapshotEvent: eventWithTime;
let incrementalSnapshotCount = 0;
const wrappedEmit = (e: eventWithTime, isCheckout?: boolean) => {
wrappedEmit = (e: eventWithTime, isCheckout?: boolean) => {
emit(e, isCheckout);
if (e.type === EventType.FullSnapshot) {
lastFullSnapshotEvent = e;