исрпвь ошибку client.js:178 Uncaught (in promise) TypeError: Cannot read properties of…
- User
исрпвь ошибку client.js:178 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'appendChild') at createPeerConnection (client.js:178:27) at connectToPeer (client.js:227:11) at Socket. (client.js:123:5) at Emitter.emit (index.js:136:20) at Socket.emitEvent (socket.js:553:20) at Socket.onevent (socket.js:540:18) at Socket.onpacket (socket.js:508:22) at Emitter.emit (index.js:136:20) at manager.js:217:18 вот код // public/client.js const socket = io();
// Элементы интерфейса const localVideo = document.getElementById('localVideo'); const remoteVideosContainer = document.getElementById('remoteVideosContainer'); // Убедитесь, что такой элемент существует в HTML const chat = document.getElementById('chat'); const messageInput = document.getElementById('message-input'); const sendButton = document.getElementById('send-button'); const toggleAudioButton = document.getElementById('toggleAudio'); const toggleVideoButton = document.getElementById('toggleVideo'); const shareScreenButton = document.getElementById('shareScreen');
// Получение медиапотоков let localStream; let screenStream; const peers = {};
// Конфигурация ICE серверов с дополнительными STUN и TURN серверами const config = { iceServers: [ // Дополнительные STUN-серверы от Google { urls: 'stun:stun.l.google.com:19302' }, { urls: 'stun:stun1.l.google.com:19302' }, { urls: 'stun:stun2.l.google.com:19302' }, { urls: 'stun:stun3.l.google.com:19302' }, { urls: 'stun:stun4.l.google.com:19302' },
code// Пример добавления TURN-сервера { urls: 'turn:YOUR_TURN_SERVER_URL', // Замените на ваш TURN-сервер username: 'YOUR_TURN_USERNAME', // Замените на имя пользователя TURN credential: 'YOUR_TURN_CREDENTIAL' // Замените на пароль TURN } ]};
// Функция для проверки доступных устройств async function getAvailableMedia() { try { const devices = await navigator.mediaDevices.enumerateDevices(); const hasAudio = devices.some(device => device.kind === 'audioinput'); const hasVideo = devices.some(device => device.kind === 'videoinput');
codelet constraints = {}; if (hasVideo) constraints.video = true; if (hasAudio) constraints.audio = true; if (!hasVideo && !hasAudio) { throw new Error('Нет доступных устройств ввода.'); } return constraints; } catch (err) { console.error('Ошибка при проверке устройств:', err); throw err; } - Assistant