diff --git a/package.json b/package.json index 27e5103..a57c3cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@profullstack/player", - "version": "0.3.0", + "version": "0.3.1", "description": "One web player for every source a Profullstack site serves: MP4, HLS, MPEG-2 transport streams and audio, with one control bar, on desktop, mobile, PWA and television.", "keywords": [ "video", diff --git a/src/engines/codecs.ts b/src/engines/codecs.ts index e43746d..3f9e6f7 100644 --- a/src/engines/codecs.ts +++ b/src/engines/codecs.ts @@ -85,7 +85,12 @@ export function codecName(codec: string | null | undefined): string | null { * handed is the one that has to pass, and only that one is ever true here anyway. */ export function mseCandidates(kind: 'video' | 'audio', codec: string | undefined): string[] { - if (!codec) return []; + // `kind` is typed, and that protects TypeScript callers only. This module is + // imported by two plain-JavaScript client bundles where a missing kind is an + // ordinary runtime value, and the original guarded both -- dropping it in the + // port turned `mseCandidates(null, 'mp3')` from "nothing to ask" into a + // question about `null/mp4`. Caught by genrewatch's own suite on adoption. + if (!codec || !kind) return []; if (kind === 'audio') { /* diff --git a/test/codecs.test.ts b/test/codecs.test.ts index 5715db2..432ce38 100644 --- a/test/codecs.test.ts +++ b/test/codecs.test.ts @@ -35,8 +35,12 @@ describe('mseCandidates', () => { expect(mseCandidates('audio', 'ac-3')).toEqual(['audio/mp4; codecs="ac-3"']); }); - it('has nothing to ask when there is no codec', () => { + it('has nothing to ask when there is no codec, or no kind', () => { expect(mseCandidates('audio', undefined)).toEqual([]); + // Regression: `kind` is typed, which protects TypeScript callers and not + // the two JavaScript bundles that import this. Without the runtime guard, + // a missing kind asked MSE about `null/mp4`. + expect(mseCandidates(null as unknown as 'audio', 'mp3')).toEqual([]); }); });