From e222665a9552c6348d59fcdcd892ab5cfc366a90 Mon Sep 17 00:00:00 2001 From: Adam Waldron Date: Tue, 12 Dec 2023 00:08:08 -0800 Subject: [PATCH] fix debounce again --- src/playlist-controller.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/playlist-controller.js b/src/playlist-controller.js index 582d6f509..a2719b452 100644 --- a/src/playlist-controller.js +++ b/src/playlist-controller.js @@ -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; @@ -2444,12 +2443,21 @@ export class PlaylistController extends videojs.EventTarget { */ updatePlaylistByKeyStatus(keyId, status) { this.addKeyStatus_(keyId, status); + // this gets called a LOT. Unless we want to change contrib-eme we should debounce here. const ONE_SECOND = 1000; + const debouncePlaylistUpdate = (fn) => { + let timeoutId; - debounce(() => { + return () => { + clearTimeout(timeoutId); + timeoutId = setTimeout(fn.apply(this), ONE_SECOND); + }; + }; + + debouncePlaylistUpdate(() => { this.excludeNonUsablePlaylistsByKeyId_(); this.fastQualityChange_(); - }, ONE_SECOND); + }); } }