在单个文件中记录多个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 (将#修改为@)