2026-07-06 09:44:26 +00:00
|
|
|
import { useEffect, useRef } from 'react'
|
|
|
|
|
import { FaDesktop, FaStop, FaPlay } from 'react-icons/fa'
|
|
|
|
|
import { Button } from '@/components/ui'
|
2026-08-14 11:32:31 +00:00
|
|
|
import { useLocalization } from '@/utils/hooks/useLocalization'
|
2026-05-08 05:34:29 +00:00
|
|
|
|
|
|
|
|
interface ScreenSharePanelProps {
|
2026-07-06 09:44:26 +00:00
|
|
|
isSharing: boolean
|
|
|
|
|
onStartShare: () => void
|
|
|
|
|
onStopShare: () => void
|
|
|
|
|
sharedScreen?: MediaStream
|
|
|
|
|
sharerName?: string
|
2026-05-08 05:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
2026-07-06 09:44:26 +00:00
|
|
|
export const ScreenSharePanel = ({
|
2026-05-08 05:34:29 +00:00
|
|
|
isSharing,
|
|
|
|
|
onStartShare,
|
|
|
|
|
onStopShare,
|
|
|
|
|
sharedScreen,
|
|
|
|
|
sharerName,
|
2026-07-06 09:44:26 +00:00
|
|
|
}: ScreenSharePanelProps) => {
|
2026-08-14 11:32:31 +00:00
|
|
|
const { translate } = useLocalization()
|
2026-07-06 09:44:26 +00:00
|
|
|
const videoRef = useRef<HTMLVideoElement>(null)
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-08-11 12:44:56 +00:00
|
|
|
const videoEl = videoRef.current
|
|
|
|
|
if (!videoEl) return
|
|
|
|
|
|
|
|
|
|
videoEl.srcObject = sharedScreen ?? null
|
|
|
|
|
if (sharedScreen) {
|
|
|
|
|
void videoEl.play().catch(() => undefined)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
videoEl.srcObject = null
|
2026-07-06 09:44:26 +00:00
|
|
|
}
|
|
|
|
|
}, [sharedScreen])
|
|
|
|
|
|
2026-05-08 05:34:29 +00:00
|
|
|
return (
|
|
|
|
|
<div className="bg-white rounded-lg shadow-md p-4 mb-4">
|
|
|
|
|
<div className="flex items-center justify-between mb-4">
|
|
|
|
|
<div className="flex items-center space-x-2">
|
|
|
|
|
<FaDesktop className="text-blue-600" size={20} />
|
2026-08-14 11:32:31 +00:00
|
|
|
<h3 className="font-semibold text-gray-800">
|
|
|
|
|
{translate('::App.Videoroom.ScreenShare')}
|
|
|
|
|
</h3>
|
2026-05-08 05:34:29 +00:00
|
|
|
</div>
|
2026-07-06 09:44:26 +00:00
|
|
|
|
2026-05-08 05:34:29 +00:00
|
|
|
{isSharing ? (
|
2026-06-25 22:55:44 +00:00
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
variant="plain"
|
|
|
|
|
shape="none"
|
2026-05-08 05:34:29 +00:00
|
|
|
onClick={onStopShare}
|
2026-06-25 22:55:44 +00:00
|
|
|
className="!inline-flex !h-auto items-center gap-2 rounded-lg !bg-red-600 !px-3 py-2 text-white transition-colors hover:!bg-red-700"
|
2026-05-08 05:34:29 +00:00
|
|
|
>
|
|
|
|
|
<FaStop size={16} />
|
2026-08-14 11:32:31 +00:00
|
|
|
<span>{translate('::App.Videoroom.StopSharing')}</span>
|
2026-06-25 22:55:44 +00:00
|
|
|
</Button>
|
2026-05-08 05:34:29 +00:00
|
|
|
) : (
|
2026-06-25 22:55:44 +00:00
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
variant="plain"
|
|
|
|
|
shape="none"
|
2026-05-08 05:34:29 +00:00
|
|
|
onClick={onStartShare}
|
2026-06-25 22:55:44 +00:00
|
|
|
className="!inline-flex !h-auto items-center gap-2 rounded-lg !bg-blue-600 !px-3 py-2 text-white transition-colors hover:!bg-blue-700"
|
2026-05-08 05:34:29 +00:00
|
|
|
>
|
|
|
|
|
<FaPlay size={16} />
|
2026-08-14 11:32:31 +00:00
|
|
|
<span>{translate('::App.Videoroom.ShareScreen')}</span>
|
2026-06-25 22:55:44 +00:00
|
|
|
</Button>
|
2026-05-08 05:34:29 +00:00
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{sharedScreen && (
|
|
|
|
|
<div className="relative bg-gray-900 rounded-lg overflow-hidden aspect-video">
|
|
|
|
|
<video
|
2026-07-06 09:44:26 +00:00
|
|
|
ref={videoRef}
|
2026-05-08 05:34:29 +00:00
|
|
|
autoPlay
|
|
|
|
|
playsInline
|
|
|
|
|
muted
|
|
|
|
|
className="w-full h-full object-contain"
|
|
|
|
|
/>
|
2026-07-06 09:44:26 +00:00
|
|
|
|
2026-05-08 05:34:29 +00:00
|
|
|
{sharerName && (
|
|
|
|
|
<div className="absolute bottom-2 left-2 bg-black bg-opacity-50 text-white px-2 py-1 rounded text-sm">
|
2026-08-14 11:32:31 +00:00
|
|
|
{translate('::App.Videoroom.IsSharingScreen', { name: sharerName })}
|
2026-05-08 05:34:29 +00:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{isSharing && !sharedScreen && (
|
|
|
|
|
<div className="bg-gray-100 rounded-lg p-8 text-center">
|
|
|
|
|
<FaDesktop size={48} className="mx-auto text-gray-400 mb-4" />
|
2026-08-14 11:32:31 +00:00
|
|
|
<p className="text-gray-600">{translate('::App.Videoroom.StartingScreenShare')}</p>
|
2026-05-08 05:34:29 +00:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2026-07-06 09:44:26 +00:00
|
|
|
)
|
|
|
|
|
}
|