From 151bdda36d60499f5cfdd4d5c6ebbe088025cd2a Mon Sep 17 00:00:00 2001 From: Rohan Gupta Date: Sat, 10 Dec 2022 14:47:14 +0530 Subject: [PATCH] fix(chapters): removed duplicate chapters by id (#4810) fixes https://github.com/shaka-project/shaka-player/issues/4750 Solved by creating a `Set` for filtering out deplicate elements. Need confirmation, Shouldn't we add an `assert` for `language` argument passed to https://github.com/shaka-project/shaka-player/blob/76f96b9fee2dc43b03f6803dd80c51fdc5b73a9e/lib/player.js#L4340-L4342 --- AUTHORS | 1 + CONTRIBUTORS | 1 + lib/player.js | 6 +++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 701a828f33..8ece9ded7e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -68,6 +68,7 @@ Prakash Robert Colantuoni Robert Galluccio Rodolphe Breton +Rohan Gupta Roi Lipman Roksolana Ivanyshyn Rostislav Hejduk diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 7e0989a110..ca741e91ff 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -100,6 +100,7 @@ Robert Colantuoni Robert Galluccio Rodolphe Breton Rohit Makasana +Rohan Gupta Roi Lipman Roksolana Ivanyshyn Rostislav Hejduk diff --git a/lib/player.js b/lib/player.js index 279782b61d..7227db2087 100644 --- a/lib/player.js +++ b/lib/player.js @@ -4347,6 +4347,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget { return []; } const chapters = []; + const uniqueChapters = new Set(); for (const chaptersTrack of chaptersTracksWithLanguage) { if (chaptersTrack && chaptersTrack.cues) { for (const cue of chaptersTrack.cues) { @@ -4361,7 +4362,10 @@ shaka.Player = class extends shaka.util.FakeEventTarget { startTime: cue.startTime, endTime: cue.endTime, }; - chapters.push(chapter); + if (!uniqueChapters.has(id)) { + chapters.push(chapter); + uniqueChapters.add(id); + } } } }