Repository navigation
fix: keep room playback reporting independent of subtitles #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /* eslint-disable max-classes-per-file -- Minimal parser and renderer test doubles. */ | ||
| import { | ||
| beforeEach, describe, expect, it, vi, | ||
| } from 'vitest'; | ||
| import actions from '@/store/modules/slplayer/subtitleActions'; | ||
| import { insertElementBeforeVideo } from '@/player'; | ||
|
|
||
| const fixtures = vi.hoisted(() => ({ pending: [], renderers: [], signals: [] })); | ||
| vi.mock('@/player', () => ({ | ||
| insertElementBeforeVideo: vi.fn(), | ||
| })); | ||
| vi.mock('@/utils/fetchutils', () => ({ makeUrl: () => 'https://fixture.invalid/subtitles' })); | ||
| vi.mock('@/utils/streams', () => ({ | ||
| default: (url, signal) => { fixtures.signals.push(signal); return {}; }, | ||
| })); | ||
| vi.mock('synclounge-libjass', () => ({ | ||
| parser: { | ||
| StreamParser: class { | ||
| constructor() { | ||
| this.ass = Promise.resolve(); | ||
| this.minimalASS = new Promise((resolve) => { fixtures.pending.push(resolve); }); | ||
| } | ||
| }, | ||
| }, | ||
| renderers: { | ||
| WebRenderer: class { | ||
| constructor(ass) { | ||
| this._ass = ass; | ||
| this.libjassSubsWrapper = { remove: vi.fn() }; | ||
| fixtures.renderers.push(this); | ||
| } | ||
| }, | ||
| }, | ||
| })); | ||
|
|
||
| const makeContext = () => { | ||
| const context = { | ||
| getters: { GET_DECISION_AND_START_PARAMS: {}, CAN_DIRECT_PLAY_SUBTITLES: false }, | ||
| commit: vi.fn(), | ||
| }; | ||
| context.dispatch = vi.fn((type, payload) => { | ||
| if (['PUBLISH_SUBTITLE_SIZE', 'RERENDER_SUBTITLE_CONTAINER', 'GET_OR_MAKE_VIDEO_CLOCK'].includes(type)) { | ||
| return Promise.resolve(); | ||
| } | ||
| return actions[type](context, payload); | ||
| }); | ||
| return context; | ||
| }; | ||
|
|
||
| beforeEach(async () => { | ||
| await actions.DESTROY_SUBTITLES(makeContext()); | ||
| fixtures.pending.length = 0; | ||
| fixtures.renderers.length = 0; | ||
| fixtures.signals.length = 0; | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| describe('subtitle startup ownership', () => { | ||
| it('cannot overwrite a newer track when the old parser finishes late', async () => { | ||
| const context = makeContext(); | ||
| const old = actions.SET_SUBTITLE_URL(context); | ||
| await vi.waitFor(() => expect(fixtures.pending).toHaveLength(1)); | ||
| const current = actions.SET_SUBTITLE_URL(context); | ||
| await vi.waitFor(() => expect(fixtures.pending).toHaveLength(2)); | ||
| expect(fixtures.signals[0].aborted).toBe(true); | ||
| const selected = { track: 'current' }; | ||
| fixtures.pending[1](selected); | ||
| await current; | ||
| fixtures.pending[0]({ track: 'old' }); | ||
| await old; | ||
| expect(fixtures.renderers).toHaveLength(1); | ||
| expect(fixtures.renderers[0]._ass).toBe(selected); | ||
| expect(insertElementBeforeVideo).toHaveBeenCalledExactlyOnceWith( | ||
| fixtures.renderers[0].libjassSubsWrapper, | ||
| ); | ||
| }); | ||
|
|
||
| it('does not create a renderer after subtitles have been destroyed', async () => { | ||
| const context = makeContext(); | ||
| const pending = actions.SET_SUBTITLE_URL(context); | ||
| await vi.waitFor(() => expect(fixtures.pending).toHaveLength(1)); | ||
| await actions.DESTROY_SUBTITLES(context); | ||
| fixtures.pending[0]({ track: 'late' }); | ||
| await pending; | ||
| expect(fixtures.signals[0].aborted).toBe(true); | ||
| expect(fixtures.renderers).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('ignores a ready subtitle parser when its video source has been cancelled', async () => { | ||
| const context = makeContext(); | ||
| let cancelled = false; | ||
| const ensureCurrent = () => { | ||
| if (cancelled) throw new DOMException('Source cancelled', 'AbortError'); | ||
| }; | ||
| const pending = actions.SET_SUBTITLE_URL(context, { ensureCurrent }); | ||
| await vi.waitFor(() => expect(fixtures.pending).toHaveLength(1)); | ||
| cancelled = true; | ||
| fixtures.pending[0]({ track: 'cancelled' }); | ||
| await pending; | ||
| expect(fixtures.renderers).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('ignores an already-cancelled request without destroying current subtitles', async () => { | ||
| const context = makeContext(); | ||
| await actions.SET_SUBTITLE_URL(context, { | ||
| ensureCurrent: () => { throw new DOMException('Source cancelled', 'AbortError'); }, | ||
| }); | ||
| expect(context.dispatch).not.toHaveBeenCalled(); | ||
| expect(fixtures.renderers).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('only starts the latest of two simultaneous subtitle requests', async () => { | ||
| const context = makeContext(); | ||
| const first = actions.SET_SUBTITLE_URL(context); | ||
| const second = actions.SET_SUBTITLE_URL(context); | ||
| await vi.waitFor(() => expect(fixtures.pending).toHaveLength(1)); | ||
| fixtures.pending[0]({ track: 'latest' }); | ||
| await Promise.all([first, second]); | ||
| expect(fixtures.renderers).toHaveLength(1); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.