MCPcopy Create free account
hub / github.com/Roy3838/Observer / MediaUploadMessage

Function MediaUploadMessage

app/src/components/MediaUploadMessage.tsx:12–316  ·  view source on GitHub ↗
({ requestText, onResponse })

Source from the content-addressed store, hash-verified

10}
11
12const MediaUploadMessage: React.FC<MediaUploadMessageProps> = ({ requestText, onResponse }) => {
13 const [showPreview, setShowPreview] = useState(false);
14 const [stream, setStream] = useState<MediaStream | null>(null);
15 const [captureMode, setCaptureMode] = useState<'camera' | 'screen' | null>(null);
16 const videoRef = useRef<HTMLVideoElement>(null);
17 const fileInputRef = useRef<HTMLInputElement>(null);
18
19 const logger = createLoggerDecorator('MediaUploadMessage');
20
21 useEffect(() => {
22 logger.info('Component mounted');
23 return () => {
24 logger.info('Component unmounting');
25 if (stream) {
26 logger.info('Cleaning up stream on unmount');
27 stream.getTracks().forEach(track => track.stop());
28 }
29 };
30 }, []);
31
32 useEffect(() => {
33 if (stream && videoRef.current) {
34 logger.info('Setting video source', { hasStream: !!stream, hasVideoRef: !!videoRef.current });
35 videoRef.current.srcObject = stream;
36
37 videoRef.current.onloadedmetadata = () => {
38 logger.info('Video metadata loaded, attempting to play');
39 videoRef.current?.play().catch(error => {
40 logger.error('Failed to play video', error);
41 });
42 };
43
44 videoRef.current.onerror = (error) => {
45 logger.error('Video element error', error);
46 };
47 }
48 }, [stream]);
49
50 const handleUploadImage = () => {
51 logger.info('Upload image button clicked');
52 fileInputRef.current?.click();
53 };
54
55 const handleFileSelect = (event: React.ChangeEvent<HTMLInputElement>) => {
56 const file = event.target.files?.[0];
57 logger.info('File selected', { fileName: file?.name, fileType: file?.type, fileSize: file?.size });
58
59 if (file && file.type.startsWith('image/')) {
60 logger.info('Valid image file, reading as data URL');
61 const reader = new FileReader();
62 reader.onload = (e) => {
63 const result = e.target?.result as string;
64 logger.info('File reader loaded', { resultLength: result.length, resultPreview: result.substring(0, 100) });
65 // Extract base64 data (remove data:image/...;base64, prefix)
66 const base64Data = result.split(',')[1];
67 logger.info('Extracted base64 data', { base64Length: base64Data.length });
68 onResponse({ type: 'image', data: base64Data });
69 };

Callers

nothing calls this directly

Calls 4

createLoggerDecoratorFunction · 0.90
infoMethod · 0.80
errorMethod · 0.80
stopMethod · 0.45

Tested by

no test coverage detected