webrtc для каждого видео-чата, но для отправки видео другому нужна только одна сторона
Я прочитал много примеров о webrtc, но я не могу понять, как переписать видео p2p между A и B, но просто нужно, чтобы A отправлял потоковое видео на B, используя p2p-соединение. Как это сделать? Я попытался отключить локальное видео в B {video: false}, но произошла ошибка, не работает.
Мой сценарий
<!DOCTYPE html>
<html>
<head>
<script src="https://simplewebrtc.com/latest-v2.js"></script>
<script type="text/javascript">
var webrtc = new SimpleWebRTC({
// the id/element dom element that will hold "our" video
localVideoEl: 'localVideo',
// the id/element dom element that will hold remote videos
remoteVideosEl: 'remotesVideos',
// immediately ask for camera access
autoRequestMedia: true,
//https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
//https://github.com/andyet/signalmaster/blob/master/README.md
media: {
audio: false,
video: {
//width: 720,
width: {ideal: 640},
// height: 1280,
height: {ideal: 480},
frameRate: {ideal: 15}
}
},
receiveMedia: {
offerToReceiveAudio: 0,
offerToReceiveVideo: 1
}
});
// we have to wait until it's ready
webrtc.on('readyToCall', function () {
// you can name it anything
webrtc.joinRoom('zika ghe vl');
});
</script>
</head>
<body>
<div id="remotesVideos"></div>
</body>
</html>
1 ответ
Решение
На стороне отправителя включить видео, отключить аудио. На ресивере отключите оба. попробуйте ниже код
<!DOCTYPE html>
<html>
<head>
<script src="https://simplewebrtc.com/latest-v2.js"></script>
<button onclick="start(false)">Receive video</button>
<button onclick="start(true)"">Send video</button>
<script type="text/javascript">
function start (e) {
/**
have separate settings to get the trigger form UI
*/
var videoSettings = {
//width: 720,
width: {ideal: 640},
// height: 1280,
height: {ideal: 480},
frameRate: {ideal: 15}
}
if(!e) videoSettings = e;
new SimpleWebRTC({
// the id/element dom element that will hold "our" video
localVideoEl: 'localVideo',
// the id/element dom element that will hold remote videos
remoteVideosEl: 'remotesVideos',
// immediately ask for camera access
autoRequestMedia: true,
//https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
//https://github.com/andyet/signalmaster/blob/master/README.md
media: {
audio: false,
video: videoSettings
},
receiveMedia: {
offerToReceiveAudio: 0,
offerToReceiveVideo: 1
}
}).on('readyToCall', function () {
// you can name it anything
this.joinRoom('zika ghe vl');
});
}
</script>
</head>
<body>
<div id="remotesVideos"></div>
</body>
</html>