105 lines
3.3 KiB
JavaScript
105 lines
3.3 KiB
JavaScript
|
|
/**
|
||
|
|
* This method can be used to get all recorded blobs from IndexedDB storage.
|
||
|
|
* @param {string} type - 'all' or 'audio' or 'video' or 'gif'
|
||
|
|
* @param {function} callback - Callback function to get all stored blobs.
|
||
|
|
* @method
|
||
|
|
* @memberof RecordRTC
|
||
|
|
* @example
|
||
|
|
* RecordRTC.getFromDisk('all', function(dataURL, type){
|
||
|
|
* if(type === 'audio') { }
|
||
|
|
* if(type === 'video') { }
|
||
|
|
* if(type === 'gif') { }
|
||
|
|
* });
|
||
|
|
*/
|
||
|
|
RecordRTC.getFromDisk = function(type, callback) {
|
||
|
|
if (!callback) {
|
||
|
|
throw 'callback is mandatory.';
|
||
|
|
}
|
||
|
|
|
||
|
|
console.log('Getting recorded ' + (type === 'all' ? 'blobs' : type + ' blob ') + ' from disk!');
|
||
|
|
DiskStorage.Fetch(function(dataURL, _type) {
|
||
|
|
if (type !== 'all' && _type === type + 'Blob' && callback) {
|
||
|
|
callback(dataURL);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (type === 'all' && callback) {
|
||
|
|
callback(dataURL, _type.replace('Blob', ''));
|
||
|
|
}
|
||
|
|
});
|
||
|
|
};
|
||
|
|
|
||
|
|
/**
|
||
|
|
* This method can be used to store recorded blobs into IndexedDB storage.
|
||
|
|
* @param {object} options - {audio: Blob, video: Blob, gif: Blob}
|
||
|
|
* @method
|
||
|
|
* @memberof RecordRTC
|
||
|
|
* @example
|
||
|
|
* RecordRTC.writeToDisk({
|
||
|
|
* audio: audioBlob,
|
||
|
|
* video: videoBlob,
|
||
|
|
* gif : gifBlob
|
||
|
|
* });
|
||
|
|
*/
|
||
|
|
RecordRTC.writeToDisk = function(options) {
|
||
|
|
console.log('Writing recorded blob(s) to disk!');
|
||
|
|
options = options || {};
|
||
|
|
if (options.audio && options.video && options.gif) {
|
||
|
|
options.audio.getDataURL(function(audioDataURL) {
|
||
|
|
options.video.getDataURL(function(videoDataURL) {
|
||
|
|
options.gif.getDataURL(function(gifDataURL) {
|
||
|
|
DiskStorage.Store({
|
||
|
|
audioBlob: audioDataURL,
|
||
|
|
videoBlob: videoDataURL,
|
||
|
|
gifBlob: gifDataURL
|
||
|
|
});
|
||
|
|
});
|
||
|
|
});
|
||
|
|
});
|
||
|
|
} else if (options.audio && options.video) {
|
||
|
|
options.audio.getDataURL(function(audioDataURL) {
|
||
|
|
options.video.getDataURL(function(videoDataURL) {
|
||
|
|
DiskStorage.Store({
|
||
|
|
audioBlob: audioDataURL,
|
||
|
|
videoBlob: videoDataURL
|
||
|
|
});
|
||
|
|
});
|
||
|
|
});
|
||
|
|
} else if (options.audio && options.gif) {
|
||
|
|
options.audio.getDataURL(function(audioDataURL) {
|
||
|
|
options.gif.getDataURL(function(gifDataURL) {
|
||
|
|
DiskStorage.Store({
|
||
|
|
audioBlob: audioDataURL,
|
||
|
|
gifBlob: gifDataURL
|
||
|
|
});
|
||
|
|
});
|
||
|
|
});
|
||
|
|
} else if (options.video && options.gif) {
|
||
|
|
options.video.getDataURL(function(videoDataURL) {
|
||
|
|
options.gif.getDataURL(function(gifDataURL) {
|
||
|
|
DiskStorage.Store({
|
||
|
|
videoBlob: videoDataURL,
|
||
|
|
gifBlob: gifDataURL
|
||
|
|
});
|
||
|
|
});
|
||
|
|
});
|
||
|
|
} else if (options.audio) {
|
||
|
|
options.audio.getDataURL(function(audioDataURL) {
|
||
|
|
DiskStorage.Store({
|
||
|
|
audioBlob: audioDataURL
|
||
|
|
});
|
||
|
|
});
|
||
|
|
} else if (options.video) {
|
||
|
|
options.video.getDataURL(function(videoDataURL) {
|
||
|
|
DiskStorage.Store({
|
||
|
|
videoBlob: videoDataURL
|
||
|
|
});
|
||
|
|
});
|
||
|
|
} else if (options.gif) {
|
||
|
|
options.gif.getDataURL(function(gifDataURL) {
|
||
|
|
DiskStorage.Store({
|
||
|
|
gifBlob: gifDataURL
|
||
|
|
});
|
||
|
|
});
|
||
|
|
}
|
||
|
|
};
|