2017-08-23 45 views
0

我想記錄每個新的會話/用戶添加到RTCMultiConnection。
我使用下面的演示網址應用 https://rtcmulticonnection.herokuapp.com/demos/Audio+Video+TextChat+FileSharing.htmlstartRecording使用RecordRTC與RTCMultiConnection不工作

我現在已經增加了以下CDN參考代碼。 https://cdn.webrtc-experiment.com/RecordRTC.js

這是我正在使用的代碼,但connection.streams[event.streamid].startRecording();不起作用。

// ..................RTCMultiConnection Code............. // ...................................................... var connection = new RTCMultiConnection(); var btnStopRec = document.getElementById("btnStopRecording"); connection.socketURL = 'https://rtcmulticonnection.herokuapp.com:443/'; connection.enableFileSharing = true; connection.session = { audio: true, video: true, data: true, }; connection.sdpConstraints.mandatory = { OfferToReceiveAudio: true, OfferToReceiveVideo: true, }; connection.onstream = function (event) { document.body.appendChild(event.mediaElement); console.log("stream recording starts") connection.streams[event.streamid].startRecording(); console.log("stream recording started") }

回答

1

我包含在一個片段所有可能的情況,下面。請只拿你需要的代碼:

// global object that contains multiple recorders 
var recorders = {}; 

// auto start recorder as soon as stream starts/begins 
connection.onstream = function(event) { 
    document.body.appendChild(event.mediaElement); 

    recorders[event.streamid] = RecordRTC(event.stream, { 
     type: 'video' 
    }); 

    recorders[event.streamid].startRecording(); 
}; 

// auto stop recorder as soon as stream stops/ends 
connection.onstreamended = function(event) { 
    if (recorders[event.streamid]) { 
     recorders[event.streamid].stopRecording(function() { 
      var blob = recorders[event.streamid].getBlob(); 
      var url = URL.createObjectURL(blob); 
      window.open(url); 

      delete recorders[streamid]; // clear 
     }); 
    } 

    if (event.mediaElement.parentNode) { 
     event.mediaElement.parentNode.removeChild(event.mediaElement); 
    } 
}; 

// stop single recorder 
document.getElementById('manually-stop-single-recording').onclick = function() { 
    var streamid = prompt('Enter streamid'); 
    recorders[streamid].stopRecording(function() { 
     var blob = recorders[streamid].getBlob(); 
     var url = URL.createObjectURL(blob); 
     window.open(url); 

     delete recorders[streamid]; // clear 
    }); 
}; 

// stop all recorders 
document.getElementById('manually-stop-all-recordings').onclick = function() { 
    Object.keys(recorders).forEach(function(streamid) { 
     recorders[streamid].stopRecording(function() { 
      var blob = recorders[streamid].getBlob(); 
      var url = URL.createObjectURL(blob); 
      window.open(url); 

      delete recorders[streamid]; // clear 
     }); 
    }); 
}; 

// record outside onstream event 
// i.e. start recording anytime manually 
document.getElementById('record-stream-outside-the-onstream-event').onclick = function() { 
    var streamid = prompt('Enter streamid'); 
    var stream = connection.streamEvents[streamid].stream; 

    recorders[streamid] = RecordRTC(stream, { 
     type: 'video' 
    }); 

    recorders[streamid].startRecording(); 
}; 
+0

謝謝兄弟... tusee大幹草...... :) –