我需要构建一个Web应用程序,使用WebRTC获取网络摄像头视频流和麦克风音频流,并立即将其翻译到服务器以供进一步广播到多个客户端。该应用程序必须实时进行全双工通信,就像是一种实时视频聊天应用。它将是某种教育应用程序。
那么问题来了:现在是否可能?我应该使用哪些技术?应该在后端使用WebRTC、WebSocket和Node.js吗?还是可以使用PHP代替Node?我可以使用Socket.io吗?还有其他方法可以实现这一点吗?或者可以使用Flash吗?
我需要构建一个Web应用程序,使用WebRTC获取网络摄像头视频流和麦克风音频流,并立即将其翻译到服务器以供进一步广播到多个客户端。该应用程序必须实时进行全双工通信,就像是一种实时视频聊天应用。它将是某种教育应用程序。
那么问题来了:现在是否可能?我应该使用哪些技术?应该在后端使用WebRTC、WebSocket和Node.js吗?还是可以使用PHP代替Node?我可以使用Socket.io吗?还有其他方法可以实现这一点吗?或者可以使用Flash吗?
<video autoplay></video>
<script language="javascript" type="text/javascript">
function onVideoFail(e) {
console.log('webcam fail!', e);
};
function hasGetUserMedia() {
// Note: Opera is unprefixed.
return !!(navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia || navigator.msGetUserMedia);
}
if (hasGetUserMedia()) {
// Good to go!
} else {
alert('getUserMedia() is not supported in your browser');
}
window.URL = window.URL || window.webkitURL;
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia;
var video = document.querySelector('video');
var streamRecorder;
var webcamstream;
if (navigator.getUserMedia) {
navigator.getUserMedia({audio: true, video: true}, function(stream) {
video.src = window.URL.createObjectURL(stream);
webcamstream = stream;
// streamrecorder = webcamstream.record();
}, onVideoFail);
} else {
alert ('failed');
}
function startRecording() {
streamRecorder = webcamstream.record();
setTimeout(stopRecording, 10000);
}
function stopRecording() {
streamRecorder.getRecordedData(postVideoToServer);
}
function postVideoToServer(videoblob) {
var data = {};
data.video = videoblob;
data.metadata = 'test metadata';
data.action = "upload_video";
jQuery.post("http://www.kongraju.in/uploadvideo.php", data, onUploadSuccess);
}
function onUploadSuccess() {
alert ('video uploaded');
}
</script>
<div id="webcamcontrols">
<button class="recordbutton" onclick="startRecording();">RECORD</button>
</div>