import { useState } from 'react'; function TextShare({ textHistory, setTextHistory, dataChannels, useFallback, socket, code }) { const [textInput, setTextInput] = useState(''); const handleSend = () => { if (!textInput.trim()) return; console.log('handleSend:', { dataChannels, useFallback, code }); if (!useFallback && Object.keys(dataChannels).length > 0) { Object.keys(dataChannels).forEach((peerId) => { if (dataChannels[peerId].readyState === 'open') { dataChannels[peerId].send(JSON.stringify({ type: 'text', text: textInput })); console.log(`Sent text to peer ${peerId}`); } }); } else if (useFallback && socket && code) { socket.emit('text', { code, text: textInput }); console.log(`Sending text via socket for room ${code}: ${textInput}`); } setTextHistory((prev) => [...prev, textInput]); // Update sender's textHistory setTextInput(''); }; const handleKeySend = (e) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); // Prevent adding a new line handleSend(); // Trigger send action } }; const selectText = (x) => { const element = document.getElementById(`msg-${x}`); if (element && window.getSelection) { const selection = window.getSelection(); selection.removeAllRanges(); const range = document.createRange(); range.selectNodeContents(element); selection.addRange(range); //document.execCommand('copy') // deprecated //navigator.clipboard.writeText(element.textContent); // new way } else { console.warn(`Element msg-${x} not found or selection API unavailable`); } }; return (

Share Text