Class: shaka.offline.Storage

This manages persistent offline data including storage, listing, and deleting stored manifests. Playback of offline manifests are done through the Player using a special URI (see shaka.offline.OfflineUri). First, check support() to see if offline is supported by the platform. Second, configure() the storage object with callbacks to your application. Third, call store(), remove(), or list() as needed. When done, call destroy().

Constructor

new Storage(playeropt, non-null)

This manages persistent offline data including storage, listing, and deleting stored manifests. Playback of offline manifests are done through the Player using a special URI (see shaka.offline.OfflineUri). First, check support() to see if offline is supported by the platform. Second, configure() the storage object with callbacks to your application. Third, call store(), remove(), or list() as needed. When done, call destroy().

Parameters:
Name Type Attributes Description
player shaka.Player <optional>
A player instance to share a networking engine and configuration with. When initializing with a player, storage is only valid as long as |destroy| has not been called on the player instance. When omitted, storage will manage its own networking engine and configuration.
Implements:
Source:

Members

openDownloadManagers_ :Array.<!shaka.offline.DownloadManager>

A list of open download managers that are being used to download things.
Type:
Source:

openOperations_ :Array.<!Promise>

A list of open operations that are being performed by this instance of |shaka.offline.Storage|.
Type:
  • Array.<!Promise>
Source:

segmentsFromStore_ :Array.<number>

A list of segment ids for all the segments that were added during the current store. If the store fails or is aborted, these need to be removed from storage.
Type:
  • Array.<number>
Source:

Methods

deleteAll() → {Promise}

Delete the on-disk storage and all the content it contains. This should not be done in normal circumstances. Only do it when storage is rendered unusable, such as by a version mismatch. No business logic will be run, and licenses will not be released.
Source:
Returns:
Type
Promise

deleteLicenseFor_(netnon-null, drmConfignon-null, muxernon-null, manifestDb) → {Promise}

Parameters:
Name Type Description
net shaka.net.NetworkingEngine
drmConfig shaka.extern.DrmConfiguration
muxer shaka.offline.StorageMuxer
manifestDb shaka.extern.ManifestDB
Source:
Returns:
Type
Promise

forEachSegment_(stream, startTime, callback)

Parameters:
Name Type Description
stream shaka.extern.Stream
startTime number
callback function(!shaka.media.SegmentReference)
Source:

getAllSegmentIds_(manifest) → {Array.<number>}

Parameters:
Name Type Description
manifest shaka.extern.ManifestDB
Source:
Returns:
Type
Array.<number>

getAllStreamsFromManifest_(manifest) → {Set.<shaka.extern.Stream>}

Get the set of all streams in |manifest|.
Parameters:
Name Type Description
manifest shaka.extern.Manifest
Source:
Returns:
Type
Set.<shaka.extern.Stream>

getCapabilities_(manifestDb, isVideo) → {Array.<MediaKeySystemMediaCapability>}

Parameters:
Name Type Description
manifestDb shaka.extern.ManifestDB
isVideo boolean
Source:
Returns:
Type
Array.<MediaKeySystemMediaCapability>

support() → {boolean}

Gets whether offline storage is supported. Returns true if offline storage is supported for clear content. Support for offline storage of encrypted content will not be determined until storage is attempted.
Source:
Returns:
Type
boolean

validateManifest_(manifest)

Go over a manifest and issue warnings for any suspicious properties.
Parameters:
Name Type Description
manifest shaka.extern.Manifest
Source:

configure(config, valueopt) → {boolean}

Sets configuration values for Storage. This is associated with Player.configure and will change the player instance given at initialization.
Parameters:
Name Type Attributes Description
config string | Object This should either be a field name or an object following the form of shaka.extern.PlayerConfiguration, where you may omit any field you do not wish to change.
value * <optional>
This should be provided if the previous parameter was a string field name.
Source:
Returns:
Type
boolean

createDrmEngine(manifest, onError, config) → {Promise.<!shaka.media.DrmEngine>}

This method is public so that it can be override in testing.
Parameters:
Name Type Description
manifest shaka.extern.Manifest
onError function(shaka.util.Error)
config shaka.extern.PlayerConfiguration
Source:
Returns:
Type
Promise.<!shaka.media.DrmEngine>

createOfflineManifest_(downloadernon-null, storage, drmEnginenon-null, manifest, originalManifestUri, metadatanon-null, config) → {shaka.extern.ManifestDB}

Creates an offline 'manifest' for the real manifest. This does not store the segments yet, only adds them to the download manager through createStreams_.
Parameters:
Name Type Description
downloader shaka.offline.DownloadManager
storage shaka.extern.StorageCell
drmEngine shaka.media.DrmEngine
manifest shaka.extern.Manifest
originalManifestUri string
metadata Object
config shaka.extern.PlayerConfiguration
Source:
Returns:
Type
shaka.extern.ManifestDB

createStream_(downloadernon-null, storage, estimator, manifest, stream, config, initSegmentDbKeyCachenon-null, segmentDbKeyCachenon-null) → {shaka.extern.StreamDB}

Converts a manifest stream to a database stream. This will search the segment index and add all the segments to the download manager.
Parameters:
Name Type Description
downloader shaka.offline.DownloadManager
storage shaka.extern.StorageCell
estimator shaka.offline.StreamBandwidthEstimator
manifest shaka.extern.Manifest
stream shaka.extern.Stream
config shaka.extern.PlayerConfiguration
initSegmentDbKeyCache Map.<shaka.media.InitSegmentReference, !Promise.<?number>>
segmentDbKeyCache Map.<string, !Promise.<number>>
Source:
Returns:
Type
shaka.extern.StreamDB

createStreams_(downloadernon-null, storage, estimator, drmEnginenon-null, manifest, config) → {Array.<shaka.extern.StreamDB>}

Converts manifest Streams to database Streams. This will use the current configuration to get the tracks to use, then it will search each segment index and add all the segments to the download manager through createStream_.
Parameters:
Name Type Description
downloader shaka.offline.DownloadManager
storage shaka.extern.StorageCell
estimator shaka.offline.StreamBandwidthEstimator
drmEngine shaka.media.DrmEngine
manifest shaka.extern.Manifest
config shaka.extern.PlayerConfiguration
Source:
Returns:
Type
Array.<shaka.extern.StreamDB>

destroy() → {Promise}

Request that this object be destroyed, releasing all resources and shutting down all operations. Returns a Promise which is resolved when destruction is complete. This Promise should never be rejected.
Implements:
Source:
Returns:
Type
Promise

downloadManifest_(storage, drmEnginenon-null, manifest, uri, metadatanon-null, config, downloadernon-null) → {Promise.<shaka.extern.ManifestDB>}

Create a download manager and download the manifest.
Parameters:
Name Type Description
storage shaka.extern.StorageCell
drmEngine shaka.media.DrmEngine
manifest shaka.extern.Manifest
uri string
metadata Object
config shaka.extern.PlayerConfiguration
downloader shaka.offline.DownloadManager
Source:
Returns:
Type
Promise.<shaka.extern.ManifestDB>

ensureNotDestroyed_()

Throws an error if the object is destroyed.
Source:

filterManifest_(manifest, drmEnginenon-null, config) → {Promise}

Filter |manifest| such that it will only contain the variants and text streams that we want to store and can actually play.
Parameters:
Name Type Description
manifest shaka.extern.Manifest
drmEngine shaka.media.DrmEngine
config shaka.extern.PlayerConfiguration
Source:
Returns:
Type
Promise

getConfiguration() → {shaka.extern.PlayerConfiguration}

Return a copy of the current configuration. Modifications of the returned value will not affect the Storage instance's active configuration. You must call storage.configure() to make changes.
Source:
Returns:
Type
shaka.extern.PlayerConfiguration

getInitSegmentDbKey_(downloadernon-null, downloadGroup, streamId, storage, estimator, initSegmentReference, config, initSegmentDbKeyCachenon-null) → {Promise.<?number>}

Get a Promise to the DB key for a given init segment reference. The return values will be cached so that multiple calls with the same init segment reference will only trigger one request.
Parameters:
Name Type Description
downloader shaka.offline.DownloadManager
downloadGroup number
streamId number
storage shaka.extern.StorageCell
estimator shaka.offline.StreamBandwidthEstimator
initSegmentReference shaka.media.InitSegmentReference
config shaka.extern.PlayerConfiguration
initSegmentDbKeyCache Map.<shaka.media.InitSegmentReference, !Promise.<?number>>
Source:
Returns:
Type
Promise.<?number>

getNetworkingEngine() → {shaka.net.NetworkingEngine}

Return the networking engine that storage is using. If storage was initialized with a player instance, then the networking engine returned will be the same as |player.getNetworkingEngine()|. The returned value will only be null if |destroy| was called before |getNetworkingEngine|.
Source:
Returns:
Type
shaka.net.NetworkingEngine

getSegmentDbKey_(downloadernon-null, downloadGroup, streamId, storage, estimator, segmentReference, config, segmentDbKeyCachenon-null) → {Promise.<number>}

Get a Promise to the DB key for a given segment reference. The return values will be cached so that multiple calls with the same segment reference will only trigger one request.
Parameters:
Name Type Description
downloader shaka.offline.DownloadManager
downloadGroup number
streamId number
storage shaka.extern.StorageCell
estimator shaka.offline.StreamBandwidthEstimator
segmentReference shaka.media.SegmentReference
config shaka.extern.PlayerConfiguration
segmentDbKeyCache Map.<string, !Promise.<number>>
Source:
Returns:
Type
Promise.<number>

getStoreInProgress() → {boolean}

Returns true if an asset is currently downloading.
Deprecated:
  • Yes
Source:
Returns:
Type
boolean

list() → {Promise.<!Array.<shaka.extern.StoredContent>>}

Lists all the stored content available.
Source:
Returns:
A Promise to an array of structures representing all stored content. The "offlineUri" member of the structure is the URI that should be given to Player.load() to play this piece of content offline. The "appMetadata" member is the appMetadata argument you passed to store().
Type
Promise.<!Array.<shaka.extern.StoredContent>>

list_() → {Promise.<!Array.<shaka.extern.StoredContent>>}

See |shaka.offline.Storage.list| for details.
Source:
Returns:
Type
Promise.<!Array.<shaka.extern.StoredContent>>

parseManifest(uri, parser, config) → {Promise.<shaka.extern.Manifest>}

This method is public so that it can be overridden in testing.
Parameters:
Name Type Description
uri string
parser shaka.extern.ManifestParser
config shaka.extern.PlayerConfiguration
Source:
Returns:
Type
Promise.<shaka.extern.Manifest>

remove(contentUri) → {Promise}

Removes the given stored content. This will also attempt to release the licenses, if any.
Parameters:
Name Type Description
contentUri string
Source:
Returns:
Type
Promise

remove_(contentUri) → {Promise}

See |shaka.offline.Storage.remove| for details.
Parameters:
Name Type Description
contentUri string
Source:
Returns:
Type
Promise

removeEmeSessions() → {Promise.<boolean>}

Removes any EME sessions that were not successfully removed before. This returns whether all the sessions were successfully removed.
Source:
Returns:
Type
Promise.<boolean>

removeEmeSessions_() → {Promise.<boolean>}

Source:
Returns:
Type
Promise.<boolean>

removeFromDRM_(urinon-null, manifestDb, muxernon-null) → {Promise}

Parameters:
Name Type Description
uri shaka.offline.OfflineUri
manifestDb shaka.extern.ManifestDB
muxer shaka.offline.StorageMuxer
Source:
Returns:
Type
Promise

removeFromStorage_(storage, urinon-null, manifest) → {Promise}

Parameters:
Name Type Description
storage shaka.extern.StorageCell
uri shaka.offline.OfflineUri
manifest shaka.extern.ManifestDB
Source:
Returns:
Type
Promise

requireSupport_()

Used by functions that need storage support to ensure that the current platform has storage support before continuing. This should only be needed to be used at the start of public methods.
Source:

startAbortableOperation_(actionnon-null) → {shaka.extern.IAbortableOperation.<T>}

The equivalent of startOperation_, but for abortable operations.
Parameters:
Name Type Description
action shaka.extern.IAbortableOperation.<T>
Source:
Returns:
Type
shaka.extern.IAbortableOperation.<T>

startOperation_(actionnon-null) → {Promise.<T>}

Perform an action. Track the action's progress so that when we destroy we will wait until all the actions have completed before allowing destroy to resolve.
Parameters:
Name Type Description
action Promise.<T>
Source:
Returns:
Type
Promise.<T>

store(uri, appMetadataopt, non-null, mimeTypeopt) → {shaka.extern.IAbortableOperation.<shaka.extern.StoredContent>}

Stores the given manifest. If the content is encrypted, and encrypted content cannot be stored on this platform, the Promise will be rejected with error code 6001, REQUESTED_KEY_SYSTEM_CONFIG_UNAVAILABLE. Multiple assets can be downloaded at the same time, but note that since the storage instance has a single networking engine, multiple storage objects will be necessary if some assets require unique network filters. This snapshots the storage config at the time of the call, so it will not honor any changes to config mid-store operation.
Parameters:
Name Type Attributes Description
uri string The URI of the manifest to store.
appMetadata Object <optional>
An arbitrary object from the application that will be stored along-side the offline content. Use this for any application-specific metadata you need associated with the stored content. For details on the data types that can be stored here, please refer to https://bit.ly/StructClone
mimeType string <optional>
The mime type for the content |manifestUri| points to.
Source:
Returns:
An AbortableOperation that resolves with a structure representing what was stored. The "offlineUri" member is the URI that should be given to Player.load() to play this piece of content offline. The "appMetadata" member is the appMetadata argument you passed to store(). If you want to cancel this download, call the "abort" method on AbortableOperation.
Type
shaka.extern.IAbortableOperation.<shaka.extern.StoredContent>

store_(uri, appMetadatanon-null, getParser, config, downloadernon-null) → {Promise.<shaka.extern.StoredContent>}

See |shaka.offline.Storage.store| for details.
Parameters:
Name Type Description
uri string
appMetadata Object
getParser function(): !Promise.<shaka.extern.ManifestParser>
config shaka.extern.PlayerConfiguration
downloader shaka.offline.DownloadManager
Source:
Returns:
Type
Promise.<shaka.extern.StoredContent>