Skip to content

Commit

Permalink
Review and annotate BlobFileSource
Browse files Browse the repository at this point in the history
  • Loading branch information
sethlu committed Aug 26, 2017
1 parent bad8ea0 commit 87039a0
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions scripts/jointsources/BlobFileSource.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@

var BlobFileSource = Source.createComponent("BlobFileSource");
/**
* BlobFileSource
* Abstract model for a media file that can be audio, video, image, doc, etc.
*/
let BlobFileSource = Source.createComponent("BlobFileSource");

BlobFileSource.defineMethod("construct", function construct() {

// Construct file handler
if (!this.fileHandler) this.fileHandler = new BlobFileHandler();

});

BlobFileSource.defineMethod("init", function init(content, conversation, sourceId) {
BlobFileSource.defineMethod("init", function init(content, jointSource, sourceId) {

// Sync file handler
if (content && content["0"]) {
this.fileHandler.blob = content["0"];
this.fileHandler.didUpdate();
Expand All @@ -18,18 +24,23 @@ BlobFileSource.defineMethod("init", function init(content, conversation, sourceI

BlobFileSource.defineMethod("didUpdate", function didUpdate() {

// Sync file handler
this.fileHandler.blob = this.content["0"];
this.fileHandler.didUpdate();

});

BlobFileSource.defineMethod("destruct", function destruct() {

// Destruct file handler
this.fileHandler.destroy();
delete this.fileHandler;

});

BlobFileSource.prototype.prePublish = function () {
// Publish

BlobFileSource.prototype.prePublish = function prePublish() {
return Promise.resolve()
.then(function () {
if (this.content["0"] && this.content["0"] instanceof Blob) {
Expand All @@ -41,7 +52,9 @@ BlobFileSource.prototype.prePublish = function () {
}.bind(this));
};

BlobFileSource.prototype.getFileStats = function () {
// Stats

BlobFileSource.prototype.getFileStats = function getFileStats() {
if (this.content["0"]) {
if (this.content["0"] instanceof Blob) {
return Promise.resolve({
Expand All @@ -51,5 +64,5 @@ BlobFileSource.prototype.getFileStats = function () {
}
return ICA.getFileStats(this.content["0"]);
}
return Promise.reject(new Error("File not exist"));
return Promise.reject(new Error("File does not exist"));
};

0 comments on commit 87039a0

Please sign in to comment.