Skip to content

Commit

Permalink
fix debounce again
Browse files Browse the repository at this point in the history
  • Loading branch information
adrums86 committed Dec 12, 2023
1 parent 3110c57 commit e222665
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {merge, createTimeRanges} from './util/vjs-compat';
import { addMetadata, createMetadataTrackIfNotExists, addDateRangeMetadata } from './util/text-tracks';
import ContentSteeringController from './content-steering-controller';
import { bufferToHexString } from './util/string.js';
import { debounce } from 'lodash';

const ABORT_EARLY_EXCLUSION_SECONDS = 10;

Expand Down Expand Up @@ -2444,12 +2443,21 @@ export class PlaylistController extends videojs.EventTarget {
*/
updatePlaylistByKeyStatus(keyId, status) {
this.addKeyStatus_(keyId, status);

Check warning on line 2445 in src/playlist-controller.js

View check run for this annotation

Codecov / codecov/patch

src/playlist-controller.js#L2444-L2445

Added lines #L2444 - L2445 were not covered by tests

// this gets called a LOT. Unless we want to change contrib-eme we should debounce here.
const ONE_SECOND = 1000;
const debouncePlaylistUpdate = (fn) => {

Check warning on line 2449 in src/playlist-controller.js

View check run for this annotation

Codecov / codecov/patch

src/playlist-controller.js#L2448-L2449

Added lines #L2448 - L2449 were not covered by tests
let timeoutId;

debounce(() => {
return () => {
clearTimeout(timeoutId);
timeoutId = setTimeout(fn.apply(this), ONE_SECOND);

Check warning on line 2454 in src/playlist-controller.js

View check run for this annotation

Codecov / codecov/patch

src/playlist-controller.js#L2452-L2454

Added lines #L2452 - L2454 were not covered by tests
};
};

debouncePlaylistUpdate(() => {
this.excludeNonUsablePlaylistsByKeyId_();
this.fastQualityChange_();

Check warning on line 2460 in src/playlist-controller.js

View check run for this annotation

Codecov / codecov/patch

src/playlist-controller.js#L2458-L2460

Added lines #L2458 - L2460 were not covered by tests
}, ONE_SECOND);
});
}
}

0 comments on commit e222665

Please sign in to comment.