如何解决在单个文件中记录多个RTCMulticonnection流
我正在使用RTCMulticonnection与WebRTC一起进行实时流传输,用户可以共享他们的摄像机供稿并同时进行屏幕显示。它工作正常,但是当我使用RecordRTC录制流时,无论何时用户从摄像机切换到屏幕或从屏幕切换到摄像机,它都会开始单独的录制。我如何将其记录在单个文件中。下面是我的代码:
var connection = new RTCMultiConnection();
var video = document.querySelector('#video')
// this line is VERY_important
connection.socketURL = 'https://rtcmulticonnection.herokuapp.com:443/';
// if you want audio+video conferencing
connection.session = {
audio: true,video: {
mandatory:{
width: 1280,height: 720
}
},oneway: true
};
connection.mediaConstraints = {
video: true,audio: true,screen: false
};
connection.open('coach-stream'+roomid)
connection.sdpConstraints.mandatory = {
OfferToReceiveAudio: false,OfferToReceiveVideo: false
};
$('#share').on('click',function(e){
e.preventDefault();
var cameraOptions = {
screen: true
};
connection.captureUserMedia(function(camera) {
var screen = camera.getVideoTracks()[0]
connection.attachStreams.forEach(function(stream){
stream.getVideoTracks().forEach(tracks => {
tracks = screen
})
})
var streamEvent = {
type: 'local',stream: camera,streamid: camera.id,mediaElement: video
};
//connection.dontCaptureUserMedia = true;
screen.onended = function(){
var cameraOptions2 = {
video: true
};
connection.captureUserMedia(function(camera) {
var screen = camera.getVideoTracks()[0]
connection.attachStreams.forEach(function(stream){
stream.getVideoTracks().forEach(tracks => {
tracks = screen
})
})
var streamEvent = {
type: 'local',mediaElement: video
};
//connection.dontCaptureUserMedia = true;
},cameraOptions2);
}
},cameraOptions);
});
var blob
connection.onstream=function(event){
$('#count').html(connection.getAllParticipants().length+' <i class="fa fa-eye"></i>')
if( event.type === 'local' ){
video.addEventListener("pause",function(){
connection.streamEvents.selectFirst({local: true}).stream.mute();
});
video.addEventListener("play",function(){
connection.streamEvents.selectFirst({local: true}).stream.unmute();
});
}
sid = event.streamid
video.srcObject = event.stream
video.play();
var screen = connection.streamEvents.selectFirst({local: true,isScreen: true}).stream;
var recorder = RecordRTC([event.stream],{type:'video',mimeType: 'video/webm;codecs=vp8'})
recorder.startRecording();
$('#stp').on('click',function(e){
e.preventDefault();
connection.getAllParticipants().forEach(function(pid) {
connection.disconnectWith(pid);
});
connection.attachStreams.forEach(function(localStream) {
localStream.getTracks().forEach(function(track) {
if (track.readyState == 'live') {
track.stop();
}
})
});
connection.removeStream('video')
connection.removeStream('audio')
video.srcObject = null
请有人帮助我。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。