Skip to content

Commit 75721ca

Browse files
committed
Refactor a lot
1 parent bb21add commit 75721ca

File tree

6 files changed

+135
-348
lines changed

6 files changed

+135
-348
lines changed

src/bigscreenplayer.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,7 @@ function BigscreenPlayer() {
645645
* @function
646646
* @returns {Promise<void>}
647647
*/
648-
setAudioDescribedEnabled: (enabled) =>
649-
enabled ? playerComponent.setAudioDescribedOn() : playerComponent.setAudioDescribedOff(),
648+
setAudioDescribed: (enabled) => playerComponent.setAudioDescribed(enabled),
650649

651650
/**
652651
*
@@ -767,14 +766,6 @@ function BigscreenPlayer() {
767766
getInitialPlaybackTime,
768767
getTimeShiftBufferDepthInMilliseconds,
769768
getPresentationTimeOffsetInMilliseconds,
770-
771-
/**
772-
* @function
773-
* @param {Array} sources - Array of new media sources
774-
*/
775-
replaceMediaSources: (sources) => {
776-
playerComponent && playerComponent.replaceMediaSources(sources)
777-
},
778769
}
779770
}
780771

src/bigscreenplayer.test.js

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,9 @@ describe("Bigscreen Player", () => {
113113
tearDown: jest.fn(),
114114
setPlaybackRate: jest.fn(),
115115
getPlaybackRate: jest.fn(),
116-
replaceMediaSources: jest.fn(),
117116
isAudioDescribedAvailable: jest.fn(),
118117
isAudioDescribedEnabled: jest.fn(),
119-
setAudioDescribedOn: jest.fn(),
120-
setAudioDescribedOff: jest.fn(),
118+
setAudioDescribed: jest.fn(),
121119
}
122120

123121
jest.spyOn(PlayerComponent, "getLiveSupport").mockReturnValue(LiveSupport.SEEKABLE)
@@ -1534,23 +1532,25 @@ describe("Bigscreen Player", () => {
15341532
})
15351533
})
15361534

1537-
describe("setAudioDescribedEnabled", () => {
1538-
it("should turn Audio Described on/off when a value is passed in", async () => {
1535+
describe("setAudioDescribed", () => {
1536+
it("should call through to PlayerComponent.setAudioDescribed", async () => {
15391537
await asyncInitialiseBigscreenPlayer(createPlaybackElement(), bigscreenPlayerData)
1540-
bigscreenPlayer.setAudioDescribedEnabled(true)
1538+
bigscreenPlayer.setAudioDescribed(true)
15411539

1542-
expect(mockPlayerComponentInstance.setAudioDescribedOn).toHaveBeenCalledTimes(1)
1543-
expect(mockPlayerComponentInstance.setAudioDescribedOff).toHaveBeenCalledTimes(0)
1540+
expect(mockPlayerComponentInstance.setAudioDescribed).toHaveBeenCalledTimes(1)
1541+
expect(mockPlayerComponentInstance.setAudioDescribed).toHaveBeenCalledWith(true)
1542+
expect(mockPlayerComponentInstance.setAudioDescribed).not.toHaveBeenCalledWith(false)
15441543

1545-
bigscreenPlayer.setAudioDescribedEnabled(false)
1544+
bigscreenPlayer.setAudioDescribed(false)
15461545

1547-
expect(mockPlayerComponentInstance.setAudioDescribedOn).toHaveBeenCalledTimes(1)
1548-
expect(mockPlayerComponentInstance.setAudioDescribedOff).toHaveBeenCalledTimes(1)
1546+
expect(mockPlayerComponentInstance.setAudioDescribed).toHaveBeenCalledTimes(2)
1547+
expect(mockPlayerComponentInstance.setAudioDescribed).toHaveBeenCalledWith(true)
1548+
expect(mockPlayerComponentInstance.setAudioDescribed).toHaveBeenCalledWith(false)
15491549
})
15501550
})
15511551

15521552
describe("isAudioDescribedEnabled", () => {
1553-
it("calls through to playercomponent enabled when called", async () => {
1553+
it("calls through to PlayerComponent.isAudioDescribedEnabled", async () => {
15541554
await asyncInitialiseBigscreenPlayer(createPlaybackElement(), bigscreenPlayerData)
15551555

15561556
bigscreenPlayer.isAudioDescribedEnabled()
@@ -1560,7 +1560,7 @@ describe("Bigscreen Player", () => {
15601560
})
15611561

15621562
describe("isAudioDescribedAvailable", () => {
1563-
it("calls through to playercomponent available when called", async () => {
1563+
it("calls through to PlayerComponent.isAudioDescribedAvailable", async () => {
15641564
await asyncInitialiseBigscreenPlayer(createPlaybackElement(), bigscreenPlayerData)
15651565

15661566
bigscreenPlayer.isAudioDescribedAvailable()
@@ -1670,15 +1670,4 @@ describe("Bigscreen Player", () => {
16701670
expect(DebugTool.getDebugLogs).toHaveBeenCalledTimes(1)
16711671
})
16721672
})
1673-
1674-
describe("replaceMediaSources", () => {
1675-
it("should call through to player component", async () => {
1676-
await asyncInitialiseBigscreenPlayer(createPlaybackElement(), bigscreenPlayerData)
1677-
1678-
const sources = "https://newsource.com"
1679-
bigscreenPlayer.replaceMediaSources(sources)
1680-
1681-
expect(mockPlayerComponentInstance.replaceMediaSources).toHaveBeenCalledWith(sources)
1682-
})
1683-
})
16841673
})

src/mediasources.test.ts

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import SourceLoader from "./manifest/sourceloader"
66
import { ManifestType } from "./models/manifesttypes"
77
import { TransferFormat } from "./models/transferformats"
88
import getError from "./testutils/geterror"
9-
import DebugTool from "./debugger/debugtool"
10-
11-
jest.mock("./debugger/debugtool")
129

1310
jest.mock("./manifest/sourceloader", () => ({
1411
default: {
@@ -575,34 +572,6 @@ describe("Media Sources", () => {
575572

576573
expect(mediaSources.currentSource()).toBe("http://source2.com")
577574
})
578-
579-
it("fails over correctly after sources have been replaced", async () => {
580-
testMedia.urls = [
581-
{ url: "http://source1.com", cdn: "http://cdn1.com" },
582-
{ url: "http://source2.com", cdn: "http://cdn2.com" },
583-
]
584-
585-
testMedia.audioDescribed = [
586-
{ url: "http://audiodescribedsource1.com", cdn: "http://audiodescribedcdn1.com" },
587-
{ url: "http://audiodescribedsource2.com", cdn: "http://audiodescribedcdn2.com" },
588-
]
589-
590-
const mediaSources = MediaSources()
591-
await mediaSources.init(testMedia)
592-
593-
await mediaSources.failover({
594-
isBufferingTimeoutError: true,
595-
code: PluginEnums.ERROR_CODES.BUFFERING_TIMEOUT,
596-
message: PluginEnums.ERROR_MESSAGES.BUFFERING_TIMEOUT,
597-
duration: 100,
598-
currentTime: 94,
599-
})
600-
601-
await mediaSources.replace(mediaSources.getAudioDescribedSources())
602-
await mediaSources.replace(mediaSources.getMainSources())
603-
604-
expect(mediaSources.currentSource()).toBe("http://source2.com")
605-
})
606575
})
607576

608577
describe("Subtitle Sources", () => {
@@ -828,67 +797,4 @@ describe("Media Sources", () => {
828797
expect(mediaSources.availableSources()).toEqual([])
829798
})
830799
})
831-
832-
describe("replace", () => {
833-
beforeEach(() => {
834-
jest.clearAllMocks()
835-
})
836-
837-
it("replaces the media sources", async () => {
838-
const cdn = "http://replacedcdn.com"
839-
const url = "http://replacedurl.com/"
840-
841-
const mediaSources = MediaSources()
842-
await mediaSources.init(testMedia)
843-
844-
await mediaSources.replace([{ cdn, url }])
845-
846-
expect(mediaSources.currentSource()).toBe(url)
847-
})
848-
849-
it("updates debug output after a replace", async () => {
850-
const cdn = "http://replacedcdn.com"
851-
const url = "http://replacedurl.com/"
852-
853-
const mediaSources = MediaSources()
854-
await mediaSources.init(testMedia)
855-
856-
await mediaSources.replace([{ cdn, url }])
857-
858-
expect(DebugTool.dynamicMetric).toHaveBeenCalledWith("cdns-available", [cdn])
859-
expect(DebugTool.dynamicMetric).toHaveBeenCalledWith("current-url", url)
860-
})
861-
862-
it("does not refresh the manifest if not needed", async () => {
863-
const cdn = "http://replacedcdn.com"
864-
const url = "http://replacedurl.com/"
865-
866-
const mediaSources = MediaSources()
867-
await mediaSources.init(testMedia)
868-
869-
await mediaSources.replace([{ cdn, url }])
870-
expect(SourceLoader.load).toHaveBeenCalledTimes(1)
871-
})
872-
873-
it("refreshes the manifest if needed", async () => {
874-
const cdn = "http://replacedcdn.com"
875-
const url = "http://replacedurl.com/"
876-
877-
jest.mocked(SourceLoader.load).mockResolvedValueOnce({
878-
time: {
879-
manifestType: ManifestType.DYNAMIC,
880-
presentationTimeOffsetInMilliseconds: 1731406718000,
881-
availabilityStartTimeInMilliseconds: 1731406718000,
882-
timeShiftBufferDepthInMilliseconds: 0,
883-
},
884-
transferFormat: TransferFormat.HLS,
885-
})
886-
887-
const mediaSources = MediaSources()
888-
await mediaSources.init(testMedia)
889-
890-
await mediaSources.replace([{ cdn, url }])
891-
expect(SourceLoader.load).toHaveBeenCalledTimes(2)
892-
})
893-
})
894800
})

0 commit comments

Comments
 (0)