From 3c4fa3139b06a1e186b233eae9454b33bd97e4ca Mon Sep 17 00:00:00 2001 From: orthatg <325504+orthatg@users.noreply.github.com> Date: Thu, 9 May 2019 10:05:00 -0500 Subject: [PATCH 1/2] Added error handling for getSeekableBlob If an error occurs during EMBL decoding, the function will no longer fail. Now errors are caught and the callback will always be called. --- RecordRTC.js | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/RecordRTC.js b/RecordRTC.js index 1bccef53..dca2f07b 100644 --- a/RecordRTC.js +++ b/RecordRTC.js @@ -1881,6 +1881,7 @@ function setSrcObject(stream, element) { /** * @param {Blob} file - File or Blob object. * @param {function} callback - Callback function. + * @returns {Blob} seekableFile - New seekable File or Blob; returns null if error occurred * @example * getSeekableBlob(blob or file, callback); * @see {@link https://github.com/muaz-khan/RecordRTC|RecordRTC Source Code} @@ -1897,19 +1898,29 @@ function getSeekableBlob(inputBlob, callback) { var fileReader = new FileReader(); fileReader.onload = function(e) { - var ebmlElms = decoder.decode(this.result); - ebmlElms.forEach(function(element) { - reader.read(element); - }); - reader.stop(); - var refinedMetadataBuf = tools.makeMetadataSeekable(reader.metadatas, reader.duration, reader.cues); - var body = this.result.slice(reader.metadataSize); - var newBlob = new Blob([refinedMetadataBuf, body], { - type: 'video/webm' - }); - - callback(newBlob); - }; + try { + var ebmlElms = decoder.decode(this.result); + ebmlElms.forEach(function(element) { + reader.read(element); + }); + reader.stop(); + var refinedMetadataBuf = tools.makeMetadataSeekable(reader.metadatas, reader.duration, reader.cues); + var body = this.result.slice(reader.metadataSize); + var newBlob = new Blob([refinedMetadataBuf, body], { + type: 'video/webm' + }); + + callback(newBlob); + } + catch (error) { + console.error("Could not decode file to make it seekable", {error}); + callback(null); + } + }; + fileReader.onerror = function(error) { + console.error("An error occurred attempting to load file", {error}); + callback(null); + }; fileReader.readAsArrayBuffer(inputBlob); } From fa5128a65a45973f1281b7f0d38f7f64be1ba1f6 Mon Sep 17 00:00:00 2001 From: orthatg <325504+orthatg@users.noreply.github.com> Date: Thu, 9 May 2019 10:13:59 -0500 Subject: [PATCH 2/2] Match formatting style: tabs to spaces --- RecordRTC.js | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/RecordRTC.js b/RecordRTC.js index dca2f07b..d3226f28 100644 --- a/RecordRTC.js +++ b/RecordRTC.js @@ -1898,29 +1898,29 @@ function getSeekableBlob(inputBlob, callback) { var fileReader = new FileReader(); fileReader.onload = function(e) { - try { - var ebmlElms = decoder.decode(this.result); - ebmlElms.forEach(function(element) { - reader.read(element); - }); - reader.stop(); - var refinedMetadataBuf = tools.makeMetadataSeekable(reader.metadatas, reader.duration, reader.cues); - var body = this.result.slice(reader.metadataSize); - var newBlob = new Blob([refinedMetadataBuf, body], { - type: 'video/webm' - }); - - callback(newBlob); - } - catch (error) { - console.error("Could not decode file to make it seekable", {error}); - callback(null); - } - }; - fileReader.onerror = function(error) { - console.error("An error occurred attempting to load file", {error}); - callback(null); - }; + try { + var ebmlElms = decoder.decode(this.result); + ebmlElms.forEach(function(element) { + reader.read(element); + }); + reader.stop(); + var refinedMetadataBuf = tools.makeMetadataSeekable(reader.metadatas, reader.duration, reader.cues); + var body = this.result.slice(reader.metadataSize); + var newBlob = new Blob([refinedMetadataBuf, body], { + type: 'video/webm' + }); + + callback(newBlob); + } + catch (error) { + console.error("Could not decode file to make it seekable", {error}); + callback(null); + } + }; + fileReader.onerror = function(error) { + console.error("An error occurred attempting to load file", {error}); + callback(null); + }; fileReader.readAsArrayBuffer(inputBlob); }