main funcions fixes

This commit is contained in:
2025-09-29 22:06:11 +09:00
parent 40e016e128
commit c8c3274527
7995 changed files with 1517998 additions and 1057 deletions

View File

@@ -800,4 +800,61 @@ function showAlert(type, message) {
document.body.removeChild(alert);
}
}, 5000);
}
}
// === ОПЕРАТОР: Веб-камера и WebRTC ===
function showOperatorWebcamButton() {
const btn = document.getElementById('startOperatorWebcam');
if (btn) btn.style.display = '';
}
function hideOperatorWebcamButton() {
const btn = document.getElementById('startOperatorWebcam');
if (btn) btn.style.display = 'none';
}
function startOperatorWebcam() {
navigator.mediaDevices.getUserMedia({ video: true, audio: false })
.then(stream => {
operatorWebcamStream = stream;
const video = document.getElementById('operatorWebcam');
if (video) {
video.srcObject = stream;
video.style.display = '';
}
startOperatorWebRTC(stream);
})
.catch(err => {
showAlert('danger', 'Ошибка доступа к веб-камере: ' + err);
});
}
function startOperatorWebRTC(stream) {
operatorWebcamPeer = new RTCPeerConnection(rtcConfig);
stream.getTracks().forEach(track => operatorWebcamPeer.addTrack(track, stream));
operatorWebcamPeer.onicecandidate = e => {
if (e.candidate) {
socket.emit('webrtc:ice-candidate', { candidate: e.candidate });
}
};
operatorWebcamPeer.createOffer().then(offer => {
return operatorWebcamPeer.setLocalDescription(offer);
}).then(() => {
socket.emit('webrtc:offer', { offer: operatorWebcamPeer.localDescription });
});
}
socket.on('webrtc:answer', data => {
if (operatorWebcamPeer) {
operatorWebcamPeer.setRemoteDescription(new RTCSessionDescription(data.answer));
}
});
socket.on('webrtc:ice-candidate', data => {
if (operatorWebcamPeer && data.candidate) {
operatorWebcamPeer.addIceCandidate(new RTCIceCandidate(data.candidate));
}
});
// Показывать кнопку веб-камеры при принятии сессии
socket.on('camera:response', data => {
if (data.accepted) {
showOperatorWebcamButton();
} else {
hideOperatorWebcamButton();
}
});