"use strict"; var File = require("./file"); var Vocabulary = require("../../wType/vocabulary"); var Uint64 = require("../../wType/uint64"); var Audio = File.inherit({ className: "Audio", constructor: function Audio(addr) { File.fn.constructor.call(this, addr); this._loadedFrames = 0; this._totalFrames = 0; this._waitingForFrames = false; this._portions = []; this.addHandler("responseFrames"); }, hasMore: function() { return this._totalFrames > this._loadedFrames; }, _getAdditional: function(add) { var ac = File.fn._getAdditional.call(this, add); if (ac) { this._loadedFrames = 0; this._totalFrames = this._additional.at("framesAmount").valueOf(); this._waitingForFrames = false; } this.initialized = true; return ac; }, _h_responseFrames: function(ev) { if (this._waitingForFrames === true) { var data = ev.getData(); var success = data.at("result").valueOf(); if (success === 0) { var amount = data.at("amount").valueOf(); var blob = data.at("data").clone(); this._loadedFrames += amount; this._waitingForFrames = false; this._portions.push(blob); this.trigger("newFrames", blob); } } }, requestMore: function() { if (!this._waitingForFrames) { if (this._registered && this._subscribed) { var allowed = this._totalFrames - this._loadedFrames; if (allowed > 0) { var vc = new Vocabulary(); vc.insert("index", new Uint64(this._loadedFrames)); vc.insert("amount", new Uint64(Math.min(framePortion, allowed))); this.send(vc, "requestFrames"); this._waitingForFrames = true; } } } } }); var framePortion = 10; module.exports = Audio;