Skip to content

Commit

Permalink
Merged muaz-khan#45 "Fix undefined problems with browser defined obje…
Browse files Browse the repository at this point in the history
…cts"
  • Loading branch information
muaz-khan committed Oct 5, 2015
1 parent 4935379 commit 2beeceb
Show file tree
Hide file tree
Showing 11 changed files with 317 additions and 84 deletions.
21 changes: 15 additions & 6 deletions AudioVideo-on-Firefox.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ <h2 class="header">
<a href="https://www.webrtc-experiment.com/RecordRTC/">RecordRTC Main Demo</a> (Records screen/video/audio in all browsers!)
</li>

<li>
<a href="https://www.webrtc-experiment.com/RecordRTC/PHP/">RecordRTC-to-PHP</a>
(audio/video recording and uploading to server)
</li>

<li>
<a href="https://www.webrtc-experiment.com/RecordRTC/Canvas-Recording/">Canvas Recording!</a> (Web-Page Recording)
</li>
Expand Down Expand Up @@ -185,11 +190,6 @@ <h2 class="header">
(used ffmpeg to merge wav/webm in single WebM container)
</li>

<li>
<a href="https://github.com/muaz-khan/RecordRTC/tree/master/RecordRTC-to-PHP">RecordRTC-to-PHP</a>
(audio/video recording and uploading to server)
</li>

<li>
<a href="https://github.com/muaz-khan/RecordRTC/tree/master/RecordRTC-to-ASPNETMVC">RecordRTC-to-ASP.NET MVC</a>
(audio/video recording and uploading to server)
Expand Down Expand Up @@ -231,6 +231,12 @@ <h2 class="header">Using RecordRTC...</h2>
</ol>
</section>

<section class="experiment own-widgets">
<h2 class="header" id="updates" style="color: red; padding-bottom: .1em;"><a href="https://github.com/muaz-khan/RecordRTC/issues" target="_blank">RecordRTC Issues</a>
</h2>
<div id="github-issues"></div>
</section>

<section class="experiment">
<h2 class="header" id="feedback">Feedback</h2>
<div>
Expand All @@ -247,7 +253,7 @@ <h2 class="header" id="feedback">Feedback</h2>
</section>

<section class="experiment own-widgets latest-commits">
<h2 class="header" id="updates" style="color: red; padding-bottom: .1em;"><a href="https://github.com/muaz-khan/WebRTC-Experiment/commits/master" target="_blank">Latest Updates</a>
<h2 class="header" id="updates" style="color: red; padding-bottom: .1em;"><a href="https://github.com/muaz-khan/RecordRTC/commits/master" target="_blank">Latest Updates</a>
</h2>
<div id="github-commits"></div>
</section>
Expand All @@ -263,6 +269,9 @@ <h2 class="header" id="updates" style="color: red; padding-bottom: .1em;"><a hre
</footer>

<!-- commits.js is useless for you! -->
<script>
window.useThisGithubPath = 'muaz-khan/RecordRTC';
</script>
<script src="//cdn.webrtc-experiment.com/commits.js" async>
</script>
</body>
Expand Down
3 changes: 2 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ module.exports = function(grunt) {
concat: {
options: {
stripBanners: true,
separator: '\n'
separator: '\n',
banner: '// Last time updated at <%= grunt.template.today("dddd, mmmm dS, yyyy, h:MM:ss TT") %> \n\n'
},
dist: {
src: [
Expand Down
19 changes: 14 additions & 5 deletions Record-Mp3-or-Wav.html
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ <h2 class="header">
<a href="https://www.webrtc-experiment.com/RecordRTC/">RecordRTC Main Demo</a> (Records screen/video/audio in all browsers!)
</li>

<li>
<a href="https://www.webrtc-experiment.com/RecordRTC/PHP/">RecordRTC-to-PHP</a>
(audio/video recording and uploading to server)
</li>

<li>
<a href="https://www.webrtc-experiment.com/RecordRTC/Canvas-Recording/">Canvas Recording!</a> (Web-Page Recording)
</li>
Expand Down Expand Up @@ -288,11 +293,6 @@ <h2 class="header">
(used ffmpeg to merge wav/webm in single WebM container)
</li>

<li>
<a href="https://github.com/muaz-khan/RecordRTC/tree/master/RecordRTC-to-PHP">RecordRTC-to-PHP</a>
(audio/video recording and uploading to server)
</li>

<li>
<a href="https://github.com/muaz-khan/RecordRTC/tree/master/RecordRTC-to-ASPNETMVC">RecordRTC-to-ASP.NET MVC</a>
(audio/video recording and uploading to server)
Expand All @@ -307,6 +307,12 @@ <h2 class="header">
</ol>
</section>

<section class="experiment own-widgets">
<h2 class="header" id="updates" style="color: red; padding-bottom: .1em;"><a href="https://github.com/muaz-khan/RecordRTC/issues" target="_blank">RecordRTC Issues</a>
</h2>
<div id="github-issues"></div>
</section>

<section class="experiment">
<h2 class="header" id="feedback">Feedback</h2>
<div>
Expand Down Expand Up @@ -339,6 +345,9 @@ <h2 class="header" id="updates" style="color: red; padding-bottom: .1em;"><a hre
</footer>

<!-- commits.js is useless for you! -->
<script>
window.useThisGithubPath = 'muaz-khan/RecordRTC';
</script>
<script src="https://cdn.webrtc-experiment.com/commits.js" async></script>
</body>

Expand Down
19 changes: 14 additions & 5 deletions RecordRTC-to-PHP/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,11 @@ <h2 class="header">
<a href="https://www.webrtc-experiment.com/RecordRTC/">RecordRTC Main Demo</a> (Records screen/video/audio in all browsers!)
</li>

<li>
<a href="https://www.webrtc-experiment.com/RecordRTC/PHP/">RecordRTC-to-PHP</a>
(audio/video recording and uploading to server)
</li>

<li>
<a href="https://www.webrtc-experiment.com/RecordRTC/Canvas-Recording/">Canvas Recording!</a> (Web-Page Recording)
</li>
Expand Down Expand Up @@ -847,11 +852,6 @@ <h2 class="header">
(used ffmpeg to merge wav/webm in single WebM container)
</li>

<li>
<a href="https://github.com/muaz-khan/RecordRTC/tree/master/RecordRTC-to-PHP">RecordRTC-to-PHP</a>
(audio/video recording and uploading to server)
</li>

<li>
<a href="https://github.com/muaz-khan/RecordRTC/tree/master/RecordRTC-to-ASPNETMVC">RecordRTC-to-ASP.NET MVC</a>
(audio/video recording and uploading to server)
Expand All @@ -866,6 +866,12 @@ <h2 class="header">
</ol>
</section>

<section class="experiment own-widgets">
<h2 class="header" id="updates" style="color: red; padding-bottom: .1em;"><a href="https://github.com/muaz-khan/RecordRTC/issues" target="_blank">RecordRTC Issues</a>
</h2>
<div id="github-issues"></div>
</section>

<section class="experiment">
<h2 class="header" id="feedback">Feedback</h2>
<div>
Expand Down Expand Up @@ -1052,6 +1058,9 @@ <h2 class="header" id="updates" style="color: red; padding-bottom: .1em;"><a hre
</footer>

<!-- commits.js is useless for you! -->
<script>
window.useThisGithubPath = 'muaz-khan/RecordRTC';
</script>
<script src="https://cdn.webrtc-experiment.com/commits.js" async></script>
</body>

Expand Down
84 changes: 59 additions & 25 deletions RecordRTC.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Last time updated at October 04, 2015
// Last time updated at Monday, October 5th, 2015, 9:30:19 PM

// links:
// Open-Sourced: https://github.com/muaz-khan/RecordRTC
Expand Down Expand Up @@ -739,8 +739,7 @@ function RecordRTCConfiguration(mediaStream, config) {
}

if (!config.bitsPerSecond) {
// or use lowest: 128000
config.bitsPerSecond = 256 * 1024 * 8; // 256 kbps
config.bitsPerSecond = 128000;
}
}

Expand Down Expand Up @@ -1136,46 +1135,56 @@ MRecordRTC.writeToDisk = RecordRTC.writeToDisk;
// Cross-Browser-Declarations.js

// animation-frame used in WebM recording

/*jshint -W079 */
var requestAnimationFrame = window.requestAnimationFrame;
if (typeof requestAnimationFrame === 'undefined') {
if (typeof webkitRequestAnimationFrame !== 'undefined') {
/*global requestAnimationFrame:true */
var requestAnimationFrame = webkitRequestAnimationFrame;
requestAnimationFrame = webkitRequestAnimationFrame;
}

if (typeof mozRequestAnimationFrame !== 'undefined') {
/*global requestAnimationFrame:true */
var requestAnimationFrame = mozRequestAnimationFrame;
requestAnimationFrame = mozRequestAnimationFrame;
}
}

/*jshint -W079 */
var cancelAnimationFrame = window.cancelAnimationFrame;
if (typeof cancelAnimationFrame === 'undefined') {
if (typeof webkitCancelAnimationFrame !== 'undefined') {
/*global cancelAnimationFrame:true */
var cancelAnimationFrame = webkitCancelAnimationFrame;
cancelAnimationFrame = webkitCancelAnimationFrame;
}

if (typeof mozCancelAnimationFrame !== 'undefined') {
/*global cancelAnimationFrame:true */
var cancelAnimationFrame = mozCancelAnimationFrame;
cancelAnimationFrame = mozCancelAnimationFrame;
}
}

// WebAudio API representer
var AudioContext = window.AudioContext;

if (typeof AudioContext === 'undefined') {
if (typeof webkitAudioContext !== 'undefined') {
/*global AudioContext:true */
var AudioContext = webkitAudioContext;
AudioContext = webkitAudioContext;
}

if (typeof mozAudioContext !== 'undefined') {
/*global AudioContext:true */
var AudioContext = mozAudioContext;
AudioContext = mozAudioContext;
}
}

/*jshint -W079 */
var URL = window.URL;

if (typeof URL === 'undefined' && typeof webkitURL !== 'undefined') {
/*global URL:true */
var URL = webkitURL;
URL = webkitURL;
}

var isEdge = navigator.userAgent.indexOf('Edge') !== -1 && (!!navigator.msSaveBlob || !!navigator.msSaveOrOpenBlob);
Expand All @@ -1197,8 +1206,23 @@ if (typeof navigator !== 'undefined') {
};
}

if (typeof webkitMediaStream !== 'undefined') {
var MediaStream = webkitMediaStream;
var MediaStream = window.MediaStream;

if (typeof MediaStream === 'undefined' && typeof webkitMediaStream !== 'undefined') {
MediaStream = webkitMediaStream;
}

/*global MediaStream:true */
if (!('stop' in MediaStream.prototype)) {
MediaStream.prototype.stop = function() {
this.getAudioTracks().forEach(function(track) {
track.stop();
});

this.getVideoTracks().forEach(function(track) {
track.stop();
});
};
}

if (typeof location !== 'undefined') {
Expand Down Expand Up @@ -1351,23 +1375,23 @@ function MediaStreamRecorder(mediaStream, config) {
var self = this;

config = config || {
audioBitsPerSecond: 128000,
videoBitsPerSecond: 2500000,
bitsPerSecond: 128000,
mimeType: 'video/webm'
};

// if user chosen only audio option; and he tried to pass MediaStream with
// both audio and video tracks;
// using a dirty workaround to generate audio-only stream so that we can get audio/ogg output.
if (!isChrome && config.mimeType && config.mimeType !== 'video/webm' && mediaStream.getVideoTracks && mediaStream.getVideoTracks().length) {
var context = new AudioContext();
var mediaStreamSource = context.createMediaStreamSource(mediaStream);
if (!isChrome && config.type && config.type === 'audio') {
if (mediaStream.getVideoTracks && mediaStream.getVideoTracks().length) {
var context = new AudioContext();
var mediaStreamSource = context.createMediaStreamSource(mediaStream);

var destination = context.createMediaStreamDestination();
mediaStreamSource.connect(destination);
var destination = context.createMediaStreamDestination();
mediaStreamSource.connect(destination);

mediaStream = destination.stream;
mediaStream = destination.stream;
}

if (!config.mimeType || config.mimeType.indexOf('audio') === -1) {
config.mimeType = 'audio/ogg';
Expand Down Expand Up @@ -1420,7 +1444,7 @@ function MediaStreamRecorder(mediaStream, config) {

// Dispatching OnDataAvailable Handler
mediaRecorder.ondataavailable = function(e) {
if (e.data && !e.data.size) {
if (isChrome && e.data && !('size' in e.data)) {
e.data.size = e.data.length || e.data.byteLength || 0;
}

Expand Down Expand Up @@ -1468,6 +1492,13 @@ function MediaStreamRecorder(mediaStream, config) {
type: e.data.type || config.mimeType || 'audio/ogg'
});

if (bytesToSize(self.blob) === '3.69 KB') {
if (!config.disableLogs) {
console.error('Seems recorded blob is corrupt.');
}
return;
}

if (self.callback) {
self.callback();
}
Expand Down Expand Up @@ -1547,6 +1578,9 @@ function MediaStreamRecorder(mediaStream, config) {
// mediaRecorder.requestData();
mediaRecorder.stop();
}

// mandatory to make sure Firefox doesn't fails to record streams 3-4 times without reloading the page.
mediaRecorder = null;
};

/**
Expand Down Expand Up @@ -1574,17 +1608,17 @@ function MediaStreamRecorder(mediaStream, config) {
* recorder.resume();
*/
this.resume = function() {
if (!mediaRecorder) {
return;
}

if (this.dontFireOnDataAvailableEvent) {
this.dontFireOnDataAvailableEvent = false;
dataAvailable = false;
this.record();
return;
}

if (!mediaRecorder) {
return;
}

if (mediaRecorder.state === 'paused') {
mediaRecorder.resume();
}
Expand Down
4 changes: 2 additions & 2 deletions RecordRTC.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 2beeceb

Please sign in to comment.