Code coverage report for api/audio_video/AudioVideo.js

Statements: 66.07% (37 / 56)      Branches: 60% (24 / 40)      Functions: 75% (9 / 12)      Lines: 66.07% (37 / 56)      Ignored: none     

All files » api/audio_video/ » AudioVideo.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 1331 1 1                   1 812 726   812 812     1 1             285215                         813                                     285271 285217 285217   54     27     27       27 27   27 27                               28 28           29 28   29     4     4       4           1 1 1 1 1   1         1  
var FieldDBObject = require("./../FieldDBObject").FieldDBObject;
var AudioPlayer = require("./AudioPlayer").AudioPlayer;
var mime = require("browserify-mime");
/**
 * @class The AudioVideo is a type of FieldDBObject with any additional fields or
 * metadata that a team might use to ground/tag their primary data.
 *
 *
 * @name  AudioVideo
 * @extends FieldDBObject
 * @constructs
 */
var AudioVideo = function AudioVideo(options) {
  if (!this._fieldDBtype) {
    this._fieldDBtype = "AudioVideo";
  }
  this.debug("Constructing AudioVideo length: ", options);
  FieldDBObject.apply(this, arguments);
};
 
var DEFAULT_BASE_SPEECH_URL = "https://localhost:3184";
AudioVideo.prototype = Object.create(FieldDBObject.prototype, /** @lends AudioVideo.prototype */ {
  constructor: {
    value: AudioVideo
  },
 
  BASE_SPEECH_URL: {
    get: function() {
      return DEFAULT_BASE_SPEECH_URL;
    },
    set: function(value) {
      DEFAULT_BASE_SPEECH_URL = value;
    }
  },
 
  api: {
    value: "speech"
  },
 
  id: {
    get: function() {
      return this._URL || FieldDBObject.DEFAULT_STRING;
    },
    set: function(value) {
      if (value === this._URL) {
        return;
      }
      if (!value) {
        delete this._URL;
        return;
      }
      if (value.trim) {
        value = value.trim();
      }
      this._URL = value;
    }
  },
 
  URL: {
    get: function() {
      if (!this._URL && this.filename) {
        var baseUrl = this.url ? this.url : this.BASE_SPEECH_URL;
        return baseUrl + "/" + this.dbname + "/" + this.filename;
      }
      return this._URL || FieldDBObject.DEFAULT_STRING;
    },
    set: function(value) {
      Iif (value === this._URL) {
        return;
      }
      Iif (!value) {
        delete this._URL;
        return;
      }
      Eif (value.trim) {
        value = value.trim();
      }
      this._URL = value;
      Iif (this.audioPlayer) {
        this.audioPlayer.src = value;
      }
    }
  },
 
  play: {
    value: function(optionalStartTime, optionalEndTime, optionalDuration) {
      this.warn("playing", this, optionalStartTime, optionalEndTime, optionalDuration);
      this.audioPlayer = this.audioPlayer || new AudioPlayer();
      this.audioPlayer.play(this.URL);
    }
  },
 
  guessType: {
    value: function(filename) {
      var guessedType = mime.lookup(filename);
      return guessedType;
    }
  },
 
  type: {
    get: function() {
      if (!this._type && this.filename) {
        this._type = this.guessType(this.filename);
      }
      return this._type || FieldDBObject.DEFAULT_STRING;
    },
    set: function(value) {
      Iif (value === this._type) {
        return;
      }
      Iif (this.filename && !this.checksum) {
        this.warn("type cannot be set, it is automatically determined from the filename. Not using: " + value);
        value = this.guessType(this.filename);
      }
      this._type = value;
    }
  },
 
  toJSON: {
    value: function(includeEvenEmptyAttributes, removeEmptyAttributes) {
      this.debug("Customizing toJSON ", includeEvenEmptyAttributes, removeEmptyAttributes);
      var json = FieldDBObject.prototype.toJSON.apply(this, arguments);
      delete json.audioPlayer;
      json.type = this.type;
      json.URL = this.URL;
 
      return json;
    }
  }
 
});
exports.AudioVideo = AudioVideo;