Skip to content

Commit

Permalink
Updated dev/WebAssemblyRecorder.js for some missing API.
Browse files Browse the repository at this point in the history
  • Loading branch information
muaz-khan committed Jan 20, 2019
1 parent 75ea68d commit a2a4ba0
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 24 deletions.
57 changes: 46 additions & 11 deletions RecordRTC.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

// Last time updated: 2019-01-15 1:33:03 AM UTC
// Last time updated: 2019-01-20 9:21:50 AM UTC

// ________________
// RecordRTC v5.5.3
Expand Down Expand Up @@ -1071,7 +1071,7 @@ function GetRecorderType(mediaStream, config) {
* recorder.addStream(MediaStream);
* recorder.mediaType = {
* audio: true, // or StereoAudioRecorder or MediaStreamRecorder
* video: true, // or WhammyRecorder or MediaStreamRecorder or WebAssemblyRecorder
* video: true, // or WhammyRecorder or MediaStreamRecorder or WebAssemblyRecorder or CanvasRecorder
* gif: true // or GifRecorder
* };
* // mimeType is optional and should be set only in advance cases.
Expand Down Expand Up @@ -1111,7 +1111,7 @@ function MRecordRTC(mediaStream) {
* var recorder = new MRecordRTC();
* recorder.mediaType = {
* audio: true, // TRUE or StereoAudioRecorder or MediaStreamRecorder
* video: true, // TRUE or WhammyRecorder or MediaStreamRecorder or WebAssemblyRecorder
* video: true, // TRUE or WhammyRecorder or MediaStreamRecorder or WebAssemblyRecorder or CanvasRecorder
* gif : true // TRUE or GifRecorder
* };
*/
Expand Down Expand Up @@ -1186,16 +1186,18 @@ function MRecordRTC(mediaStream) {
if (isMediaRecorderCompatible() && !!mediaType.audio && typeof mediaType.audio === 'function') {
var videoTrack = getTracks(mediaStream, 'video')[0];

if (!!navigator.mozGetUserMedia) {
if (isFirefox) {
newStream = new MediaStream();
newStream.addTrack(videoTrack);

if (recorderType && recorderType === WhammyRecorder) {
// Firefox does NOT support webp-encoding yet
// Firefox does NOT supports webp-encoding yet
// But Firefox do supports WebAssemblyRecorder
recorderType = MediaStreamRecorder;
}
} else {
newStream = new MediaStream([videoTrack]);
newStream = new MediaStream();
newStream.addTrack(videoTrack);
}
}

Expand All @@ -1210,7 +1212,9 @@ function MRecordRTC(mediaStream) {
timeSlice: this.timeSlice,
onTimeStamp: this.onTimeStamp,
workerPath: this.workerPath,
webAssemblyPath: this.webAssemblyPath
webAssemblyPath: this.webAssemblyPath,
frameRate: this.frameRate, // used by WebAssemblyRecorder; values: usually 30; accepts any.
bitrate: this.bitrate // used by WebAssemblyRecorder; values: 0 to 1000+
});

if (!mediaType.audio) {
Expand All @@ -1221,9 +1225,15 @@ function MRecordRTC(mediaStream) {
if (!!mediaType.audio && !!mediaType.video) {
var self = this;

// this line prevents StereoAudioRecorder
// todo: fix it
if (isMediaRecorderCompatible() /* && !this.audioRecorder */ ) {
var isSingleRecorder = isMediaRecorderCompatible() === true;

if (mediaType.audio instanceof StereoAudioRecorder && !!mediaType.video) {
isSingleRecorder = false;
} else if (mediaType.audio !== true && mediaType.video !== true && mediaType.audio !== mediaType.video) {
isSingleRecorder = false;
}

if (isSingleRecorder === true) {
self.audioRecorder = null;
self.videoRecorder.startRecording();
} else {
Expand Down Expand Up @@ -5632,7 +5642,7 @@ if (typeof RecordRTC !== 'undefined') {
* });
* @see {@link https://github.com/muaz-khan/RecordRTC|RecordRTC Source Code}
* @param {MediaStream} mediaStream - MediaStream object fetched using getUserMedia API or generated using captureStreamUntilEnded or WebAudio API.
* @param {object} config - {webAssemblyPath:'webm-wasm.wasm',workerPath: 'webm-worker.js', frameRate: 30, width: 1920, height: 1080}
* @param {object} config - {webAssemblyPath:'webm-wasm.wasm',workerPath: 'webm-worker.js', frameRate: 30, width: 1920, height: 1080, bitrate: 1024}
*/
function WebAssemblyRecorder(stream, config) {
// based on: github.com/GoogleChromeLabs/webm-wasm
Expand Down Expand Up @@ -5747,6 +5757,10 @@ function WebAssemblyRecorder(stream, config) {
isPaused = false;
this.blob = null;
startRecording(stream);

if (typeof config.initCallback === 'function') {
config.initCallback();
}
};

var isPaused;
Expand Down Expand Up @@ -5805,6 +5819,27 @@ function WebAssemblyRecorder(stream, config) {
callback(this.blob);
};

// for debugging
this.name = 'WebAssemblyRecorder';
this.toString = function() {
return this.name;
};

/**
* This method resets currently recorded data.
* @method
* @memberof WebAssemblyRecorder
* @example
* recorder.clearRecordedData();
*/
this.clearRecordedData = function() {
arrayOfBuffers = [];
isPaused = false;
this.blob = null;

// todo: if recording-ON then STOP it first
};

/**
* @property {Blob} blob - The recorded blob object.
* @memberof WebAssemblyRecorder
Expand Down
8 changes: 4 additions & 4 deletions RecordRTC.min.js

Large diffs are not rendered by default.

28 changes: 19 additions & 9 deletions dev/MRecordRTC.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* recorder.addStream(MediaStream);
* recorder.mediaType = {
* audio: true, // or StereoAudioRecorder or MediaStreamRecorder
* video: true, // or WhammyRecorder or MediaStreamRecorder or WebAssemblyRecorder
* video: true, // or WhammyRecorder or MediaStreamRecorder or WebAssemblyRecorder or CanvasRecorder
* gif: true // or GifRecorder
* };
* // mimeType is optional and should be set only in advance cases.
Expand Down Expand Up @@ -53,7 +53,7 @@ function MRecordRTC(mediaStream) {
* var recorder = new MRecordRTC();
* recorder.mediaType = {
* audio: true, // TRUE or StereoAudioRecorder or MediaStreamRecorder
* video: true, // TRUE or WhammyRecorder or MediaStreamRecorder or WebAssemblyRecorder
* video: true, // TRUE or WhammyRecorder or MediaStreamRecorder or WebAssemblyRecorder or CanvasRecorder
* gif : true // TRUE or GifRecorder
* };
*/
Expand Down Expand Up @@ -128,16 +128,18 @@ function MRecordRTC(mediaStream) {
if (isMediaRecorderCompatible() && !!mediaType.audio && typeof mediaType.audio === 'function') {
var videoTrack = getTracks(mediaStream, 'video')[0];

if (!!navigator.mozGetUserMedia) {
if (isFirefox) {
newStream = new MediaStream();
newStream.addTrack(videoTrack);

if (recorderType && recorderType === WhammyRecorder) {
// Firefox does NOT support webp-encoding yet
// Firefox does NOT supports webp-encoding yet
// But Firefox do supports WebAssemblyRecorder
recorderType = MediaStreamRecorder;
}
} else {
newStream = new MediaStream([videoTrack]);
newStream = new MediaStream();
newStream.addTrack(videoTrack);
}
}

Expand All @@ -152,7 +154,9 @@ function MRecordRTC(mediaStream) {
timeSlice: this.timeSlice,
onTimeStamp: this.onTimeStamp,
workerPath: this.workerPath,
webAssemblyPath: this.webAssemblyPath
webAssemblyPath: this.webAssemblyPath,
frameRate: this.frameRate, // used by WebAssemblyRecorder; values: usually 30; accepts any.
bitrate: this.bitrate // used by WebAssemblyRecorder; values: 0 to 1000+
});

if (!mediaType.audio) {
Expand All @@ -163,9 +167,15 @@ function MRecordRTC(mediaStream) {
if (!!mediaType.audio && !!mediaType.video) {
var self = this;

// this line prevents StereoAudioRecorder
// todo: fix it
if (isMediaRecorderCompatible() /* && !this.audioRecorder */ ) {
var isSingleRecorder = isMediaRecorderCompatible() === true;

if (mediaType.audio instanceof StereoAudioRecorder && !!mediaType.video) {
isSingleRecorder = false;
} else if (mediaType.audio !== true && mediaType.video !== true && mediaType.audio !== mediaType.video) {
isSingleRecorder = false;
}

if (isSingleRecorder === true) {
self.audioRecorder = null;
self.videoRecorder.startRecording();
} else {
Expand Down
25 changes: 25 additions & 0 deletions dev/WebAssemblyRecorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ function WebAssemblyRecorder(stream, config) {
isPaused = false;
this.blob = null;
startRecording(stream);

if (typeof config.initCallback === 'function') {
config.initCallback();
}
};

var isPaused;
Expand Down Expand Up @@ -189,6 +193,27 @@ function WebAssemblyRecorder(stream, config) {
callback(this.blob);
};

// for debugging
this.name = 'WebAssemblyRecorder';
this.toString = function() {
return this.name;
};

/**
* This method resets currently recorded data.
* @method
* @memberof WebAssemblyRecorder
* @example
* recorder.clearRecordedData();
*/
this.clearRecordedData = function() {
arrayOfBuffers = [];
isPaused = false;
this.blob = null;

// todo: if recording-ON then STOP it first
};

/**
* @property {Blob} blob - The recorded blob object.
* @memberof WebAssemblyRecorder
Expand Down

0 comments on commit a2a4ba0

Please sign in to comment.