fix(dash): [PKG-DASH-05] align nullable SDK metadata and validate real types

This commit is contained in:
Harvey Zhao committed 2026-09-12 06:07:03 +08:00
1 parent c4b5f5f454
commit 2ad00730ee
25 files changed
+1255 -25

No files matched your search

@@ -73,6 +73,9 @@ the controlled error/identity tests. Changes to SDK capability detection belong
`sdk.ts`, not in a global `any` or ambient module escape.
Public `Config`, `Option`, `QualityLevel`, `AudioTrack`, and `Result` are named types.
AudioTrack id/index/lang include null as declared by both actual SDK generations;
internal AudioFields aliases that public shape. Nullable default labels preserve
runtime behavior, while caller formatters must still return strings.
Default callbacks infer known SDK fields; explicit generic parameters or callback
annotations accept a caller's more detailed SDK interfaces. Original object-based
formatters remain valid. The optional overload supports omitted/undefined options;
@@ -126,5 +129,9 @@ It also includes a native SDK control without an ArtPlayer instance. Early SDK 4
paused-seek stalls remain open; later passes do not resolve them. Unsupported MSE is
recorded as a playback capability gap, not acceptance. This plugin currently refreshes
on ready/restart/explicit update, not automatically on external SDK events.
`refactor/scripts/dash-sdk-types.test.mjs` compares actual SDK-only and plugin
consumers across ten compiler/module configurations, retaining upstream-only
Node10/old DOM diagnostics. The exact peer dependency closure is hash-pinned in
`refactor/baselines/dash-type-dependencies.json`; no type shim or paths mapping is used.
See [refactor validation](../../refactor/dash-validation.md) for baseline failures
and [task plan](../../refactor/plan.md) for remaining type and release work.
@@ -6,6 +6,27 @@ Accepts a caller-owned dash.js instance at `art.dash`. Quality selection adapts
dash.js 4.x quality methods or 5.x representation methods. Version 5 selection uses
representation IDs so bitrate filtering does not change the selected quality.
## TypeScript
The formatter receives the original SDK object. For dash.js 5.2.1 types:
```ts
import type { MediaInfo, Representation } from 'dashjs'
import dashControl from 'artplayer-plugin-dash-control'
dashControl<Representation, MediaInfo>({
quality: { getName: level => `${level.height}p` },
audio: { getName: track => track.lang || String(track.id) },
})
```
dash.js 4.5.2 uses `BitrateInfo` for quality instead of `Representation`. Audio
metadata `id`, `index`, and `lang` may be null; custom formatters must return strings.
The original object-based formatters and synchronous `update()` remain supported.
Actual 5.2.1 SDK types resolve with TypeScript 5.9.3 NodeNext/Bundler in our matrix;
Node10 resolution and TypeScript 4.3.5 have upstream SDK declaration limitations.
See the [tested type matrix](../../refactor/changes/2026-09-12-PKG-DASH-05-sdk-types.md).
## Demo
[https://artplayer.org](https://artplayer.org/?libs=https://cdnjs.cloudflare.com/ajax/libs/dashjs/5.2.1/modern/umd/dash.all.min.js%0A./uncompiled/artplayer-plugin-dash-control/index.js&example=dash.control)
@@ -1,6 +1,6 @@
import type { Config } from '../types/artplayer-plugin-dash-control'
import type { AudioTrack, Config } from '../types/artplayer-plugin-dash-control'
export type Label = string | number | undefined
export type Label = string | number | null | undefined
export type Identifier = string | number
export type Valid = () => boolean
export type Cleanup = () => void
@@ -12,11 +12,7 @@ export interface QualityFields {
qualityIndex?: number
}
export interface AudioFields {
id?: Identifier
index?: number
lang?: string
}
export type AudioFields = AudioTrack
export interface Dash<Level extends object = object, Track extends object = object> {
getVideoElement: () => object | null
@@ -10,9 +10,9 @@ export interface QualityLevel {
}
export interface AudioTrack {
id?: string | number
index?: number
lang?: string
id?: string | number | null
index?: number | null
lang?: string | null
}
export interface Config<Item extends object = object> {