Skip to content

Commit

Permalink
use array includes
Browse files Browse the repository at this point in the history
  • Loading branch information
SivanA-Kaltura committed Jun 6, 2024
1 parent b2e2d18 commit d0664d2
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/dash-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1563,17 +1563,18 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
}

public setCachedUrls(cachedUrls: string[]): void {
if (!Array.isArray(cachedUrls)) return;
const newUrls = new Set(cachedUrls);
const existingUrls = new Set(this.assetCache?.list());
for (const url of newUrls) {
if (!existingUrls.has(url)) {
this.assetCache?.add(url);
if (!Array.isArray(cachedUrls) || !this.assetCache) return;

const existingUrls = this.assetCache.list();

for (const url of cachedUrls) {
if (!existingUrls.includes(url)) {
this.assetCache.add(url);
}
}
for (const url of existingUrls) {
if (!newUrls.has(url)) {
this.assetCache?.remove(url, true);
if (!cachedUrls.includes(url)) {
this.assetCache.remove(url, true);
}
}
}
Expand Down

0 comments on commit d0664d2

Please sign in to comment.