sozsoft-platform/ui/src/views/admin/videoroom/ScreenSharePanel.tsx

100 lines
3 KiB
TypeScript
Raw Normal View History

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(() => {
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')}
2026-08-14 11:32:31 +00:00
</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 ? (
<Button
type="button"
variant="plain"
shape="none"
2026-05-08 05:34:29 +00:00
onClick={onStopShare}
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} />
<span>{translate('::App.VideoRoom.StopSharing')}</span>
</Button>
2026-05-08 05:34:29 +00:00
) : (
<Button
type="button"
variant="plain"
shape="none"
2026-05-08 05:34:29 +00:00
onClick={onStartShare}
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} />
<span>{translate('::App.VideoRoom.ShareScreen')}</span>
</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">
{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" />
<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
)
}