Merge remote-tracking branch 'origin/main' into feat/apps-in-toss
This commit is contained in:
commit
597017bd37
1 file changed
+8
-19
@@ -50,7 +50,7 @@ function embed(id: string) {
|
||||
return `${YT_ORIGIN}/embed/${id}?${q}`
|
||||
}
|
||||
|
||||
type Func = 'playVideo' | 'pauseVideo' | 'seekTo' | 'mute' | 'unMute'
|
||||
type Func = 'playVideo' | 'seekTo' | 'mute' | 'unMute'
|
||||
|
||||
/** 이미 띄운 플레이어에 명령 (IFrame API 메시지) */
|
||||
function command(frame: HTMLIFrameElement | null | undefined, func: Func, args: unknown[] = []) {
|
||||
@@ -181,8 +181,6 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta
|
||||
const frames = useRef(new Map<number, HTMLIFrameElement>())
|
||||
const atRef = useRef(start)
|
||||
const soundRef = useRef(false)
|
||||
// 누르기로 멈춘 상태. 다른 영상으로 넘어가면 다시 재생 중으로
|
||||
const paused = useRef(false)
|
||||
|
||||
// 처음 한 번: 시작 영상으로 맞추고, 뒤 페이지 스크롤을 잠근다
|
||||
const startRef = useRef(start)
|
||||
@@ -217,7 +215,7 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta
|
||||
return () => io.disconnect()
|
||||
}, [])
|
||||
|
||||
// 미리 띄운 영상이 재생되기 시작하면(첫 장면을 받음) 보이는 영상이 아닐 때 멈추고 처음으로
|
||||
// 플레이어가 재생을 시작하면(첫 장면을 받음) 보이게 한다. 앞뒤 영상은 멈추지 않는다: 멈췄다 다시 틀면 유튜브가 재생·멈춤 버튼을 영상 위에 띄운다
|
||||
useEffect(() => {
|
||||
const onMessage = (e: MessageEvent) => {
|
||||
if (e.origin !== YT_ORIGIN || typeof e.data !== 'string') return
|
||||
@@ -231,9 +229,6 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta
|
||||
for (const [i, f] of frames.current) {
|
||||
if (f.contentWindow !== e.source) continue
|
||||
setReady((r) => (r.has(i) ? r : new Set(r).add(i)))
|
||||
if (i === atRef.current) continue
|
||||
command(f, 'pauseVideo')
|
||||
command(f, 'seekTo', [0, true])
|
||||
}
|
||||
}
|
||||
window.addEventListener('message', onMessage)
|
||||
@@ -244,27 +239,21 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta
|
||||
useEffect(() => {
|
||||
if (atRef.current !== at) moved(items[at])
|
||||
atRef.current = at
|
||||
paused.current = false
|
||||
// 앞뒤 영상은 소리 없이 계속 돌고 있으니, 넘어온 영상만 처음부터 다시 틀고 소리를 맞춘다 (멈춤 명령은 쓰지 않는다)
|
||||
for (const [i, f] of frames.current) {
|
||||
if (i === at) {
|
||||
command(f, 'seekTo', [0, true])
|
||||
command(f, soundRef.current ? 'unMute' : 'mute')
|
||||
command(f, 'playVideo')
|
||||
} else {
|
||||
command(f, 'pauseVideo')
|
||||
command(f, 'mute')
|
||||
}
|
||||
} else command(f, 'mute')
|
||||
}
|
||||
}, [at, items])
|
||||
|
||||
// 마우스로도 끌어 넘긴다: 영상 위는 유튜브 iframe 이 마우스를 가져가서, 그 위에 투명한 판을 깔고 끈 만큼 목록을 옮긴다.
|
||||
// 손가락은 브라우저 스크롤에 맡기고, 끌지 않고 누르기만 하면 재생·일시정지
|
||||
// 손가락은 브라우저 스크롤에 맡기고, 끌지 않고 누르기만 하면 릴스처럼 소리 켜기·끄기 (멈추면 유튜브 버튼이 떠서)
|
||||
const drag = useRef<{ y: number; top: number; moved: boolean } | null>(null)
|
||||
const lastPointer = useRef('')
|
||||
const [dragging, setDragging] = useState(false)
|
||||
const togglePause = () => {
|
||||
paused.current = !paused.current
|
||||
command(frames.current.get(atRef.current), paused.current ? 'pauseVideo' : 'playVideo')
|
||||
}
|
||||
const onPointerDown = (e: ReactPointerEvent<HTMLDivElement>) => {
|
||||
lastPointer.current = e.pointerType
|
||||
const box = list.current
|
||||
@@ -287,7 +276,7 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta
|
||||
drag.current = null
|
||||
setDragging(false)
|
||||
if (!d || !box) return
|
||||
if (!d.moved) return togglePause()
|
||||
if (!d.moved) return toggleSound()
|
||||
// 30px 만 끌어도 다음·이전 영상으로, 그보다 덜 끌면 제자리로
|
||||
const h = box.clientHeight
|
||||
const dy = e.clientY - d.y
|
||||
@@ -374,7 +363,7 @@ function ShortsViewer({ items, start, onClose, onAt }: { items: ShortItem[]; sta
|
||||
drag.current = null
|
||||
setDragging(false)
|
||||
}}
|
||||
onClick={() => lastPointer.current !== 'mouse' && togglePause()}
|
||||
onClick={() => lastPointer.current !== 'mouse' && toggleSound()}
|
||||
className={cx('absolute inset-0 touch-pan-y select-none', dragging ? 'cursor-grabbing' : 'cursor-grab')}
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user