From 1ffdc0b0ead675777687ff5ecd2b20e129f0bd6d Mon Sep 17 00:00:00 2001 From: Nicholas Frederiksen Date: Wed, 8 Nov 2023 17:21:19 +0100 Subject: [PATCH] fix: add id query to each dummy segment url to make them unique (#49) --- index.js | 7 ++++++- spec/hls_splice_subtitle_spec.js | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index e92920a..ad5273c 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,11 @@ const findNearestBw = (bw, array) => { const NOT_MULTIVARIANT_ERROR_MSG = "Error: Source is Not a Multivariant Manifest"; +let DUMMY_SUBTITLE_COUNT = 0; +const getDummySubtitleSegmentId = () => { + return DUMMY_SUBTITLE_COUNT++; +} + const findNearestGroupAndLang = (_group, _language, _playlist) => { const groups = Object.keys(_playlist); let group = groups[0]; // default @@ -258,7 +263,7 @@ class HLSSpliceVod { for (let index = 0; index < playlist.items.PlaylistItem.length; index++) { if (playlist.items.PlaylistItem[index].get("duration")) { duration += playlist.items.PlaylistItem[index].get("duration"); - playlist.items.PlaylistItem[index].set("uri", this.dummySubtitleEndpoint); + playlist.items.PlaylistItem[index].set("uri", this.dummySubtitleEndpoint + `?id=${getDummySubtitleSegmentId()}`); } } return [subtitleItems, duration]; diff --git a/spec/hls_splice_subtitle_spec.js b/spec/hls_splice_subtitle_spec.js index ed3e5b9..377dd44 100644 --- a/spec/hls_splice_subtitle_spec.js +++ b/spec/hls_splice_subtitle_spec.js @@ -95,7 +95,7 @@ describe("HLSSpliceVod with subs", () => { expect(substringsSubs[11]).toBe("#EXT-X-DISCONTINUITY"); expect(substringsSubs[12]).toBe("#EXT-X-CUE-OUT:DURATION=15"); expect(substringsSubs[13]).toBe("#EXTINF:3.0000,"); - expect(substringsSubs[14]).toBe("/dummy"); + expect(substringsSubs[14]).toContain("/dummy?id="); expect(substringsSubs[24]).toBe("#EXT-X-CUE-IN"); done(); }); @@ -193,7 +193,7 @@ describe("HLSSpliceVod with subs", () => { expect(substrings[7]).toBe("http://mock.com/ad/ad1_0_av.ts"); expect(substrings[16]).toBe("#EXT-X-DISCONTINUITY"); - expect(substringsSubs[6]).toBe("/dummy"); + expect(substringsSubs[6]).toContain("/dummy?id="); expect(substringsSubs[15]).toBe("#EXT-X-DISCONTINUITY"); done(); });