Files
shaka-player/lib/offline/offline_manifest_parser.js
T
Joey Parrish 562a2d567b chore: Strictly require jsdoc
This enables the eslint rule requiring jsdocs on all class
declarations, function declarations, and methods.

Unfortunately, there are two problems with this:

1. We don't use class _declarations_, we use class _expressions_,
which are not covered by this rule.  So it does not enforce jsdoc at
the class level.
2. We tend to document a class at the class-level, rather than at the
constructor.  But a constructor counts as a method for eslint, so it
requires docs on the constructor.  There is no way to configure it to
make an exception for trivial constructors.

So for all trivial (no-argument) constructors, we add empty jsdocs:
  /** */
  constructor() {

This was quicker and easier than setting up some alternative plugin in
eslint to make an exception for us.

The good news is that this rule caught several undocumented parameters
and places where the jsdoc comment was malformed.  So fixing those
also improves the compiler's ability to enforce types.

Change-Id: Icbc46ed690c94e53d354648a883119524f8fca45
2021-01-09 02:00:31 +00:00

121 lines
3.1 KiB
JavaScript

/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
goog.provide('shaka.offline.OfflineManifestParser');
goog.require('goog.asserts');
goog.require('shaka.log');
goog.require('shaka.media.ManifestParser');
goog.require('shaka.offline.ManifestConverter');
goog.require('shaka.offline.OfflineUri');
goog.require('shaka.offline.StorageMuxer');
goog.require('shaka.util.Error');
/**
* @summary Creates a new offline manifest parser.
* @implements {shaka.extern.ManifestParser}
*/
shaka.offline.OfflineManifestParser = class {
/** */
constructor() {
/** @private {shaka.offline.OfflineUri} */
this.uri_ = null;
}
/** @override */
configure(config) {
// No-op
}
/** @override */
async start(uriString, playerInterface) {
/** @type {shaka.offline.OfflineUri} */
const uri = shaka.offline.OfflineUri.parse(uriString);
this.uri_ = uri;
if (uri == null || !uri.isManifest()) {
throw new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
shaka.util.Error.Category.NETWORK,
shaka.util.Error.Code.MALFORMED_OFFLINE_URI,
uriString);
}
/** @type {!shaka.offline.StorageMuxer} */
const muxer = new shaka.offline.StorageMuxer();
try {
await muxer.init();
const cell = await muxer.getCell(uri.mechanism(), uri.cell());
const manifests = await cell.getManifests([uri.key()]);
const manifest = manifests[0];
const converter = new shaka.offline.ManifestConverter(
uri.mechanism(), uri.cell());
const finalManifest = converter.fromManifestDB(manifest);
playerInterface.makeTextStreamsForClosedCaptions(finalManifest);
return finalManifest;
} finally {
await muxer.destroy();
}
}
/** @override */
stop() {
return Promise.resolve();
}
/** @override */
update() {
// No-op
}
/** @override */
async onExpirationUpdated(sessionId, expiration) {
goog.asserts.assert(
this.uri_,
'Should not get update event before start has been called');
/** @type {!shaka.offline.OfflineUri} */
const uri = this.uri_;
/** @type {!shaka.offline.StorageMuxer} */
const muxer = new shaka.offline.StorageMuxer();
try {
await muxer.init();
const cell = await muxer.getCell(uri.mechanism(), uri.cell());
const manifests = await cell.getManifests([uri.key()]);
const manifest = manifests[0];
const foundSession = manifest.sessionIds.includes(sessionId);
const newExpiration = manifest.expiration == undefined ||
manifest.expiration > expiration;
if (foundSession && newExpiration) {
shaka.log.debug('Updating expiration for stored content');
await cell.updateManifestExpiration(uri.key(), expiration);
}
} catch (e) {
// Ignore errors with update.
shaka.log.error('There was an error updating', uri, e);
} finally {
await muxer.destroy();
}
}
};
shaka.media.ManifestParser.registerParserByMime(
'application/x-offline-manifest',
() => new shaka.offline.OfflineManifestParser());