Skip to content

Commit 2cc150b

Browse files
committed
fix(player): add dash src to media src type
1 parent 008be88 commit 2cc150b

10 files changed

Lines changed: 47 additions & 43 deletions

File tree

packages/vidstack/src/core/api/player-events.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ import type { DOMEvent } from 'maverick.js/std';
22

33
import type { MediaPlayer } from '../../components';
44
import type { LoggerEvents } from '../../foundation/logger/events';
5+
import type { DASHProviderEvents } from '../../providers/dash/events';
56
import type { GoogleCastEvents } from '../../providers/google-cast/events';
67
import type { HLSProviderEvents } from '../../providers/hls/events';
78
import type { VideoPresentationEvents } from '../../providers/video/presentation/events';
89
import type { MediaEvents } from './media-events';
910
import type { MediaRequestEvents } from './media-request-events';
10-
import type { DashProviderEvents } from '../../providers/dash/events';
1111

1212
export interface MediaPlayerEvents
1313
extends MediaEvents,
14-
MediaRequestEvents,
15-
MediaUserEvents,
16-
LoggerEvents,
17-
VideoPresentationEvents,
18-
HLSProviderEvents,
19-
DashProviderEvents,
20-
GoogleCastEvents {
14+
MediaRequestEvents,
15+
MediaUserEvents,
16+
LoggerEvents,
17+
VideoPresentationEvents,
18+
HLSProviderEvents,
19+
DASHProviderEvents,
20+
GoogleCastEvents {
2121
'media-player-connect': MediaPlayerConnectEvent;
2222
/** @internal */
2323
'find-media-player': FindMediaPlayerEvent;
@@ -32,7 +32,7 @@ export interface MediaPlayerEvents
3232
* @composed
3333
* @detail player
3434
*/
35-
export interface MediaPlayerConnectEvent extends DOMEvent<MediaPlayer> { }
35+
export interface MediaPlayerConnectEvent extends DOMEvent<MediaPlayer> {}
3636

3737
export interface FindMediaPlayerEventDetail {
3838
(player: MediaPlayer | null): void;
@@ -44,6 +44,6 @@ export interface FindMediaPlayerEventDetail {
4444
* @composed
4545
* @detail callback
4646
*/
47-
export interface FindMediaPlayerEvent extends DOMEvent<FindMediaPlayerEventDetail> { }
47+
export interface FindMediaPlayerEvent extends DOMEvent<FindMediaPlayerEventDetail> {}
4848

49-
export interface MediaUserEvents { }
49+
export interface MediaUserEvents {}

packages/vidstack/src/core/api/src-types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isNumber, isString } from 'maverick.js/std';
22
import type { SetRequired } from 'type-fest';
33

4-
export type MediaSrc = string | AudioSrc | VideoSrc | HLSSrc | YouTubeSrc | VimeoSrc;
4+
export type MediaSrc = string | AudioSrc | VideoSrc | HLSSrc | DASHSrc | YouTubeSrc | VimeoSrc;
55

66
export type MediaSrcObject = MediaStream | MediaSource | Blob;
77

@@ -69,6 +69,13 @@ export type HLSMimeType =
6969
| 'video/mpegurl'
7070
| 'application/mpegurl';
7171

72+
export interface DASHSrc {
73+
src: string;
74+
type: DASHMimeType;
75+
}
76+
77+
export type DASHMimeType = 'application/dash+xml';
78+
7279
export interface YouTubeSrc {
7380
src: string;
7481
type: 'video/youtube';

packages/vidstack/src/providers/dash/dash.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TextTrack } from '../../core/tracks/text/text-track';
1010
import { ListSymbol } from '../../foundation/list/symbols';
1111
import { RAFLoop } from '../../foundation/observers/raf-loop';
1212
import { canPlayAudioType, canPlayVideoType, IS_CHROME } from '../../utils/support';
13-
import type { DashConstructor, DashInstanceCallback } from './types';
13+
import type { DASHConstructor, DASHInstanceCallback } from './types';
1414

1515
export type DashGetMediaTracks = (type: DASH.MediaType, manifest: object) => DASH.MediaInfo[];
1616

@@ -21,7 +21,7 @@ export class DASHController {
2121
private _stopLiveSync: (() => void) | null = null;
2222

2323
_config: Partial<DASH.MediaPlayerSettingClass> = {};
24-
_callbacks = new Set<DashInstanceCallback>();
24+
_callbacks = new Set<DASHInstanceCallback>();
2525

2626
get instance() {
2727
return this._instance;
@@ -32,7 +32,7 @@ export class DASHController {
3232
protected _ctx: MediaContext,
3333
) {}
3434

35-
setup(ctor: DashConstructor) {
35+
setup(ctor: DASHConstructor) {
3636
this._instance = ctor().create();
3737

3838
const dispatcher = this._dispatchDASHEvent.bind(this);

packages/vidstack/src/providers/dash/events.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { DOMEvent } from 'maverick.js/std';
33

44
import type { MediaPlayer } from '../../components/player';
55

6-
export interface DashProviderEvents {
6+
export interface DASHProviderEvents {
77
'dash-lib-load-start': DASHLibLoadStartEvent;
88
'dash-lib-loaded': DASHLibLoadedEvent;
99
'dash-lib-load-error': DASHLibLoadErrorEvent;

packages/vidstack/src/providers/dash/lib-loader.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import { DOMEvent, isFunction, isString, isUndefined } from 'maverick.js/std';
33
import type { MediaContext } from '../../core/api/media-context';
44
import { coerceToError } from '../../utils/error';
55
import { loadScript } from '../../utils/network';
6-
import type { DashConstructor, DashConstructorLoader, DashLibrary } from './types';
6+
import type { DASHConstructor, DASHConstructorLoader, DASHLibrary } from './types';
77

88
interface LoadDASHConstructorCallbacks {
99
onLoadStart?: () => void;
10-
onLoaded?: (ctor: DashConstructor) => void;
10+
onLoaded?: (ctor: DASHConstructor) => void;
1111
onLoadError?: (err: Error) => void;
1212
}
1313

1414
export class DASHLibLoader {
1515
constructor(
16-
private _lib: DashLibrary,
16+
private _lib: DASHLibrary,
1717
private _ctx: MediaContext,
18-
private _callback: (ctor: DashConstructor) => void,
18+
private _callback: (ctor: DASHConstructor) => void,
1919
) {
2020
this._startLoading();
2121
}
@@ -61,7 +61,7 @@ export class DASHLibLoader {
6161
this._ctx.player.dispatch(new DOMEvent<void>('dash-lib-load-start'));
6262
}
6363

64-
private _onLoaded(ctor: DashConstructor) {
64+
private _onLoaded(ctor: DASHConstructor) {
6565
if (__DEV__) {
6666
this._ctx.logger
6767
?.infoGroup('Loaded `dash.js`')
@@ -71,7 +71,7 @@ export class DASHLibLoader {
7171
}
7272

7373
this._ctx.player.dispatch(
74-
new DOMEvent<DashConstructor>('dash-lib-loaded', {
74+
new DOMEvent<DASHConstructor>('dash-lib-loaded', {
7575
detail: ctor,
7676
}),
7777
);
@@ -105,7 +105,7 @@ export class DASHLibLoader {
105105
}
106106

107107
async function importDASH(
108-
loader: DashConstructor | DashConstructorLoader | undefined,
108+
loader: DASHConstructor | DASHConstructorLoader | undefined,
109109
callbacks: LoadDASHConstructorCallbacks = {},
110110
) {
111111
if (isUndefined(loader)) return undefined;
@@ -114,12 +114,12 @@ async function importDASH(
114114

115115
// Must be static.
116116
if (loader.prototype && loader.prototype !== Function) {
117-
callbacks.onLoaded?.(loader as DashConstructor);
118-
return loader as DashConstructor;
117+
callbacks.onLoaded?.(loader as DASHConstructor);
118+
return loader as DASHConstructor;
119119
}
120120

121121
try {
122-
const ctor = (await (loader as DashConstructorLoader)())?.default;
122+
const ctor = (await (loader as DASHConstructorLoader)())?.default;
123123

124124
if (ctor) {
125125
callbacks.onLoaded?.(ctor);
@@ -148,7 +148,7 @@ async function importDASH(
148148
async function loadDASHScript(
149149
src: unknown,
150150
callbacks: LoadDASHConstructorCallbacks = {},
151-
): Promise<DashConstructor | undefined> {
151+
): Promise<DASHConstructor | undefined> {
152152
if (!isString(src)) return undefined;
153153

154154
callbacks.onLoadStart?.();

packages/vidstack/src/providers/dash/provider.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { MediaProviderAdapter } from '../types';
88
import { VideoProvider } from '../video/provider';
99
import { DASHController } from './dash';
1010
import { DASHLibLoader } from './lib-loader';
11-
import type { DashConstructor, DashInstanceCallback, DashLibrary } from './types';
11+
import type { DASHConstructor, DASHInstanceCallback, DASHLibrary } from './types';
1212

1313
const JS_DELIVR_CDN = 'https://cdn.jsdelivr.net';
1414

@@ -31,7 +31,7 @@ const JS_DELIVR_CDN = 'https://cdn.jsdelivr.net';
3131
export class DASHProvider extends VideoProvider implements MediaProviderAdapter {
3232
protected override $$PROVIDER_TYPE = 'DASH';
3333

34-
private _ctor: DashConstructor | null = null;
34+
private _ctor: DASHConstructor | null = null;
3535
private readonly _controller = new DASHController(this.video, this._ctx);
3636

3737
/**
@@ -61,7 +61,7 @@ export class DASHProvider extends VideoProvider implements MediaProviderAdapter
6161
return true;
6262
}
6363

64-
protected _library: DashLibrary = `${JS_DELIVR_CDN}/npm/[email protected]/dist/dash${
64+
protected _library: DASHLibrary = `${JS_DELIVR_CDN}/npm/[email protected]/dist/dash${
6565
__DEV__ ? '.all.debug.js' : '.all.min.js'
6666
}`;
6767

@@ -123,7 +123,7 @@ export class DASHProvider extends VideoProvider implements MediaProviderAdapter
123123
* The given callback is invoked when a new `dash.js` instance is created and right before it's
124124
* attached to media.
125125
*/
126-
onInstance(callback: DashInstanceCallback): Dispose {
126+
onInstance(callback: DASHInstanceCallback): Dispose {
127127
const instance = this._controller.instance;
128128
if (instance) callback(instance);
129129
this._controller._callbacks.add(callback);
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import type * as DASH from 'dashjs';
22

3-
import type { DashProviderEvents } from './events';
3+
import type { DASHProviderEvents } from './events';
44

5-
export { type DashProviderEvents };
6-
7-
export type DashConstructor = typeof DASH.MediaPlayer;
8-
export type DashConstructorLoader = () => Promise<{ default: DashConstructor } | undefined>;
9-
export type DashLibrary = DashConstructor | DashConstructorLoader | string | undefined;
10-
export type DashInstanceCallback = (player: DASH.MediaPlayerClass) => void;
5+
export { type DASHProviderEvents };
116

7+
export type DASHConstructor = typeof DASH.MediaPlayer;
8+
export type DASHConstructorLoader = () => Promise<{ default: DASHConstructor } | undefined>;
9+
export type DASHLibrary = DASHConstructor | DASHConstructorLoader | string | undefined;
10+
export type DASHInstanceCallback = (player: DASH.MediaPlayerClass) => void;

packages/vidstack/src/providers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export { YouTubeProviderLoader } from './youtube/loader';
1414
export type { AudioProvider } from './audio/provider';
1515
export type { GoogleCastProvider } from './google-cast/provider';
1616
export type { HLSProvider } from './hls/provider';
17-
export type { DASHProvider } from './dash/provider'
17+
export type { DASHProvider } from './dash/provider';
1818
export type { VideoProvider } from './video/provider';
1919
export type { VimeoProvider } from './vimeo/provider';
2020
export type { YouTubeProvider } from './youtube/provider';

packages/vidstack/src/providers/type-check.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function isHLSProvider(provider: any): provider is HLSProvider {
2121
return provider?.$$PROVIDER_TYPE === 'HLS';
2222
}
2323

24-
export function isDashProvider(provider: any): provider is DASHProvider {
24+
export function isDASHProvider(provider: any): provider is DASHProvider {
2525
return provider?.$$PROVIDER_TYPE === 'DASH';
2626
}
2727

packages/vidstack/src/utils/mime.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ export const HLS_VIDEO_TYPES = new Set<string>([
4949
'application/mpegurl',
5050
]);
5151

52-
export const DASH_VIDEO_TYPES = new Set<string>([
53-
"application/dash+xml",
54-
]);
52+
export const DASH_VIDEO_TYPES = new Set<string>(['application/dash+xml']);
5553

5654
export function isAudioSrc({ src, type }: Src): boolean {
5755
return isString(src)

0 commit comments

Comments
 (0)