|
|
|
|
@ -1,3 +1,4 @@ |
|
|
|
|
/* eslint-disable @typescript-eslint/no-explicit-any */ |
|
|
|
|
import { |
|
|
|
|
RefObject, |
|
|
|
|
useEffect, |
|
|
|
|
@ -8,6 +9,8 @@ import styled from 'styled-components/macro' |
|
|
|
|
import { Icon } from 'features/Icon' |
|
|
|
|
import { useAuthStore } from 'features/AuthStore' |
|
|
|
|
|
|
|
|
|
import { isIOS } from 'config' |
|
|
|
|
|
|
|
|
|
const PipWrapper = styled.div` |
|
|
|
|
cursor: pointer; |
|
|
|
|
margin-left: 25px; |
|
|
|
|
@ -21,17 +24,39 @@ type PipProps = { |
|
|
|
|
|
|
|
|
|
export const PiP = ({ videoRef }: PipProps) => { |
|
|
|
|
const { user } = useAuthStore() |
|
|
|
|
|
|
|
|
|
const togglePip = async () => { |
|
|
|
|
const isInPIP = () => Boolean(document.pictureInPictureElement) |
|
|
|
|
|
|
|
|
|
const closePIP = async () => { |
|
|
|
|
if (!isInPIP()) return |
|
|
|
|
|
|
|
|
|
if (isIOS) { |
|
|
|
|
await (videoRef.current as any)?.webkitSetPresentationMode('inline') |
|
|
|
|
} |
|
|
|
|
await document.exitPictureInPicture() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const openPIP = async () => { |
|
|
|
|
if (isInPIP()) return |
|
|
|
|
|
|
|
|
|
if (isIOS) { |
|
|
|
|
await (videoRef.current as any)?.webkitSetPresentationMode('picture-in-picture') |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
await videoRef.current?.requestPictureInPicture() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
if ( |
|
|
|
|
document.pictureInPictureEnabled && videoRef.current !== document.pictureInPictureElement |
|
|
|
|
) { |
|
|
|
|
await videoRef.current?.requestPictureInPicture() |
|
|
|
|
await openPIP() |
|
|
|
|
} else { |
|
|
|
|
await document.exitPictureInPicture() |
|
|
|
|
await closePIP() |
|
|
|
|
} |
|
|
|
|
} catch (err) { |
|
|
|
|
await document.exitPictureInPicture() |
|
|
|
|
await closePIP() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|