main funcions fixes
This commit is contained in:
@@ -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();
|
||||
}
|
||||
});
|
||||
@@ -400,13 +400,14 @@
|
||||
<label>Operator ID:</label>
|
||||
<input type="text" id="operator-id" value="demo-operator-001" placeholder="Введите ID оператора">
|
||||
</div>
|
||||
|
||||
<button class="btn btn-success" id="operator-connect" onclick="connectOperator()">
|
||||
Подключиться как оператор
|
||||
</button>
|
||||
<button class="btn btn-danger" id="operator-disconnect" onclick="disconnectOperator()" disabled>
|
||||
Отключиться
|
||||
</button>
|
||||
<button class="btn" id="startOperatorWebcam" style="display:none">Включить веб-камеру оператора</button>
|
||||
<video id="operatorWebcam" autoplay playsinline style="width:320px;display:none"></video>
|
||||
|
||||
<div class="grid">
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user