From f136aa0a5e038678aca10307676a2e44d197f197 Mon Sep 17 00:00:00 2001 From: Ahmed Saber Date: Sat, 15 Jul 2023 02:42:18 +0300 Subject: [PATCH 1/7] Refactor ANDROID_VERSION in utils/browser.js --- src/js/utils/browser.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/js/utils/browser.js b/src/js/utils/browser.js index 384517fb53..cdd41692f0 100644 --- a/src/js/utils/browser.js +++ b/src/js/utils/browser.js @@ -199,8 +199,9 @@ if (!IS_CHROMIUM) { const minor = match[2] && parseFloat(match[2]); if (major && minor) { - return parseFloat(match[1] + '.' + match[2]); - } else if (major) { + return parseFloat(`${match[1]}.${match[2]}`); + } + if (major) { return major; } return null; From 9ed2e0a524797116049a4a7d2dd2c83f8996456c Mon Sep 17 00:00:00 2001 From: Ahmed Saber Date: Sat, 15 Jul 2023 02:44:57 +0300 Subject: [PATCH 2/7] Refactor bufferedPercent in utils/buffer.js --- src/js/utils/buffer.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/js/utils/buffer.js b/src/js/utils/buffer.js index 8e5c18585f..4443b2f1db 100644 --- a/src/js/utils/buffer.js +++ b/src/js/utils/buffer.js @@ -18,8 +18,6 @@ import { createTimeRange } from './time.js'; */ export function bufferedPercent(buffered, duration) { let bufferedDuration = 0; - let start; - let end; if (!duration) { return 0; @@ -30,13 +28,11 @@ export function bufferedPercent(buffered, duration) { } for (let i = 0; i < buffered.length; i++) { - start = buffered.start(i); - end = buffered.end(i); + const start = buffered.start(i); + const end = buffered.end(i); // buffered end can be bigger than duration by a very small fraction - if (end > duration) { - end = duration; - } + end = Math.min(end, duration); bufferedDuration += end - start; } From df64c8a3eed66ba5207aeee8c4e09e64fa8e4957 Mon Sep 17 00:00:00 2001 From: Ahmed Saber Date: Sat, 15 Jul 2023 02:52:28 +0300 Subject: [PATCH 3/7] Refactor on function in utils/events.js --- src/js/utils/events.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/js/utils/events.js b/src/js/utils/events.js index 4945c236b0..0f36720b1d 100644 --- a/src/js/utils/events.js +++ b/src/js/utils/events.js @@ -305,12 +305,11 @@ export function on(elem, type, fn) { for (let m = 0, n = handlersCopy.length; m < n; m++) { if (event.isImmediatePropagationStopped()) { break; - } else { - try { - handlersCopy[m].call(elem, event, hash); - } catch (e) { - log.error(e); - } + } + try { + handlersCopy[m].call(elem, event, hash); + } catch (e) { + log.error(e); } } } From 4c938e07e9f9e6648d42a57e845513e4364b973c Mon Sep 17 00:00:00 2001 From: Ahmed Saber Date: Sat, 15 Jul 2023 02:55:21 +0300 Subject: [PATCH 4/7] Refactor filterSource in utils/filter-source.js --- src/js/utils/filter-source.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/js/utils/filter-source.js b/src/js/utils/filter-source.js index 7cfe021206..f78ca2329b 100644 --- a/src/js/utils/filter-source.js +++ b/src/js/utils/filter-source.js @@ -32,19 +32,16 @@ const filterSource = function(src) { } }); - src = newsrc; - } else if (typeof src === 'string' && src.trim()) { + return newsrc; + } if (typeof src === 'string' && src.trim()) { // convert string into object - src = [fixSource({src})]; - } else if (isObject(src) && typeof src.src === 'string' && src.src && src.src.trim()) { + return [fixSource({src})]; + } if (isObject(src) && typeof src.src === 'string' && src.src && src.src.trim()) { // src is already valid - src = [fixSource(src)]; - } else { - // invalid source, turn it into an empty array - src = []; + return [fixSource(src)]; } - - return src; + // invalid source, turn it into an empty array + return []; }; /** From dee5402aa5f9ae05409c49e0a54e3f04f8ca31da Mon Sep 17 00:00:00 2001 From: Ahmed Saber Date: Sat, 15 Jul 2023 03:04:41 +0300 Subject: [PATCH 5/7] Refactor throttle in utils/fn.js --- src/js/utils/fn.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/js/utils/fn.js b/src/js/utils/fn.js index cf7ba35ed4..df5ccc4760 100644 --- a/src/js/utils/fn.js +++ b/src/js/utils/fn.js @@ -60,19 +60,15 @@ export const bind_ = function(context, fn, uid) { * * @return {Function} */ -export const throttle = function(fn, wait) { - let last = window.performance.now(); - - const throttled = function(...args) { - const now = window.performance.now(); - - if (now - last >= wait) { - fn(...args); - last = now; - } +export const throttle = function(func, delay) { + let lastCallTime = 0; + return function throttled(...args) { + const currentTime = Date.now() + if (currentTime - lastCallTime >= delay) { + lastCallTime = currentTime; + func(...args); + } }; - - return throttled; }; /** From 4610a2f520aa85b653be8383ce54f1d3f581683a Mon Sep 17 00:00:00 2001 From: Ahmed Saber Date: Sat, 15 Jul 2023 03:07:19 +0300 Subject: [PATCH 6/7] Refactor createTimeRanges in utils/time.js --- src/js/utils/time.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/utils/time.js b/src/js/utils/time.js index 408bea08fb..b6f7c44477 100644 --- a/src/js/utils/time.js +++ b/src/js/utils/time.js @@ -141,7 +141,7 @@ function createTimeRangesObj(ranges) { export function createTimeRanges(start, end) { if (Array.isArray(start)) { return createTimeRangesObj(start); - } else if (start === undefined || end === undefined) { + } if (start === undefined || end === undefined) { return createTimeRangesObj(); } return createTimeRangesObj([[start, end]]); From 9d71e8abab4a1256683831831b0907c15f6c892e Mon Sep 17 00:00:00 2001 From: Ahmed Saber Date: Fri, 11 Aug 2023 16:04:06 +0300 Subject: [PATCH 7/7] Fix issue related to reassigning value to constant --- src/js/utils/buffer.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/js/utils/buffer.js b/src/js/utils/buffer.js index 4443b2f1db..c03c775fab 100644 --- a/src/js/utils/buffer.js +++ b/src/js/utils/buffer.js @@ -29,10 +29,8 @@ export function bufferedPercent(buffered, duration) { for (let i = 0; i < buffered.length; i++) { const start = buffered.start(i); - const end = buffered.end(i); - // buffered end can be bigger than duration by a very small fraction - end = Math.min(end, duration); + const end = Math.min(buffered.end(i), duration); bufferedDuration += end - start; }