12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- import type {ReplayFrame} from 'sentry/utils/replays/types';
- export function getPrevReplayFrame({
- frames,
- targetOffsetMs,
- allowExact = false,
- }: {
- frames: ReplayFrame[];
- targetOffsetMs: number;
- allowExact?: boolean;
- }) {
- return frames.reduce<ReplayFrame | undefined>((found, item) => {
- if (
- item.offsetMs > targetOffsetMs ||
- (!allowExact && item.offsetMs === targetOffsetMs)
- ) {
- return found;
- }
- if (
- (allowExact && item.offsetMs === targetOffsetMs) ||
- !found ||
- item.offsetMs > found.offsetMs
- ) {
- return item;
- }
- return found;
- }, undefined);
- }
- export function getNextReplayFrame({
- frames,
- targetOffsetMs,
- allowExact = false,
- }: {
- frames: ReplayFrame[];
- targetOffsetMs: number;
- allowExact?: boolean;
- }) {
- return frames.reduce<ReplayFrame | undefined>((found, item) => {
- if (
- item.offsetMs < targetOffsetMs ||
- (!allowExact && item.offsetMs === targetOffsetMs)
- ) {
- return found;
- }
- if (
- (allowExact && item.offsetMs === targetOffsetMs) ||
- !found ||
- item.offsetMs < found.offsetMs
- ) {
- return item;
- }
- return found;
- }, undefined);
- }
|