diff --git a/build/types/offline b/build/types/offline index bfd73118d9..a5ad070738 100644 --- a/build/types/offline +++ b/build/types/offline @@ -4,4 +4,5 @@ +../../lib/offline/download_manager.js +../../lib/offline/offline_manifest_parser.js +../../lib/offline/offline_scheme.js ++../../lib/offline/offline_utils.js +../../lib/offline/storage.js diff --git a/lib/offline/download_manager.js b/lib/offline/download_manager.js index 2db94bcf63..87e4c35341 100644 --- a/lib/offline/download_manager.js +++ b/lib/offline/download_manager.js @@ -19,6 +19,7 @@ goog.provide('shaka.offline.DownloadManager'); goog.require('goog.asserts'); goog.require('shaka.net.NetworkingEngine'); +goog.require('shaka.offline.OfflineUtils'); goog.require('shaka.util.Error'); goog.require('shaka.util.IDestroyable'); @@ -237,6 +238,6 @@ shaka.offline.DownloadManager.prototype.updateProgress_ = function() { (this.givenBytesTotal_ + this.bandwidthBytesTotal_); goog.asserts.assert(this.manifest_, 'Must not be destroyed'); - var manifest = shaka.offline.Storage.getStoredContent(this.manifest_); + var manifest = shaka.offline.OfflineUtils.getStoredContent(this.manifest_); this.config_.progressCallback(manifest, progress); }; diff --git a/lib/offline/offline_manifest_parser.js b/lib/offline/offline_manifest_parser.js index 5b6e628787..24e2ca2786 100644 --- a/lib/offline/offline_manifest_parser.js +++ b/lib/offline/offline_manifest_parser.js @@ -23,6 +23,7 @@ goog.require('shaka.media.PresentationTimeline'); goog.require('shaka.media.SegmentIndex'); goog.require('shaka.media.SegmentReference'); goog.require('shaka.offline.DBEngine'); +goog.require('shaka.offline.OfflineUtils'); goog.require('shaka.util.Error'); @@ -55,7 +56,7 @@ shaka.offline.OfflineManifestParser.prototype.start = var manifestId = Number(parts[1]); var dbEngine = new shaka.offline.DBEngine(); - return dbEngine.init(shaka.offline.Storage.DB_SCHEME) + return dbEngine.init(shaka.offline.OfflineUtils.DB_SCHEME) .then(function() { return dbEngine.get('manifest', manifestId); }) .then(function(manifest) { if (!manifest) { diff --git a/lib/offline/offline_scheme.js b/lib/offline/offline_scheme.js index e15a173a50..285add5061 100644 --- a/lib/offline/offline_scheme.js +++ b/lib/offline/offline_scheme.js @@ -19,6 +19,7 @@ goog.provide('shaka.offline.OfflineScheme'); goog.require('shaka.net.NetworkingEngine'); goog.require('shaka.offline.DBEngine'); +goog.require('shaka.offline.OfflineUtils'); goog.require('shaka.util.Error'); @@ -44,7 +45,7 @@ shaka.offline.OfflineScheme = function(uri, request) { var segmentParts = /^offline:[0-9]+\/[0-9]+\/([0-9]+)$/.exec(uri); if (segmentParts) { var segmentId = Number(segmentParts[1]); - var scheme = shaka.offline.Storage.DB_SCHEME; + var scheme = shaka.offline.OfflineUtils.DB_SCHEME; var dbEngine = new shaka.offline.DBEngine(); return dbEngine.init(scheme) .then(function() { return dbEngine.get('segment', segmentId); }) diff --git a/lib/offline/offline_utils.js b/lib/offline/offline_utils.js new file mode 100644 index 0000000000..d3cca49c25 --- /dev/null +++ b/lib/offline/offline_utils.js @@ -0,0 +1,56 @@ +/** + * @license + * Copyright 2016 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +goog.provide('shaka.offline.OfflineUtils'); + +goog.require('goog.asserts'); + + +/** @const {!Object.} */ +shaka.offline.OfflineUtils.DB_SCHEME = {'manifest': 'key', 'segment': 'key'}; + + +/** + * Converts the given database manifest to a storedContent structure. + * + * @param {shakaExtern.ManifestDB} manifest + * @return {shakaExtern.StoredContent} + */ +shaka.offline.OfflineUtils.getStoredContent = function(manifest) { + goog.asserts.assert(manifest.periods.length > 0, + 'Must be at least one Period.'); + return { + offlineUri: 'offline:' + manifest.key, + originalManifestUri: manifest.originalManifestUri, + duration: manifest.duration, + size: manifest.size, + tracks: manifest.periods[0].streams.map(function(stream) { + return { + id: stream.id, + active: false, + type: stream.contentType, + bandwidth: 0, + language: stream.language, + kind: stream.kind || null, + width: stream.width, + height: stream.height, + hasOutputRestrictions: false + }; + }), + appMetadata: manifest.appMetadata + }; +}; diff --git a/lib/offline/storage.js b/lib/offline/storage.js index 3517e4ee92..8e8f311674 100644 --- a/lib/offline/storage.js +++ b/lib/offline/storage.js @@ -24,6 +24,7 @@ goog.require('shaka.media.ManifestParser'); goog.require('shaka.offline.DBEngine'); goog.require('shaka.offline.DownloadManager'); goog.require('shaka.offline.OfflineManifestParser'); +goog.require('shaka.offline.OfflineUtils'); goog.require('shaka.util.ConfigUtils'); goog.require('shaka.util.Error'); goog.require('shaka.util.Functional'); @@ -91,10 +92,6 @@ shaka.offline.Storage = function(player) { }; -/** @const {!Object.} */ -shaka.offline.Storage.DB_SCHEME = {'manifest': 'key', 'segment': 'key'}; - - /** * Gets whether offline storage is supported. * @@ -106,38 +103,6 @@ shaka.offline.Storage.support = function() { }; -/** - * Converts the given database manifest to a storedContent structure. - * - * @param {shakaExtern.ManifestDB} manifest - * @return {shakaExtern.StoredContent} - */ -shaka.offline.Storage.getStoredContent = function(manifest) { - goog.asserts.assert(manifest.periods.length > 0, - 'Must be at least one Period.'); - return { - offlineUri: 'offline:' + manifest.key, - originalManifestUri: manifest.originalManifestUri, - duration: manifest.duration, - size: manifest.size, - tracks: manifest.periods[0].streams.map(function(stream) { - return { - id: stream.id, - active: false, - type: stream.contentType, - bandwidth: 0, - language: stream.language, - kind: stream.kind || null, - width: stream.width, - height: stream.height, - hasOutputRestrictions: false - }; - }), - appMetadata: manifest.appMetadata - }; -}; - - /** * Sets the DBEngine instance to use. This is used for testing. * @@ -252,7 +217,7 @@ shaka.offline.Storage.prototype.store = function( return this.cleanup_(); }.bind(this)) .then(function() { - return shaka.offline.Storage.getStoredContent(manifestDb); + return shaka.offline.OfflineUtils.getStoredContent(manifestDb); }.bind(this)) .catch(function(err) { var Functional = shaka.util.Functional; @@ -372,7 +337,7 @@ shaka.offline.Storage.prototype.list = function() { return this.dbEngine_.forEach( 'manifest', function(/** shakaExtern.ManifestDB */ manifest) { storedContents.push( - shaka.offline.Storage.getStoredContent(manifest)); + shaka.offline.OfflineUtils.getStoredContent(manifest)); }); }.bind(this)) .then(function() { return storedContents; }); @@ -532,7 +497,7 @@ shaka.offline.Storage.prototype.defaultConfig_ = function() { * @private */ shaka.offline.Storage.prototype.initIfNeeded_ = function() { - var scheme = shaka.offline.Storage.DB_SCHEME; + var scheme = shaka.offline.OfflineUtils.DB_SCHEME; return this.dbEngine_.initialized() ? Promise.resolve() : this.dbEngine_.init(scheme); }; diff --git a/test/offline_integration.js b/test/offline_integration.js index d35b710ee9..d6f21941dc 100644 --- a/test/offline_integration.js +++ b/test/offline_integration.js @@ -47,7 +47,7 @@ describe('Offline', function() { player = new shaka.Player(video); storage = new shaka.offline.Storage(player); dbEngine = new shaka.offline.DBEngine(); - dbEngine.init(shaka.offline.Storage.DB_SCHEME).catch(fail).then(done); + dbEngine.init(shaka.offline.OfflineUtils.DB_SCHEME).catch(fail).then(done); }); afterEach(function(done) { diff --git a/test/storage_unit.js b/test/storage_unit.js index 06b37f87ed..1c758fd494 100644 --- a/test/storage_unit.js +++ b/test/storage_unit.js @@ -39,7 +39,7 @@ describe('Storage', function() { storage = new shaka.offline.Storage(player); storage.setDbEngine(fakeDbEngine); - fakeDbEngine.init(shaka.offline.Storage.DB_SCHEME) + fakeDbEngine.init(shaka.offline.OfflineUtils.DB_SCHEME) .catch(fail) .then(done); });