-
Notifications
You must be signed in to change notification settings - Fork 0
/
radiokit-toolkit-playback.js.map
1 lines (1 loc) · 55.5 KB
/
radiokit-toolkit-playback.js.map
1
{"version":3,"sources":["webpack:///webpack/bootstrap eaffc8ebcfd0f425adb7","webpack:///./lib/index.ts","webpack:///./lib/channel/Player.ts","webpack:///./lib/Base.ts","webpack:///./lib/clock/SyncClock.ts","webpack:///./lib/channel/PlaylistFetcher.ts","webpack:///./lib/channel/PlaylistResolver.ts","webpack:///./lib/channel/Playlist.ts","webpack:///./lib/channel/Track.ts","webpack:///./lib/channel/TrackInfo.ts","webpack:///./lib/audio/AudioManager.ts","webpack:///./lib/audio/Factory.ts","webpack:///./lib/audio/HTMLPlayer.ts","webpack:///./lib/audio/StreamManager.ts"],"names":[],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;ACXA;AACA;AACA;AACA,oBAAmB,sBAAsB;AACzC;AACA;AACA;AACA,6CAA4C,OAAO;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kCAAiC,cAAc;AAC/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA2B;AAC3B,sCAAqC;AACrC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,qIAAoI,qDAAqD;AACzL;AACA,kBAAiB;AACjB;AACA;AACA;AACA;AACA,kBAAiB;AACjB,cAAa;AACb;AACA;AACA;AACA;AACA;AACA,cAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,UAAS;AACT;AACA;AACA;AACA;AACA,UAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,UAAS;AACT;AACA;AACA,UAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,EAAC;AACD;;;;;;;ACzNA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,yBAAwB,uBAAuB;AAC/C;AACA;AACA;AACA;AACA,4DAA2D,gBAAgB;AAC3E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,EAAC;AACD;;;;;;;ACnEA;AACA;AACA;AACA,oBAAmB,sBAAsB;AACzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,UAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,EAAC;AACD;;;;;;;ACpDA;AACA;AACA,6CAA4C,OAAO;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kCAAiC,cAAc;AAC/C,2BAA0B;AAC1B,qCAAoC;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,0BAAyB;AACzB;AACA;AACA,0BAAyB;AACzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,UAAS;AACT;AACA;AACA;AACA,EAAC;AACD;;;;;;;AC3EA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,uDAAsD,gBAAgB;AACtE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oDAAmD;AACnD,oDAAmD;AACnD;AACA,oDAAmD;AACnD,oDAAmD;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,UAAS;AACT;AACA;AACA;AACA,EAAC;AACD;;;;;;;AChEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sDAAqD,2BAA2B;AAChF;AACA;AACA;AACA;AACA,oDAAmD,wBAAwB;AAC3E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,EAAC;AACD;;;;;;;ACnCA;AACA;AACA;AACA,oBAAmB,sBAAsB;AACzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,UAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA,EAAC;AACD;;;;;;;ACtHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,wDAAuD,gBAAgB;AACvE;AACA;AACA;AACA,sDAAqD,gBAAgB;AACrE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,EAAC;AACD;;;;;;;AC/BA;AACA;AACA;AACA,oBAAmB,sBAAsB;AACzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4CAA2C,sBAAsB;AACjE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,EAAC;AACD;;;;;;;AC9FA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,EAAC;AACD;;;;;;;ACVA;AACA;AACA;AACA,oBAAmB,sBAAsB;AACzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,EAAC;AACD;;;;;;;AC5OA;AACA;AACA;AACA,oBAAmB,sBAAsB;AACzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAa;AACb;AACA;AACA;AACA,EAAC;AACD","file":"radiokit-toolkit-playback.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap eaffc8ebcfd0f425adb7","\"use strict\";\nvar Player_1 = require(\"./channel/Player\");\nexports.Channel = {\n Player: Player_1.Player,\n};\nif (typeof (window) !== \"undefined\") {\n window['RadioKitToolkitPlayback'] = {\n Channel: {\n Player: Player_1.Player,\n }\n };\n}\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./lib/index.ts\n// module id = 0\n// module chunks = 0","\"use strict\";\nvar __extends = (this && this.__extends) || function (d, b) {\n for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n};\nvar __assign = (this && this.__assign) || Object.assign || function(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\n t[p] = s[p];\n }\n return t;\n};\nvar Base_1 = require(\"../Base\");\nvar SyncClock_1 = require(\"../clock/SyncClock\");\nvar PlaylistFetcher_1 = require(\"../channel/PlaylistFetcher\");\nvar AudioManager_1 = require(\"../audio/AudioManager\");\nvar StreamManager_1 = require(\"../audio/StreamManager\");\nvar Player = (function (_super) {\n __extends(Player, _super);\n function Player(channelId, accessToken, options) {\n if (options === void 0) { options = {}; }\n var _this = _super.call(this) || this;\n _this.__fetchTimeoutId = 0;\n _this.__playbackStartedEmitted = false;\n _this.__playlist = null;\n _this.__clock = null;\n _this.__fetching = false;\n _this.__playlistFetcher = null;\n _this.__volume = 1.0;\n _this.__options = { from: 20, to: 600 };\n _this.__options = __assign({}, _this.__options, options);\n _this.__started = false;\n _this.__channelId = channelId;\n _this.__accessToken = accessToken;\n return _this;\n }\n Player.prototype.start = function () {\n if (!this.__started) {\n this.__startFetching();\n this.__started = true;\n this.__playbackStartedEmitted = false;\n if (this.__supportsAudioManager()) {\n this.debug(\"Using AudioManager\");\n this.__audioManager = new AudioManager_1.AudioManager();\n this.__audioManager.setVolume(this.__volume);\n this.__audioManager.on('playback-started', this.__onAudioManagerPlaybackStarted.bind(this));\n this.__audioManager.on('position', this.__onAudioManagerPosition.bind(this));\n }\n else {\n this.debug(\"Using StreamManager\");\n this.__streamManager = new StreamManager_1.StreamManager(this.__channelId);\n this.__streamManager.setVolume(this.__volume);\n this.__streamManager.on('playback-started', this.__onStreamManagerPlaybackStarted.bind(this));\n this.__streamManager.start();\n }\n }\n return this;\n };\n Player.prototype.stop = function () {\n if (this.__started) {\n this.__started = false;\n if (this.__audioManager) {\n this.__audioManager.offAll();\n this.__audioManager.cleanup();\n delete this.__audioManager;\n this.__audioManager = undefined;\n }\n else if (this.__streamManager) {\n this.__streamManager.offAll();\n this.__streamManager.stop();\n delete this.__streamManager;\n this.__streamManager = undefined;\n }\n return this;\n }\n };\n Player.prototype.setVolume = function (volume) {\n if (volume < 0.0 || volume > 1.0) {\n throw new Error('Volume out of range');\n }\n this.debug(\"Volume set to \" + volume);\n this.__volume = volume;\n if (this.__audioManager) {\n this.__audioManager.setVolume(volume);\n }\n return this;\n };\n Player.prototype.getVolume = function () {\n return this.__volume;\n };\n Player.prototype.isStarted = function () {\n return this.__started;\n };\n Player.prototype.fetchPlaylist = function () {\n this.__startFetching();\n return this;\n };\n Player.prototype.stopFetching = function () {\n if (this.__fetching) {\n this.__fetching = false;\n if (this.__fetchTimeoutId !== 0) {\n clearTimeout(this.__fetchTimeoutId);\n this.__fetchTimeoutId = 0;\n }\n }\n };\n Player.prototype._loggerTag = function () {\n return this['constructor']['name'] + \" \" + this.__channelId;\n };\n Player.prototype.__supportsAudioManager = function () {\n return (!this.__isAndroid() &&\n !this.__isIPhone() &&\n !this.__isSafari());\n };\n Player.prototype.__isAndroid = function () {\n return navigator.userAgent.indexOf('Android') !== -1;\n };\n Player.prototype.__isIPhone = function () {\n return navigator.userAgent.indexOf('iPhone') !== -1;\n };\n Player.prototype.__isSafari = function () {\n return navigator.userAgent.indexOf('Chrome') === -1 && navigator.userAgent.indexOf('Safari') !== -1;\n };\n Player.prototype.__startFetching = function () {\n if (!this.__fetching) {\n this.__fetching = true;\n this.__fetchOnceAndRepeat();\n }\n };\n Player.prototype.__fetchOnce = function () {\n var _this = this;\n if (this.__clock === null) {\n this.debug(\"Fetch: Synchronizing clock...\");\n var promise = new Promise(function (resolve, reject) {\n SyncClock_1.SyncClock.makeAsync()\n .then(function (clock) {\n _this.debug(\"Fetch: Synchronized clock\");\n _this.__clock = clock;\n _this.__playlistFetcher = new PlaylistFetcher_1.PlaylistFetcher(_this.__accessToken, _this.__channelId, clock, { from: _this.__options.from, to: _this.__options.to });\n return _this.__fetchPlaylist(resolve, reject);\n })\n .catch(function (error) {\n _this.warn(\"Fetch error: Unable to sync clock (\" + error.message + \")\");\n _this._trigger('error-network');\n reject(new Error(\"Unable to sync clock (\" + error.message + \")\"));\n });\n });\n return promise;\n }\n else {\n var promise = new Promise(function (resolve, reject) {\n _this.__fetchPlaylist(resolve, reject);\n });\n return promise;\n }\n };\n Player.prototype.__fetchPlaylist = function (resolve, reject) {\n var _this = this;\n this.debug(\"Fetch: Fetching playlist...\");\n this.__playlistFetcher.fetchAsync()\n .then(function (playlist) {\n _this.debug(\"Fetch: Done\");\n resolve(playlist);\n })\n .catch(function (error) {\n _this.warn(\"Fetch error: Unable to fetch playlist (\" + error.message + \")\");\n _this._trigger('error-network');\n reject(new Error(\"Unable to fetch playlist (\" + error.message + \")\"));\n });\n };\n Player.prototype.__fetchOnceAndRepeat = function () {\n var _this = this;\n this.__fetchOnce()\n .then(function (playlist) {\n _this.__playlist = playlist;\n _this.__onPlayListFetched(playlist);\n _this.__started && _this.__audioManager && _this.__audioManager.update(_this.__playlist, _this.__clock);\n _this.__scheduleNextFetch();\n })\n .catch(function (error) {\n _this.__scheduleNextFetch();\n });\n };\n Player.prototype.__scheduleNextFetch = function () {\n var _this = this;\n if (this.__fetching) {\n var timeout = 2000 + Math.round(Math.random() * 250);\n this.debug(\"Fetch: Scheduling next fetch in \" + timeout + \" ms\");\n this.__fetchTimeoutId = setTimeout(function () {\n _this.__fetchTimeoutId = 0;\n _this.__fetchOnceAndRepeat();\n }, timeout);\n }\n };\n Player.prototype.__onPlayListFetched = function (playlist) {\n this._trigger('playlist-fetched', playlist);\n };\n Player.prototype.__onAudioManagerPosition = function (track, position, duration) {\n this._trigger('track-position', track, position, duration);\n };\n Player.prototype.__onAudioManagerPlaybackStarted = function (track) {\n if (!this.__playbackStartedEmitted) {\n this._trigger('playback-started');\n this.__playbackStartedEmitted = true;\n }\n this._trigger('track-playback-started', track);\n };\n Player.prototype.__onStreamManagerPlaybackStarted = function () {\n if (!this.__playbackStartedEmitted) {\n this._trigger('playback-started');\n this.__playbackStartedEmitted = true;\n }\n };\n return Player;\n}(Base_1.Base));\nexports.Player = Player;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./lib/channel/Player.ts\n// module id = 1\n// module chunks = 0","\"use strict\";\nvar Base = (function () {\n function Base() {\n this.__events = {};\n }\n Base.prototype.on = function (eventName, callback) {\n if (this.__events.hasOwnProperty(eventName)) {\n if (this.__events[eventName].indexOf(callback) === -1) {\n this.__events[eventName].push(callback);\n }\n else {\n throw new Error(\"Trying to addd twice the same callback for event \\\"\" + eventName + \"\\\"\");\n }\n }\n else {\n this.__events[eventName] = [callback];\n }\n return this;\n };\n Base.prototype.off = function (eventName, callback) {\n if (this.__events.hasOwnProperty(eventName)) {\n var index = this.__events[eventName].indexOf(callback);\n if (index !== -1) {\n this.__events[eventName].splice(index, 1);\n }\n else {\n throw new Error(\"Trying to remove non-existent callback for event \\\"\" + eventName + \"\\\"\");\n }\n }\n return this;\n };\n Base.prototype.offAll = function (eventName) {\n if (eventName) {\n if (this.__events.hasOwnProperty(eventName)) {\n delete this.__events[eventName];\n }\n }\n else {\n this.__events = {};\n }\n return this;\n };\n Base.prototype._trigger = function (eventName) {\n var args = [];\n for (var _i = 1; _i < arguments.length; _i++) {\n args[_i - 1] = arguments[_i];\n }\n this.debug(\"Event: \" + eventName + \" (\" + JSON.stringify(args) + \")\");\n if (this.__events.hasOwnProperty(eventName)) {\n for (var _a = 0, _b = this.__events[eventName]; _a < _b.length; _a++) {\n var callback = _b[_a];\n callback.apply(this, args);\n }\n }\n return this;\n };\n Base.prototype.warn = function (message) {\n console.warn(\"[\" + new Date().toISOString() + \" RadioKit.Toolkit.Playback \" + this._loggerTag() + \"] \" + message);\n };\n Base.prototype.info = function (message) {\n console.info(\"[\" + new Date().toISOString() + \" RadioKit.Toolkit.Playback \" + this._loggerTag() + \"] \" + message);\n };\n Base.prototype.debug = function (message) {\n console.debug(\"[\" + new Date().toISOString() + \" RadioKit.Toolkit.Playback \" + this._loggerTag() + \"] \" + message);\n };\n return Base;\n}());\nexports.Base = Base;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./lib/Base.ts\n// module id = 2\n// module chunks = 0","\"use strict\";\nvar __extends = (this && this.__extends) || function (d, b) {\n for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n};\nvar Base_1 = require(\"../Base\");\nvar SyncClock = (function (_super) {\n __extends(SyncClock, _super);\n function SyncClock(serverDate) {\n var _this = _super.call(this) || this;\n _this.__offset = serverDate - Date.now();\n _this.debug(\"Synchronized clock: offset = \" + _this.__offset + \" ms\");\n return _this;\n }\n SyncClock.makeAsync = function () {\n var promise = new Promise(function (resolve, reject) {\n var xhr = new XMLHttpRequest();\n xhr.open('OPTIONS', 'https://time.radiokitapp.org/api/time/v1.0/now', true);\n xhr.setRequestHeader('Cache-Control', 'no-cache, must-revalidate');\n xhr.timeout = 5000;\n xhr.onerror = function (e) {\n reject(new Error(\"Unable to synchronize clock: Network error (\" + xhr.status + \")\"));\n };\n xhr.onabort = function (e) {\n reject(new Error(\"Unable to synchronize clock: Aborted\"));\n };\n xhr.ontimeout = function (e) {\n reject(new Error(\"Unable to synchronize clock: Timeout\"));\n };\n xhr.onreadystatechange = function () {\n if (xhr.readyState === 4) {\n if (xhr.status === 200) {\n resolve(new SyncClock(Date.parse(JSON.parse(xhr.responseText).utc_time)));\n }\n else {\n reject(new Error(\"Unable to synchronize clock: Unexpected response (status = \" + xhr.status + \")\"));\n }\n }\n };\n xhr.send();\n });\n return promise;\n };\n SyncClock.prototype.nowAsTimestamp = function () {\n return Date.now() + this.__offset;\n };\n SyncClock.prototype._loggerTag = function () {\n return this['constructor']['name'];\n };\n return SyncClock;\n}(Base_1.Base));\nexports.SyncClock = SyncClock;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./lib/clock/SyncClock.ts\n// module id = 3\n// module chunks = 0","\"use strict\";\nvar __assign = (this && this.__assign) || Object.assign || function(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\n t[p] = s[p];\n }\n return t;\n};\nvar PlaylistResolver_1 = require(\"./PlaylistResolver\");\nvar PlaylistFetcher = (function () {\n function PlaylistFetcher(accessToken, channelId, clock, options) {\n if (options === void 0) { options = {}; }\n this.__options = { from: 20, to: 600 };\n this.__options = __assign({}, this.__options, options);\n this.__clock = clock;\n this.__channelId = channelId;\n this.__accessToken = accessToken;\n }\n PlaylistFetcher.prototype.fetchAsync = function () {\n var _this = this;\n var promise = new Promise(function (resolve, reject) {\n var now = _this.__clock.nowAsTimestamp();\n var xhr = new XMLHttpRequest();\n var url = 'https://plumber.radiokitapp.org/api/rest/v1.0/media/input/file/radiokit/vault' +\n '?a[]=id' +\n '&a[]=name' +\n '&a[]=file' +\n '&a[]=cue_in_at' +\n '&a[]=cue_out_at' +\n '&a[]=cue_offset' +\n '&a[]=fade_in_at' +\n '&a[]=fade_out_at' +\n '&s[]=cue%20' + encodeURIComponent(new Date(now).toISOString()) +\n encodeURIComponent(\" \" + _this.__options.from + \" \" + _this.__options.to) +\n '&c[references][]=deq%20broadcast_channel_id%20' + encodeURIComponent(_this.__channelId) +\n '&o[]=cue_in_at%20asc';\n xhr.open('GET', url, true);\n xhr.setRequestHeader('Cache-Control', 'no-cache, must-revalidate');\n xhr.setRequestHeader('Authorization', \"Bearer \" + _this.__accessToken);\n xhr.setRequestHeader('Accept', 'application/json');\n xhr.timeout = 15000;\n xhr.onerror = function (e) {\n reject(new Error(\"Unable to fetch playlist: Network error (\" + xhr.status + \")\"));\n };\n xhr.onabort = function (e) {\n reject(new Error(\"Unable to fetch playlist: Aborted\"));\n };\n xhr.ontimeout = function (e) {\n reject(new Error(\"Unable to fetch playlist: Timeout\"));\n };\n xhr.onreadystatechange = function () {\n if (xhr.readyState === 4) {\n if (xhr.status === 200) {\n var responseAsJson = JSON.parse(xhr.responseText);\n var resolver = new PlaylistResolver_1.PlaylistResolver(_this.__accessToken, responseAsJson['data']);\n resolver.resolveAsync()\n .then(function (playlist) {\n resolve(playlist);\n })\n .catch(function (error) {\n reject(new Error(\"Unable to resolve playlist (\" + error.message + \")\"));\n });\n }\n else {\n reject(new Error(\"Unable to fetch playlist: Unexpected response (status = \" + xhr.status + \")\"));\n }\n }\n };\n xhr.send();\n });\n return promise;\n };\n return PlaylistFetcher;\n}());\nexports.PlaylistFetcher = PlaylistFetcher;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./lib/channel/PlaylistFetcher.ts\n// module id = 4\n// module chunks = 0","\"use strict\";\nvar Playlist_1 = require(\"./Playlist\");\nvar PlaylistResolver = (function () {\n function PlaylistResolver(accessToken, playlistRaw) {\n this.__playlistRaw = playlistRaw;\n this.__accessToken = accessToken;\n }\n PlaylistResolver.prototype.resolveAsync = function () {\n var _this = this;\n var promise = new Promise(function (resolve, reject) {\n var xhr = new XMLHttpRequest();\n var fileIds = [];\n for (var _i = 0, _a = _this.__playlistRaw; _i < _a.length; _i++) {\n var file = _a[_i];\n fileIds.push(encodeURIComponent(file[\"file\"]));\n }\n var url = 'https://vault.radiokitapp.org/api/rest/v1.0/data/record/file' +\n '?a[]=id' +\n '&a[]=public_url' +\n '&c[id][]=in%20' + fileIds.join(\"%20\");\n xhr.open('GET', url, true);\n xhr.setRequestHeader('Cache-Control', 'no-cache, must-revalidate');\n xhr.setRequestHeader('Authorization', \"Bearer \" + _this.__accessToken);\n xhr.setRequestHeader('Accept', 'application/json');\n xhr.timeout = 15000;\n var audio = new Audio();\n var knownFormats = [];\n if (audio.canPlayType('application/ogg; codecs=opus')) {\n knownFormats.push('application/ogg; codecs=opus');\n }\n if (audio.canPlayType('application/ogg; codecs=vorbis')) {\n knownFormats.push('application/ogg; codecs=vorbis');\n }\n if (audio.canPlayType('audio/mpeg')) {\n knownFormats.push('audio/mpeg');\n }\n xhr.setRequestHeader('X-RadioKit-KnownFormats', knownFormats.join(', '));\n xhr.onerror = function (e) {\n reject(new Error(\"Unable to fetch playlist: Network error (\" + xhr.status + \")\"));\n };\n xhr.onabort = function (e) {\n reject(new Error(\"Unable to fetch playlist: Aborted\"));\n };\n xhr.ontimeout = function (e) {\n reject(new Error(\"Unable to fetch playlist: Timeout\"));\n };\n xhr.onreadystatechange = function () {\n if (xhr.readyState === 4) {\n if (xhr.status === 200) {\n var responseAsJson = JSON.parse(xhr.responseText);\n var responseData = responseAsJson['data'];\n resolve(Playlist_1.Playlist.makeFromJson(_this.__accessToken, _this.__playlistRaw, responseData));\n }\n else {\n reject(new Error(\"Unable to fetch files: Unexpected response (status = \" + xhr.status + \")\"));\n }\n }\n };\n xhr.send();\n });\n return promise;\n };\n return PlaylistResolver;\n}());\nexports.PlaylistResolver = PlaylistResolver;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./lib/channel/PlaylistResolver.ts\n// module id = 5\n// module chunks = 0","\"use strict\";\nvar Track_1 = require(\"./Track\");\nvar Playlist = (function () {\n function Playlist(tracks) {\n this.__tracks = tracks;\n }\n Playlist.makeFromJson = function (accessToken, playlistRaw, filesRaw) {\n var tracks = {};\n for (var _i = 0, playlistRaw_1 = playlistRaw; _i < playlistRaw_1.length; _i++) {\n var playlistRecord = playlistRaw_1[_i];\n var id = playlistRecord['id'];\n var fileId = playlistRecord['file'];\n var fileUrl = void 0;\n for (var _a = 0, filesRaw_1 = filesRaw; _a < filesRaw_1.length; _a++) {\n var fileRecord = filesRaw_1[_a];\n if (fileRecord['id'] === playlistRecord['file']) {\n fileUrl = fileRecord['public_url'];\n break;\n }\n }\n var cueInAt = new Date(playlistRecord['cue_in_at']);\n var cueOutAt = new Date(playlistRecord['cue_out_at']);\n var cueOffset = playlistRecord['cue_offset'];\n var fadeInAt = playlistRecord['fade_in_at'] !== null ? new Date(playlistRecord['fade_in_at']) : null;\n var fadeOutAt = playlistRecord['fade_out_at'] !== null ? new Date(playlistRecord['fade_out_at']) : null;\n var track = new Track_1.Track(accessToken, id, fileId, fileUrl, cueInAt, cueOutAt, cueOffset, fadeInAt, fadeOutAt);\n tracks[id] = track;\n }\n return new Playlist(tracks);\n };\n Playlist.prototype.getTracks = function () {\n return this.__tracks;\n };\n return Playlist;\n}());\nexports.Playlist = Playlist;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./lib/channel/Playlist.ts\n// module id = 6\n// module chunks = 0","\"use strict\";\nvar __extends = (this && this.__extends) || function (d, b) {\n for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n};\nvar Base_1 = require(\"../Base\");\nvar TrackInfo_1 = require(\"./TrackInfo\");\nvar Track = (function (_super) {\n __extends(Track, _super);\n function Track(accessToken, id, fileId, fileUrl, cueInAt, cueOutAt, cueOffset, fadeInAt, fadeOutAt) {\n var _this = _super.call(this) || this;\n _this.__accessToken = accessToken;\n _this.__id = id;\n _this.__fileId = fileId;\n _this.__fileUrl = fileUrl;\n _this.__cueInAt = cueInAt;\n _this.__cueOutAt = cueOutAt;\n _this.__cueOffset = cueOffset;\n _this.__fadeInAt = fadeInAt;\n _this.__fadeOutAt = fadeOutAt;\n return _this;\n }\n Track.prototype.getId = function () {\n return this.__id;\n };\n Track.prototype.getFileId = function () {\n return this.__fileId;\n };\n Track.prototype.getFileUrl = function () {\n return this.__fileUrl;\n };\n Track.prototype.getCueInAt = function () {\n return this.__cueInAt;\n };\n Track.prototype.getCueOutAt = function () {\n return this.__cueOutAt;\n };\n Track.prototype.getFadeInAt = function () {\n return this.__fadeInAt;\n };\n Track.prototype.getFadeOutAt = function () {\n return this.__fadeOutAt;\n };\n Track.prototype.getCueOffset = function () {\n return this.__cueOffset;\n };\n Track.prototype.getInfoAsync = function () {\n var _this = this;\n var promise = new Promise(function (resolve, reject) {\n var xhr = new XMLHttpRequest();\n var url = 'https://vault.radiokitapp.org/api/rest/v1.0/data/record/file' +\n '?a[]=id' +\n '&a[]=name' +\n '&a[]=stage' +\n '&a[]=references' +\n '&a[]=extra' +\n '&a[]=public_url' +\n '&a[]=metadata_schemas.id' +\n '&a[]=metadata_schemas.name' +\n '&a[]=metadata_schemas.key' +\n '&a[]=metadata_schemas.kind' +\n '&a[]=metadata_items.id' +\n '&a[]=metadata_items.metadata_schema_id' +\n '&a[]=metadata_items.metadata_schema_id' +\n '&a[]=metadata_items.value_string' +\n '&a[]=metadata_items.value_db' +\n '&a[]=metadata_items.value_text' +\n '&a[]=metadata_items.value_float' +\n '&a[]=metadata_items.value_integer' +\n '&a[]=metadata_items.value_duration' +\n '&a[]=metadata_items.value_date' +\n '&a[]=metadata_items.value_datetime' +\n '&a[]=metadata_items.value_time' +\n '&a[]=metadata_items.value_file' +\n '&a[]=metadata_items.value_image' +\n '&a[]=metadata_items.value_url' +\n '&j[]=metadata_schemas' +\n '&j[]=metadata_items' +\n '&c[id][]=eq%20' + encodeURIComponent(_this.__fileId);\n xhr.open('GET', url, true);\n xhr.setRequestHeader('Authorization', \"Bearer \" + _this.__accessToken);\n xhr.setRequestHeader('Accept', 'application/json');\n xhr.timeout = 15000;\n xhr.onerror = function (e) {\n reject(new Error(\"Unable to fetch track info: Network error (\" + xhr.status + \")\"));\n };\n xhr.onabort = function (e) {\n reject(new Error(\"Unable to fetch track info: Aborted\"));\n };\n xhr.ontimeout = function (e) {\n reject(new Error(\"Unable to fetch track info: Timeout\"));\n };\n xhr.onreadystatechange = function () {\n if (xhr.readyState === 4) {\n if (xhr.status === 200) {\n var responseAsJson = JSON.parse(xhr.responseText);\n if (responseAsJson[\"data\"].length === 1) {\n resolve(TrackInfo_1.TrackInfo.makeFromJson(responseAsJson[\"data\"][0]));\n }\n else {\n reject(new Error(\"Unable to fetch track info: Record not found\"));\n }\n }\n else {\n reject(new Error(\"Unable to fetch track info: Unexpected response (status = \" + xhr.status + \")\"));\n }\n }\n };\n xhr.send();\n });\n return promise;\n };\n Track.prototype._loggerTag = function () {\n return this['constructor']['name'] + \" \" + this.__id;\n };\n return Track;\n}(Base_1.Base));\nexports.Track = Track;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./lib/channel/Track.ts\n// module id = 7\n// module chunks = 0","\"use strict\";\nvar TrackInfo = (function () {\n function TrackInfo(name, metadata) {\n this.__name = name;\n this.__metadata = metadata;\n }\n TrackInfo.makeFromJson = function (data) {\n var name = data['name'];\n var metadata = {};\n var metadataSchemas = {};\n for (var _i = 0, _a = data['metadata_schemas']; _i < _a.length; _i++) {\n var metadataSchema = _a[_i];\n metadataSchemas[metadataSchema['id']] = metadataSchema;\n }\n for (var _b = 0, _c = data['metadata_items']; _b < _c.length; _b++) {\n var metadataItem = _c[_b];\n var key = metadataSchemas[metadataItem['metadata_schema_id']].key;\n var kind = metadataSchemas[metadataItem['metadata_schema_id']].kind;\n var value = metadataItem[\"value_\" + kind];\n metadata[key] = value;\n }\n return new TrackInfo(name, metadata);\n };\n TrackInfo.prototype.getName = function () {\n return this.__name;\n };\n TrackInfo.prototype.getMetadata = function () {\n return this.__metadata;\n };\n return TrackInfo;\n}());\nexports.TrackInfo = TrackInfo;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./lib/channel/TrackInfo.ts\n// module id = 8\n// module chunks = 0","\"use strict\";\nvar __extends = (this && this.__extends) || function (d, b) {\n for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n};\nvar Factory_1 = require(\"./Factory\");\nvar Base_1 = require(\"../Base\");\nvar AudioManager = (function (_super) {\n __extends(AudioManager, _super);\n function AudioManager() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n _this.__audioPlayers = {};\n _this.__volume = 1.0;\n return _this;\n }\n AudioManager.prototype.update = function (playlist, clock) {\n var tracks = playlist.getTracks();\n var existingIds = Object.keys(this.__audioPlayers);\n var newIds = Object.keys(tracks);\n var tracksToAdd = this.__diff(tracks, this.__audioPlayers);\n var tracksToRemove = this.__diff(this.__audioPlayers, tracks);\n for (var id in tracksToAdd) {\n this.debug(\"Adding track: ID = \" + id);\n this.__audioPlayers[id] = Factory_1.Factory.makeFromTrack(tracks[id], clock);\n this.__audioPlayers[id].setVolume(this.__volume);\n this.__audioPlayers[id].on('playback-started', this.__onAudioPlayerPlaybackStarted.bind(this));\n this.__audioPlayers[id].on('position', this.__onAudioPlayerPosition.bind(this));\n this.__audioPlayers[id].start();\n }\n for (var id in tracksToRemove) {\n this.debug(\"Removing track: ID = \" + id);\n this.__removeAudioPlayer(id);\n }\n };\n AudioManager.prototype.cleanup = function () {\n for (var id in this.__audioPlayers) {\n this.__removeAudioPlayer(id);\n }\n return this;\n };\n AudioManager.prototype.setVolume = function (volume) {\n if (volume < 0.0 || volume > 1.0) {\n throw new Error('Volume out of range');\n }\n this.__volume = volume;\n for (var id in this.__audioPlayers) {\n this.__audioPlayers[id].setVolume(volume);\n }\n return this;\n };\n AudioManager.prototype._loggerTag = function () {\n return \"\" + this['constructor']['name'];\n };\n AudioManager.prototype.__removeAudioPlayer = function (id) {\n if (this.__currentTrack === this.__audioPlayers[id].getTrack()) {\n this.__currentTrack = undefined;\n }\n this.__audioPlayers[id].offAll();\n this.__audioPlayers[id].stop();\n delete this.__audioPlayers[id];\n };\n AudioManager.prototype.__diff = function (object1, object2) {\n var result = {};\n var array1 = Object.keys(object1);\n var array2 = Object.keys(object2);\n for (var _i = 0, array1_1 = array1; _i < array1_1.length; _i++) {\n var item = array1_1[_i];\n if (array2.indexOf(item) === -1) {\n result[item] = object1[item];\n }\n }\n return result;\n };\n AudioManager.prototype.__onAudioPlayerPlaybackStarted = function (audioPlayer) {\n this.__currentTrack = audioPlayer.getTrack();\n this._trigger('playback-started', this.__currentTrack);\n for (var id in this.__audioPlayers) {\n var iteratedAudioPlayer = this.__audioPlayers[id];\n var iteratedTrack = iteratedAudioPlayer.getTrack();\n if (iteratedAudioPlayer !== audioPlayer && iteratedTrack.getCueInAt() <= this.__currentTrack.getCueInAt()) {\n this.debug(\"Applying fade out to player for track \" + iteratedAudioPlayer.getTrack().getId() + \" so it does not overlap with player for track \" + audioPlayer.getTrack().getId());\n iteratedAudioPlayer.fadeOut(1000);\n }\n }\n };\n AudioManager.prototype.__onAudioPlayerPosition = function (audioPlayer, position, duration) {\n var track = audioPlayer.getTrack();\n if (track === this.__currentTrack) {\n this._trigger('position', track, position, duration);\n }\n };\n return AudioManager;\n}(Base_1.Base));\nexports.AudioManager = AudioManager;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./lib/audio/AudioManager.ts\n// module id = 9\n// module chunks = 0","\"use strict\";\nvar HTMLPlayer_1 = require(\"./HTMLPlayer\");\nvar Factory = (function () {\n function Factory() {\n }\n Factory.makeFromTrack = function (track, clock) {\n return new HTMLPlayer_1.HTMLPlayer(track, clock);\n };\n return Factory;\n}());\nexports.Factory = Factory;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./lib/audio/Factory.ts\n// module id = 10\n// module chunks = 0","\"use strict\";\nvar __extends = (this && this.__extends) || function (d, b) {\n for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n};\nvar Base_1 = require(\"../Base\");\nvar FADE_OUT_INTERVAL = 25;\nvar HTMLPlayer = (function (_super) {\n __extends(HTMLPlayer, _super);\n function HTMLPlayer(track, clock) {\n var _this = _super.call(this) || this;\n _this.__started = false;\n _this.__cueInTimeoutId = 0;\n _this.__restartTimeoutId = 0;\n _this.__positionIntervalId = 0;\n _this.__volume = 1.0;\n _this.__fadeVolumeMultiplier = 1.0;\n _this.__fadeIntervalId = 0;\n _this.__track = track;\n _this.__clock = clock;\n return _this;\n }\n HTMLPlayer.prototype.start = function () {\n if (!this.__started) {\n this.debug('Starting');\n this.__started = true;\n this.__preparePlayback();\n }\n else {\n throw new Error('Attempt to start HTML Player that is already started');\n }\n return this;\n };\n HTMLPlayer.prototype.stop = function () {\n if (this.__started) {\n this.debug('Stopping');\n this.__stopPlayback();\n this.__started = false;\n }\n else {\n throw new Error('Attempt to stop HTML Player that is not started');\n }\n return this;\n };\n HTMLPlayer.prototype.setVolume = function (volume) {\n if (volume < 0.0 || volume > 1.0) {\n throw new Error('Volume out of range');\n }\n this.__volume = volume;\n if (this.__audio) {\n this.__audio.volume = volume * this.__fadeVolumeMultiplier;\n }\n return this;\n };\n HTMLPlayer.prototype.getTrack = function () {\n return this.__track;\n };\n HTMLPlayer.prototype.fadeOut = function (duration) {\n var _this = this;\n if (this.__fadeIntervalId === 0) {\n this.debug(\"Starting fade out of duration \" + duration + \" ms\");\n var step_1 = FADE_OUT_INTERVAL / duration;\n this.__fadeIntervalId = setInterval(function () {\n _this.__fadeVolumeMultiplier -= step_1;\n if (_this.__fadeVolumeMultiplier <= 0) {\n _this.__fadeVolumeMultiplier = 0;\n clearInterval(_this.__fadeIntervalId);\n _this.__fadeIntervalId = 0;\n _this.debug(\"Finishing fade out\");\n }\n _this.debug(\"Fade out: \" + _this.__fadeVolumeMultiplier + \"%\");\n if (_this.__audio) {\n _this.__audio.volume = _this.__volume * _this.__fadeVolumeMultiplier;\n }\n }, FADE_OUT_INTERVAL);\n }\n return this;\n };\n HTMLPlayer.prototype._loggerTag = function () {\n return this['constructor']['name'] + \" \" + this.__track.getId();\n };\n HTMLPlayer.prototype.__onAudioCanPlayThroughWhenPreparing = function (e) {\n this.debug('Can play through (when preparing)');\n var now = this.__clock.nowAsTimestamp();\n var cueInAt = this.__track.getCueInAt().valueOf();\n var cueOutAt = this.__track.getCueOutAt().valueOf();\n if (now >= cueOutAt) {\n this.warn('Unable to play: Track is obsolete');\n }\n else {\n if (now < cueInAt) {\n var timeout = cueInAt - now;\n this.debug(\"Waiting for \" + timeout + \" ms\");\n this.__cueInTimeoutId = setTimeout(this.__onCueInTimeout.bind(this), timeout);\n }\n else if (now > cueInAt) {\n this.__audio.oncanplaythrough = this.__onAudioCanPlayThroughWhenReady.bind(this);\n var position = now - cueInAt;\n this.debug(\"Seeking to \" + position + \" ms\");\n this.__audio.currentTime = position / 1000.0;\n }\n else {\n this.__startPlayback();\n }\n }\n };\n HTMLPlayer.prototype.__onAudioCanPlayThroughWhenReady = function (e) {\n this.debug('Can play through (when ready)');\n this.__startPlayback();\n };\n HTMLPlayer.prototype.__onAudioError = function (e) {\n this.warn('Error');\n this.__stopPlayback();\n this.__scheduleRestart();\n };\n HTMLPlayer.prototype.__onAudioEnded = function (e) {\n this.debug('EOS');\n this.__stopPlayback();\n };\n HTMLPlayer.prototype.__onAudioSeeking = function (e) {\n this.debug('Seeking');\n };\n HTMLPlayer.prototype.__onAudioSeeked = function (e) {\n this.debug('Seeked');\n };\n HTMLPlayer.prototype.__onAudioWaiting = function (e) {\n this.warn('Waiting');\n };\n HTMLPlayer.prototype.__onAudioStalled = function (e) {\n this.warn('Stalled');\n };\n HTMLPlayer.prototype.__onAudioSuspended = function (e) {\n this.warn('Suspended');\n };\n HTMLPlayer.prototype.__onCueInTimeout = function () {\n this.debug('Cue In timeout has passed');\n this.__cueInTimeoutId = 0;\n this.__startPlayback();\n };\n HTMLPlayer.prototype.__preparePlayback = function () {\n this.debug('Preparing playback');\n this.__fadeVolumeMultiplier = 1.0;\n this.__audio = new Audio();\n this.__audio.volume = this.__volume;\n this.__audio.preload = 'none';\n this.__audio.src = this.__track.getFileUrl();\n var now = this.__clock.nowAsTimestamp();\n var cueInAt = this.__track.getCueInAt().valueOf();\n var cueOutAt = this.__track.getCueOutAt().valueOf();\n if (now >= cueOutAt) {\n this.warn('Unable to set initial currentTime: Track is obsolete');\n }\n else {\n if (now <= cueInAt) {\n this.__audio.currentTime = 0;\n }\n else {\n var position = now - cueInAt;\n this.debug(\"Setting initial currentTime to \" + position + \" ms\");\n this.__audio.onseeking = this.__onAudioSeeking.bind(this);\n this.__audio.onseeked = this.__onAudioSeeked.bind(this);\n this.__audio.currentTime = position / 1000.0;\n }\n }\n this.__audio.oncanplaythrough = this.__onAudioCanPlayThroughWhenPreparing.bind(this);\n this.__audio.onerror = this.__onAudioError.bind(this);\n this.__audio.load();\n };\n HTMLPlayer.prototype.__startPlayback = function () {\n this.debug('Starting playback');\n this.__positionIntervalId = setInterval(this.__onPositionInterval.bind(this), 250);\n this.__audio.onwaiting = this.__onAudioWaiting.bind(this);\n this.__audio.onstalled = this.__onAudioStalled.bind(this);\n this.__audio.onsuspend = this.__onAudioSuspended.bind(this);\n this.__audio.onended = this.__onAudioEnded.bind(this);\n this.__audio.play();\n this._trigger('playback-started', this);\n };\n HTMLPlayer.prototype.__stopPlayback = function () {\n this.debug('Stopping playback');\n if (this.__audio) {\n this.__audio.oncanplaythrough = undefined;\n this.__audio.onerror = undefined;\n this.__audio.onended = undefined;\n this.__audio.onwaiting = undefined;\n this.__audio.onstalled = undefined;\n this.__audio.onsuspend = undefined;\n this.__audio.onseeking = undefined;\n this.__audio.onseeked = undefined;\n if (this.__audio.readyState == 4) {\n this.__audio.pause();\n }\n this.__audio.src = '';\n delete this.__audio;\n this.__audio = undefined;\n }\n if (this.__fadeIntervalId !== 0) {\n clearInterval(this.__fadeIntervalId);\n this.__fadeIntervalId = 0;\n }\n if (this.__cueInTimeoutId !== 0) {\n clearTimeout(this.__cueInTimeoutId);\n this.__cueInTimeoutId = 0;\n }\n if (this.__restartTimeoutId !== 0) {\n clearTimeout(this.__restartTimeoutId);\n this.__restartTimeoutId = 0;\n }\n if (this.__positionIntervalId !== 0) {\n clearInterval(this.__positionIntervalId);\n this.__positionIntervalId = 0;\n }\n };\n HTMLPlayer.prototype.__scheduleRestart = function () {\n var _this = this;\n if (this.__started) {\n var timeout = 500 + Math.round(Math.random() * 250);\n this.debug(\"Scheduling restart in \" + timeout + \" ms\");\n this.__restartTimeoutId = setTimeout(function () {\n _this.__restartTimeoutId = 0;\n _this.__preparePlayback();\n }, timeout);\n }\n };\n HTMLPlayer.prototype.__onPositionInterval = function () {\n if (this.__audio) {\n var position = Math.round(this.__audio.currentTime * 1000);\n var cueInAt = this.__track.getCueInAt().valueOf();\n var cueOutAt = this.__track.getCueOutAt().valueOf();\n var duration = cueOutAt - cueInAt;\n this._trigger('position', this, position, duration);\n }\n };\n return HTMLPlayer;\n}(Base_1.Base));\nexports.HTMLPlayer = HTMLPlayer;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./lib/audio/HTMLPlayer.ts\n// module id = 11\n// module chunks = 0","\"use strict\";\nvar __extends = (this && this.__extends) || function (d, b) {\n for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n};\nvar Base_1 = require(\"../Base\");\nvar StreamManager = (function (_super) {\n __extends(StreamManager, _super);\n function StreamManager(channelId) {\n var _this = _super.call(this) || this;\n _this.__volume = 1.0;\n _this.__started = false;\n _this.__restartTimeoutId = 0;\n _this.__channelId = channelId;\n return _this;\n }\n StreamManager.prototype.start = function () {\n if (!this.__started) {\n this.debug('Starting');\n this.__started = true;\n this.__startPlayback();\n }\n else {\n throw new Error('Attempt to start Stream Manager that is already started');\n }\n return this;\n };\n StreamManager.prototype.stop = function () {\n if (this.__started) {\n this.debug('Stopping');\n this.__stopPlayback();\n this.__started = false;\n }\n else {\n throw new Error('Attempt to stop Stream Manager that is not started');\n }\n return this;\n };\n StreamManager.prototype.setVolume = function (volume) {\n if (volume < 0.0 || volume > 1.0) {\n throw new Error('Volume out of range');\n }\n this.__volume = volume;\n if (this.__audio) {\n this.__audio.volume = volume;\n }\n return this;\n };\n StreamManager.prototype._loggerTag = function () {\n return \"\" + this['constructor']['name'];\n };\n StreamManager.prototype.__onAudioError = function (e) {\n this.warn('Error');\n this.__stopPlayback();\n this.__scheduleRestart();\n };\n StreamManager.prototype.__onAudioEnded = function (e) {\n this.debug('EOS');\n this.__stopPlayback();\n this.__scheduleRestart();\n };\n StreamManager.prototype.__onAudioWaiting = function (e) {\n this.warn('Waiting');\n };\n StreamManager.prototype.__onAudioStalled = function (e) {\n this.warn('Stalled');\n };\n StreamManager.prototype.__onAudioSuspended = function (e) {\n this.warn('Suspended');\n };\n StreamManager.prototype.__startPlayback = function () {\n this.debug('Starting playback');\n this.__audio = new Audio();\n this.__audio.volume = this.__volume;\n this.__audio.src = \"http://cluster.radiokitstream.org/\" + this.__channelId + \".mp3\";\n this.__audio.onerror = this.__onAudioError.bind(this);\n this.__audio.onended = this.__onAudioEnded.bind(this);\n this.__audio.onwaiting = this.__onAudioWaiting.bind(this);\n this.__audio.onstalled = this.__onAudioStalled.bind(this);\n this.__audio.onsuspend = this.__onAudioSuspended.bind(this);\n this.__audio.play();\n this._trigger('playback-started');\n };\n StreamManager.prototype.__stopPlayback = function () {\n this.debug('Stopping playback');\n if (this.__audio) {\n this.__audio.onerror = undefined;\n this.__audio.onended = undefined;\n this.__audio.onwaiting = undefined;\n this.__audio.onstalled = undefined;\n this.__audio.onsuspend = undefined;\n if (this.__audio.readyState == 4) {\n this.__audio.pause();\n }\n this.__audio.src = '';\n delete this.__audio;\n this.__audio = undefined;\n }\n if (this.__restartTimeoutId !== 0) {\n clearTimeout(this.__restartTimeoutId);\n this.__restartTimeoutId = 0;\n }\n };\n StreamManager.prototype.__scheduleRestart = function () {\n var _this = this;\n if (this.__started) {\n var timeout = 500 + Math.round(Math.random() * 250);\n this.debug(\"Scheduling restart in \" + timeout + \" ms\");\n this.__restartTimeoutId = setTimeout(function () {\n _this.__restartTimeoutId = 0;\n _this.__startPlayback();\n }, timeout);\n }\n };\n return StreamManager;\n}(Base_1.Base));\nexports.StreamManager = StreamManager;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./lib/audio/StreamManager.ts\n// module id = 12\n// module chunks = 0"],"sourceRoot":""}