Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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();
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement