openreplay/frontend/app/components/Spots/SpotPlayer/components/SpotTimeline.tsx
Delirium b17c3ab8d7
Spots UI (#2385)
* feat ui: login flow for spot extension

* spot list, store and service created

* some fixing for header

* start work on single spot

* spot player start

* header for player, comments, icons, etc

* split stuff into compoennts, create player state manager

* player controls, activity panel etc etc

* comments, empty page, rename and stuff

* interval buttons etc

* access modal

* pubkey support

* fix tooltip

* limit 10 -> 9

* hls lib instead of videojs

* some warnings

* fix date display for exp

* change public links

* display more client data

* fix cleaning, init comment

* map network to replay player network ev

* stream support, console panel, close panels on X

* fixing streaming, destroy on leave

* fix autoplay

* show notification on spot login

* fix spot login

* backup player added, fix audio issue

* show thumbnail when no video, add spot roles

* add poster thumbnail

* some fixes to video check

* fix events jump

* fix play btn

* try catch over pubkey

* icons

* spot login pinging

* move spot login flow to login comp, use separate spot login path for unique jwt

* invalidate spot jwt on logout

* add visual data on page load event

* typo fix

* issue to copy change

* share spot url f
2024-07-31 09:56:41 +02:00

66 lines
1.9 KiB
TypeScript

import { observer } from 'mobx-react-lite';
import React from 'react';
import CustomDragLayer from 'App/components/Session_/Player/Controls/components/CustomDragLayer';
import stl from 'App/components/Session_/Player/Controls/timeline.module.css';
import { debounce } from 'App/utils';
import cn from 'classnames'
import spotPlayerStore from '../spotPlayerStore';
import SpotTimeTracker from './SpotTimeTracker';
function SpotTimeline() {
const progressRef = React.useRef<HTMLDivElement>(null);
const wasPlaying = React.useRef(false);
const [maxWidth, setMaxWidth] = React.useState(0);
const debounceSetTime = React.useMemo(
() => debounce(spotPlayerStore.setTime, 100),
[]
);
React.useEffect(() => {
if (progressRef.current) {
setMaxWidth(progressRef.current.clientWidth);
}
}, []);
const getOffset = (offsX: number) => {
return offsX / (progressRef.current?.clientWidth || 1);
};
const onDrag = (offset: { x: number }) => {
if (spotPlayerStore.isPlaying) {
wasPlaying.current = true;
spotPlayerStore.setIsPlaying(false);
}
const offs = getOffset(offset.x);
const time = spotPlayerStore.duration * offs;
debounceSetTime(time);
};
const onDrop = () => {
if (wasPlaying.current) {
spotPlayerStore.setIsPlaying(true);
wasPlaying.current = false;
}
};
const jump = (e: React.MouseEvent<HTMLDivElement>) => {
const offs = getOffset(e.nativeEvent.offsetX);
const time = spotPlayerStore.duration * offs;
spotPlayerStore.setTime(time);
};
return (
<div
ref={progressRef}
role={'button'}
className={cn(stl.progress, '-mb-1')}
onClick={jump}
>
<SpotTimeTracker onDrop={onDrop} />
<CustomDragLayer minX={0} onDrag={onDrag} maxX={maxWidth} />
<div className={stl.timeline} />
</div>
);
}
export default observer(SpotTimeline);