Source: lib/offline/indexeddb/eme_session_storage_cell.js

  1. /*! @license
  2. * Shaka Player
  3. * Copyright 2016 Google LLC
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. goog.provide('shaka.offline.indexeddb.EmeSessionStorageCell');
  7. goog.require('shaka.offline.indexeddb.DBConnection');
  8. goog.requireType('shaka.offline.indexeddb.DBOperation');
  9. /**
  10. * The implementation of the EME session storage cell.
  11. *
  12. * @implements {shaka.extern.EmeSessionStorageCell}
  13. */
  14. shaka.offline.indexeddb.EmeSessionStorageCell = class {
  15. /**
  16. * @param {IDBDatabase} connection
  17. * @param {string} store
  18. */
  19. constructor(connection, store) {
  20. /** @private {!shaka.offline.indexeddb.DBConnection} */
  21. this.connection_ = new shaka.offline.indexeddb.DBConnection(connection);
  22. /** @private {string} */
  23. this.store_ = store;
  24. }
  25. /** @override */
  26. destroy() { return this.connection_.destroy(); }
  27. /** @override */
  28. async getAll() {
  29. /** @type {!shaka.offline.indexeddb.DBOperation} */
  30. const op = this.connection_.startReadOnlyOperation(this.store_);
  31. /** @type {!Array<shaka.extern.EmeSessionDB>} */
  32. const values = [];
  33. await op.forEachEntry((key, value) => {
  34. values.push(value);
  35. });
  36. await op.promise();
  37. return values;
  38. }
  39. /** @override */
  40. add(sessions) {
  41. const op = this.connection_.startReadWriteOperation(this.store_);
  42. const store = op.store();
  43. for (const session of sessions) {
  44. store.add(session);
  45. }
  46. return op.promise();
  47. }
  48. /** @override */
  49. async remove(sessionIds) {
  50. /** @type {!shaka.offline.indexeddb.DBOperation} */
  51. const op = this.connection_.startReadWriteOperation(this.store_);
  52. await op.forEachEntry((key, value, cursor) => {
  53. if (sessionIds.includes(value.sessionId)) {
  54. cursor.delete();
  55. }
  56. });
  57. await op.promise();
  58. }
  59. };