Handle fragmented replay events in recording and playback
This commit is contained in:
1 parent
4987e0ca01
commit
15038b09d9
6 files changed
+345
-34
No files matched your search
@@ -1,7 +1,9 @@
|
||||
'use client';
|
||||
import { Column } from '@umami/react-zen';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { Empty } from '@/components/common/Empty';
|
||||
import { useMobile } from '@/components/hooks';
|
||||
import { hasReplayFullSnapshot } from '@/lib/replay';
|
||||
import 'rrweb-player/dist/style.css';
|
||||
|
||||
export function ReplayPlayer({ events }: { events: any[] }) {
|
||||
@@ -9,12 +11,14 @@ export function ReplayPlayer({ events }: { events: any[] }) {
|
||||
const playerRef = useRef<any>(null);
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
const { isMobile, isPhone } = useMobile();
|
||||
const canReplay = hasReplayFullSnapshot(events);
|
||||
const showUnavailable = !events?.length || !canReplay;
|
||||
|
||||
const playerWidth = isPhone ? 360 : isMobile ? 640 : 1024;
|
||||
const playerHeight = isPhone ? 202 : isMobile ? 360 : 576;
|
||||
|
||||
useEffect(() => {
|
||||
if (!containerRef.current || !events?.length) return;
|
||||
if (!containerRef.current || !events?.length || !canReplay) return;
|
||||
|
||||
import('rrweb-player').then(mod => {
|
||||
const RRWebPlayer = mod.default;
|
||||
@@ -46,7 +50,7 @@ export function ReplayPlayer({ events }: { events: any[] }) {
|
||||
playerRef.current = null;
|
||||
}
|
||||
};
|
||||
}, [events, playerWidth, playerHeight]);
|
||||
}, [canReplay, events, playerWidth, playerHeight]);
|
||||
|
||||
return (
|
||||
<Column alignItems="center">
|
||||
@@ -54,14 +58,16 @@ export function ReplayPlayer({ events }: { events: any[] }) {
|
||||
ref={containerRef}
|
||||
style={{
|
||||
width: playerWidth,
|
||||
minHeight: loaded ? undefined : playerHeight,
|
||||
minHeight: loaded && canReplay ? undefined : playerHeight,
|
||||
maxWidth: '100%',
|
||||
overflow: 'hidden',
|
||||
borderRadius: '8px',
|
||||
border: '1px solid var(--base300)',
|
||||
background: 'var(--base75)',
|
||||
}}
|
||||
/>
|
||||
>
|
||||
{showUnavailable && <Empty message="Replay unavailable." />}
|
||||
</div>
|
||||
</Column>
|
||||
);
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import { getClientInfo, hasBlockedIp } from '@/lib/detect';
|
||||
import { parseToken } from '@/lib/jwt';
|
||||
import { fetchAccount, fetchTeam } from '@/lib/load';
|
||||
import { getRecorderConfig } from '@/lib/recorder';
|
||||
import { getReplayEventCount } from '@/lib/replay';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { badRequest, forbidden, json, payloadTooLarge, serverError } from '@/lib/response';
|
||||
import { getWebsite } from '@/queries/prisma';
|
||||
@@ -197,7 +198,7 @@ export async function POST(request: Request) {
|
||||
visitId,
|
||||
chunkIndex,
|
||||
events,
|
||||
eventCount: events.length,
|
||||
eventCount: getReplayEventCount(events),
|
||||
startedAt,
|
||||
endedAt,
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { restoreReplayEventFragments } from '@/lib/replay';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
import { canViewAuthenticatedWebsite } from '@/permissions';
|
||||
@@ -91,7 +92,9 @@ export async function GET(
|
||||
}
|
||||
|
||||
const chunks = await getReplayChunks(websiteId, replayId, { endAt, endChunkIndex });
|
||||
const allEvents = mergeReplayEvents(chunks, { until, endChunkIndex, endEventIndex });
|
||||
const allEvents = restoreReplayEventFragments(
|
||||
mergeReplayEvents(chunks, { until, endChunkIndex, endEventIndex }),
|
||||
);
|
||||
const sessionId = chunks.length > 0 ? chunks[0].sessionId : null;
|
||||
const startedAt = chunks.length > 0 ? chunks[0].startedAt : null;
|
||||
const endedAt = chunks.length > 0 ? chunks[chunks.length - 1].endedAt : null;
|
||||
|
||||
Reference in new issue
Block a user