From 01432136560a4ea6d9d01ebdec04ec14c7287e20 Mon Sep 17 00:00:00 2001 From: zhirongwang Date: Sat, 28 Nov 2026 20:47:05 -0800 Subject: [PATCH 1/3] fix(video360): reselect viewer when cached preload upgrades to playable A video opened from a cached entry without dash/mp4 starts in the jpg preload viewer, which MediaLoader picks as flat Dash. When file info returns dash, the preload upgrade reloaded that Dash viewer in place, so .360 videos stayed flat until a page refresh. Re-run viewer selection on the server file first and call loadViewer() when it picks a different viewer, such as Video360. --- src/lib/Preview.js | 11 +++++++ src/lib/__tests__/Preview-test.js | 54 +++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/src/lib/Preview.js b/src/lib/Preview.js index e294f02be..d90d31048 100644 --- a/src/lib/Preview.js +++ b/src/lib/Preview.js @@ -1412,6 +1412,17 @@ class Preview extends EventEmitter { const viewerName = getProp(this.viewer, 'options.viewer.NAME', ''); const loader = this.getLoader(this.file); + // The preload viewer was picked from reps without dash/mp4, so it can be the wrong viewer + // (e.g. flat Dash for a .360 video, where Video360 requires dash). + const playableViewer = loader.determineViewer( + this.file, + Object.keys(this.disabledViewers), + this.options.viewers, + ); + if (playableViewer?.NAME !== viewerName) { + this.loadViewer(); + return true; + } const representation = loader.determineRepresentation(this.file, this.viewer.options.viewer); const expectedRep = viewerName === 'Dash' ? 'dash' : 'mp4'; const canUpgradeInPlace = representation?.representation === expectedRep; diff --git a/src/lib/__tests__/Preview-test.js b/src/lib/__tests__/Preview-test.js index ff7d45c88..61a74c858 100644 --- a/src/lib/__tests__/Preview-test.js +++ b/src/lib/__tests__/Preview-test.js @@ -2516,6 +2516,7 @@ describe('lib/Preview', () => { const mp4Rep = { representation: 'mp4', content: { url_template: 'https://example.com/video.mp4' } }; stubs.getLoader = jest.spyOn(preview, 'getLoader').mockReturnValue({ determineRepresentation: jest.fn().mockReturnValue(mp4Rep), + determineViewer: jest.fn().mockReturnValue({ NAME: 'MP4' }), }); preview.handleFileInfoResponse(stubs.file); @@ -2538,6 +2539,7 @@ describe('lib/Preview', () => { stubs.getCachedFile.mockReturnValue({ file_version: { sha1: 2 } }); stubs.getLoader = jest.spyOn(preview, 'getLoader').mockReturnValue({ determineRepresentation: jest.fn().mockReturnValue({ representation: 'mp4' }), + determineViewer: jest.fn().mockReturnValue({ NAME: 'MP4' }), }); preview.handleFileInfoResponse(stubs.file); @@ -2545,6 +2547,58 @@ describe('lib/Preview', () => { expect(stubs.loadViewer).toHaveBeenCalled(); }); + test('should reload the viewer instead of upgrading in place when the playable file needs a different viewer (Video360)', () => { + stubs.loadViewer.mockImplementation(() => {}); + const viewerLoad = jest.fn(); + preview.viewer = { + options: { + viewer: { NAME: 'Dash' }, + representation: { representation: PRELOAD_REP_NAME }, + }, + load: viewerLoad, + }; + stubs.file.name = 'video.360.mp4'; + stubs.file.representations.entries = [{ representation: PRELOAD_REP_NAME }, { representation: 'dash' }]; + stubs.getCachedFile.mockReturnValue({ file_version: { sha1: 2 } }); + const determineRepresentation = jest.fn().mockReturnValue({ representation: 'dash' }); + const determineViewer = jest.fn().mockReturnValue({ NAME: 'Video360' }); + stubs.getLoader = jest.spyOn(preview, 'getLoader').mockReturnValue({ + determineRepresentation, + determineViewer, + }); + + preview.handleFileInfoResponse(stubs.file); + + expect(determineViewer).toHaveBeenCalledWith(stubs.file, expect.any(Array), preview.options.viewers); + expect(determineRepresentation).not.toHaveBeenCalled(); + expect(viewerLoad).not.toHaveBeenCalled(); + expect(stubs.loadViewer).toHaveBeenCalled(); + }); + + test('should upgrade the Dash preload viewer in place when the playable file still uses Dash', () => { + const viewerLoad = jest.fn(); + preview.viewer = { + options: { + viewer: { NAME: 'Dash' }, + representation: { representation: PRELOAD_REP_NAME }, + }, + load: viewerLoad, + }; + stubs.file.representations.entries = [{ representation: PRELOAD_REP_NAME }, { representation: 'dash' }]; + stubs.getCachedFile.mockReturnValue({ file_version: { sha1: 2 } }); + const dashRep = { representation: 'dash' }; + stubs.getLoader = jest.spyOn(preview, 'getLoader').mockReturnValue({ + determineRepresentation: jest.fn().mockReturnValue(dashRep), + determineViewer: jest.fn().mockReturnValue({ NAME: 'Dash' }), + }); + + preview.handleFileInfoResponse(stubs.file); + + expect(preview.viewer.options.representation).toBe(dashRep); + expect(viewerLoad).toHaveBeenCalled(); + expect(stubs.loadViewer).not.toHaveBeenCalled(); + }); + test('should trigger account error when video file has only preload rep and no playable reps', () => { stubs.file.extension = 'mp4'; stubs.file.representations.entries = [{ representation: PRELOAD_REP_NAME }]; From 1af2442de361fc484df92567fe634eada24a0afa Mon Sep 17 00:00:00 2001 From: zhirongwang Date: Sat, 28 Nov 2026 21:16:53 -0800 Subject: [PATCH 2/3] refactor(video360): simplify preload upgrade Once the reselected viewer matches the current one, its rep is always the playable dash/mp4, so the expectedRep check and its fallback are redundant. --- src/lib/Preview.js | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/src/lib/Preview.js b/src/lib/Preview.js index d90d31048..af4adb0ed 100644 --- a/src/lib/Preview.js +++ b/src/lib/Preview.js @@ -1392,8 +1392,8 @@ class Preview extends EventEmitter { /** * If the current viewer is a video preload (jpg) and the file now has a playable rep (dash/mp4), - * either upgrade the same viewer to that rep or switch viewer (e.g. Dash → MP4). Returns true - * if this path was taken so the caller can return. + * either upgrade the same viewer to that rep or switch viewer (e.g. Dash → MP4, Dash → Video360). + * Returns true if this path was taken so the caller can return. * * @private * @param {Object} file - File from server @@ -1410,30 +1410,18 @@ class Preview extends EventEmitter { return false; } - const viewerName = getProp(this.viewer, 'options.viewer.NAME', ''); + // The preload viewer was picked before dash/mp4 existed, so the playable file may need + // a different one (e.g. Video360, which requires dash). const loader = this.getLoader(this.file); - // The preload viewer was picked from reps without dash/mp4, so it can be the wrong viewer - // (e.g. flat Dash for a .360 video, where Video360 requires dash). - const playableViewer = loader.determineViewer( - this.file, - Object.keys(this.disabledViewers), - this.options.viewers, - ); - if (playableViewer?.NAME !== viewerName) { + const viewer = loader.determineViewer(this.file, Object.keys(this.disabledViewers), this.options.viewers); + if (viewer?.NAME !== getProp(this.viewer, 'options.viewer.NAME')) { this.loadViewer(); return true; } - const representation = loader.determineRepresentation(this.file, this.viewer.options.viewer); - const expectedRep = viewerName === 'Dash' ? 'dash' : 'mp4'; - const canUpgradeInPlace = representation?.representation === expectedRep; - if (canUpgradeInPlace) { - this.viewer.options.file = this.file; - this.viewer.options.representation = representation; - this.viewer.load(); - return true; - } - this.loadViewer(); + this.viewer.options.file = this.file; + this.viewer.options.representation = loader.determineRepresentation(this.file, viewer); + this.viewer.load(); return true; } From 74c33d43b20a9ca93b6fe1535156d35b679f67cd Mon Sep 17 00:00:00 2001 From: zhirongwang Date: Sat, 28 Nov 2026 21:50:47 -0800 Subject: [PATCH 3/3] fix(video360): report the real error when no loader fits after preload If no loader can play the refreshed file, call loadViewer() so it raises the account or unsupported-file error instead of a generic refresh error. Also clarify the viewer reselection comment, rename the upgrade tests, and add a test that uses the real loaders to pick Video360. --- src/lib/Preview.js | 9 ++++-- src/lib/__tests__/Preview-test.js | 50 +++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/lib/Preview.js b/src/lib/Preview.js index af4adb0ed..4876c6007 100644 --- a/src/lib/Preview.js +++ b/src/lib/Preview.js @@ -1410,9 +1410,14 @@ class Preview extends EventEmitter { return false; } - // The preload viewer was picked before dash/mp4 existed, so the playable file may need - // a different one (e.g. Video360, which requires dash). const loader = this.getLoader(this.file); + if (!loader) { + this.loadViewer(); + return true; + } + + // The preload viewer was chosen from file info without dash/mp4, so the playable file may need + // a different viewer (e.g. Video360, which requires dash). const viewer = loader.determineViewer(this.file, Object.keys(this.disabledViewers), this.options.viewers); if (viewer?.NAME !== getProp(this.viewer, 'options.viewer.NAME')) { this.loadViewer(); diff --git a/src/lib/__tests__/Preview-test.js b/src/lib/__tests__/Preview-test.js index 61a74c858..378d4d45c 100644 --- a/src/lib/__tests__/Preview-test.js +++ b/src/lib/__tests__/Preview-test.js @@ -2502,7 +2502,7 @@ describe('lib/Preview', () => { expect(stubs.loadViewer).not.toHaveBeenCalled(); }); - test('should upgrade video preload to playable rep when file has matching rep (MP4)', () => { + test('should upgrade the MP4 preload viewer in place when the playable file still uses MP4', () => { const viewerLoad = jest.fn(); preview.viewer = { options: { @@ -2527,7 +2527,7 @@ describe('lib/Preview', () => { expect(stubs.loadViewer).not.toHaveBeenCalled(); }); - test('should call loadViewer when video preload viewer (Dash) and file has only non-matching playable rep (mp4)', () => { + test("should reload the viewer when the Dash preload viewer's file only has mp4 (switches to MP4)", () => { stubs.loadViewer.mockImplementation(() => {}); preview.viewer = { options: { @@ -2575,6 +2575,52 @@ describe('lib/Preview', () => { expect(stubs.loadViewer).toHaveBeenCalled(); }); + test('should pick Video360 with the real loaders when a .360 Dash preload gets dash', () => { + stubs.loadViewer.mockImplementation(() => {}); + jest.spyOn(Browser, 'getName').mockReturnValue('Chrome'); + jest.spyOn(Browser, 'isIOS').mockReturnValue(false); + jest.spyOn(Browser, 'hasWebGL').mockReturnValue(true); + const viewerLoad = jest.fn(); + preview.viewer = { + options: { + viewer: { NAME: 'Dash', REP: 'dash' }, + representation: { representation: PRELOAD_REP_NAME }, + }, + load: viewerLoad, + }; + stubs.file.name = 'video.360.mp4'; + stubs.file.extension = 'mp4'; + stubs.file.representations.entries = [{ representation: PRELOAD_REP_NAME }, { representation: 'dash' }]; + stubs.getCachedFile.mockReturnValue({ file_version: { sha1: 2 } }); + + preview.handleFileInfoResponse(stubs.file); + + expect(preview.getLoader(stubs.file).determineViewer(stubs.file).NAME).toBe('Video360'); + expect(viewerLoad).not.toHaveBeenCalled(); + expect(stubs.loadViewer).toHaveBeenCalled(); + }); + + test('should reload the viewer when no loader can play the file so loadViewer reports the real error', () => { + stubs.loadViewer.mockImplementation(() => {}); + const viewerLoad = jest.fn(); + preview.viewer = { + options: { + viewer: { NAME: 'MP4', REP: 'mp4' }, + representation: { representation: PRELOAD_REP_NAME }, + }, + load: viewerLoad, + }; + stubs.file.representations.entries = [{ representation: PRELOAD_REP_NAME }, { representation: 'dash' }]; + stubs.getCachedFile.mockReturnValue({ file_version: { sha1: 2 } }); + jest.spyOn(preview, 'getLoader').mockReturnValue(undefined); + + preview.handleFileInfoResponse(stubs.file); + + expect(stubs.triggerError).not.toHaveBeenCalled(); + expect(viewerLoad).not.toHaveBeenCalled(); + expect(stubs.loadViewer).toHaveBeenCalled(); + }); + test('should upgrade the Dash preload viewer in place when the playable file still uses Dash', () => { const viewerLoad = jest.fn(); preview.viewer = {