@gcorevideo/player 2.3.1 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +147 -103
- package/lib/Player.d.ts +1 -1
- package/lib/Player.d.ts.map +1 -1
- package/lib/Player.js +23 -68
- package/lib/internal.types.d.ts +2 -3
- package/lib/internal.types.d.ts.map +1 -1
- package/lib/plugins/dash-playback/DashPlayback.d.ts.map +1 -1
- package/lib/plugins/dash-playback/DashPlayback.js +52 -34
- package/lib/types.d.ts +2 -1
- package/lib/types.d.ts.map +1 -1
- package/lib/utils/mediaSources.d.ts +13 -0
- package/lib/utils/mediaSources.d.ts.map +1 -0
- package/lib/utils/mediaSources.js +82 -0
- package/package.json +1 -1
- package/src/Player.ts +26 -77
- package/src/internal.types.ts +2 -2
- package/src/plugins/dash-playback/DashPlayback.ts +349 -258
- package/src/types.ts +3 -2
- package/src/typings/@clappr/core/player.d.ts +58 -58
- package/src/utils/mediaSources.ts +104 -0
- package/tsconfig.tsbuildinfo +1 -1
package/src/types.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { PlayerMediaSource } from "./internal.types"
|
|
2
|
+
|
|
1
3
|
export type PlayerDebugTag = 'all' | 'clappr' | 'dash' | 'hls' | 'none'
|
|
2
4
|
export type PlayerDebugSettings = PlayerDebugTag | boolean
|
|
3
5
|
|
|
@@ -21,6 +23,7 @@ export type PlayerConfig = {
|
|
|
21
23
|
pluginSettings?: Record<string, unknown>
|
|
22
24
|
poster?: string
|
|
23
25
|
priorityTransport?: TransportPreference
|
|
26
|
+
sources: PlayerMediaSource[];
|
|
24
27
|
strings: TranslationSettings
|
|
25
28
|
}
|
|
26
29
|
|
|
@@ -104,8 +107,6 @@ export type QualityLevelInfo = {
|
|
|
104
107
|
bitrate: number
|
|
105
108
|
}
|
|
106
109
|
|
|
107
|
-
export type BitrateInfo = QualityLevelInfo
|
|
108
|
-
|
|
109
110
|
export enum PlayerEvent {
|
|
110
111
|
Ready = 'ready',
|
|
111
112
|
Play = 'play',
|
|
@@ -1,73 +1,73 @@
|
|
|
1
1
|
import "@clappr/core";
|
|
2
2
|
|
|
3
3
|
declare module "@clappr/core" {
|
|
4
|
-
type MediacontrolStyles = {
|
|
5
|
-
|
|
6
|
-
}
|
|
4
|
+
// type MediacontrolStyles = {
|
|
5
|
+
// // TODO
|
|
6
|
+
// }
|
|
7
7
|
|
|
8
|
-
type PlayerMediaSourceDesc = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
8
|
+
// type PlayerMediaSourceDesc = {
|
|
9
|
+
// mimeType?: string;
|
|
10
|
+
// source: string;
|
|
11
|
+
// }
|
|
12
12
|
|
|
13
|
-
type PlayerMediaSource = string | PlayerMediaSourceDesc;
|
|
13
|
+
// type PlayerMediaSource = string | PlayerMediaSourceDesc;
|
|
14
14
|
|
|
15
|
-
type HlsjsConfig = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} & Record<string, unknown>;
|
|
15
|
+
// type HlsjsConfig = {
|
|
16
|
+
// debug?: boolean;
|
|
17
|
+
// startLevel?: number;
|
|
18
|
+
// } & Record<string, unknown>;
|
|
19
19
|
|
|
20
|
-
type ShakaConfig = Record<string, unknown>;
|
|
20
|
+
// type ShakaConfig = Record<string, unknown>;
|
|
21
21
|
|
|
22
|
-
declare type CorePlaybackConfig = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
22
|
+
// declare type CorePlaybackConfig = {
|
|
23
|
+
// // audioOnly: boolean;
|
|
24
|
+
// disableContextMenu?: boolean;
|
|
25
|
+
// controls?: boolean;
|
|
26
|
+
// crossOrigin?: 'anonymous' | 'use-credentials';
|
|
27
|
+
// // enableAutomaticABR?: boolean;
|
|
28
|
+
// externalTracks?: unknown[]; // TODO
|
|
29
|
+
// hlsjsConfig?: HlsjsConfig;
|
|
30
|
+
// // initialBandwidthEstimate?: number;
|
|
31
|
+
// // maxBufferLength?: number;
|
|
32
|
+
// // maxBackBufferLength?: number;
|
|
33
|
+
// // minBufferLength?: number;
|
|
34
|
+
// minimumDvrSize?: number; // TODO ?
|
|
35
|
+
// // maxAdaptiveBitrate?: number;
|
|
36
|
+
// // maxAdaptiveVideoDimensions?: unknown; // TODO
|
|
37
|
+
// playInline: boolean;
|
|
38
|
+
// preload?: 'metadata' | 'auto' | 'none';
|
|
39
|
+
// // preferredTextLanguage?: string;
|
|
40
|
+
// // preferredAudioLanguage?: string;
|
|
41
|
+
// shakaConfiguration?: ShakaConfig;
|
|
42
|
+
// }
|
|
43
43
|
|
|
44
|
-
type ErrorLevel = "FATAL" | "WARN" | "INFO";
|
|
44
|
+
// type ErrorLevel = "FATAL" | "WARN" | "INFO";
|
|
45
45
|
|
|
46
|
-
declare type EventSpec = string;
|
|
47
|
-
declare type EventHandlerSpec = string;
|
|
48
|
-
declare type PluginEventsConfig = Record<EventSpec, EventHandlerSpec>;
|
|
46
|
+
// declare type EventSpec = string;
|
|
47
|
+
// declare type EventHandlerSpec = string;
|
|
48
|
+
// declare type PluginEventsConfig = Record<EventSpec, EventHandlerSpec>;
|
|
49
49
|
|
|
50
|
-
declare type PlaybackError = {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
50
|
+
// declare type PlaybackError = {
|
|
51
|
+
// code?: number | string;
|
|
52
|
+
// description: string;
|
|
53
|
+
// raw?: MediaError;
|
|
54
|
+
// level?: ErrorLevel;
|
|
55
|
+
// }
|
|
56
56
|
|
|
57
|
-
declare type CorePlayerEvents = {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
57
|
+
// declare type CorePlayerEvents = {
|
|
58
|
+
// // TODO event arguments types
|
|
59
|
+
// onReady?: () => void;
|
|
60
|
+
// onResize?: (data: { width: number; height: number }) => void;
|
|
61
|
+
// onPlay?: (metadata: unknown) => void;
|
|
62
|
+
// onPause?: (metadata: unknown) => void;
|
|
63
|
+
// onStop?: (metadata: unknown) => void;
|
|
64
|
+
// onEnded?: () => void;
|
|
65
|
+
// onSeek?: (currentTime: number) => void;
|
|
66
|
+
// onError?: (err: PlaybackError) => void;
|
|
67
|
+
// onTimeUpdate?: (timeProgress: { current: number; total: number }) => void;
|
|
68
|
+
// onVolumeUpdate?: (value: number) => void;
|
|
69
|
+
// onSubtitleAvailable?: () => void;
|
|
70
|
+
// }
|
|
71
71
|
|
|
72
72
|
declare type ClapprVersionSpec = {
|
|
73
73
|
min: string;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { PlayerMediaSource } from '../internal.types'
|
|
2
|
+
import DashPlayback from '../plugins/dash-playback/DashPlayback'
|
|
3
|
+
import HlsPlayback from '../plugins/hls-playback/HlsPlayback'
|
|
4
|
+
import { StreamMediaSource, TransportPreference } from '../types'
|
|
5
|
+
|
|
6
|
+
export type SourceVariants = {
|
|
7
|
+
dash: string | null
|
|
8
|
+
master: string | null
|
|
9
|
+
hls: string | null
|
|
10
|
+
mpegts: string | null
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function buildSourcesSet(sources: PlayerMediaSource[]): SourceVariants {
|
|
14
|
+
const sv: SourceVariants = {
|
|
15
|
+
dash: null,
|
|
16
|
+
master: null,
|
|
17
|
+
hls: null,
|
|
18
|
+
mpegts: null,
|
|
19
|
+
}
|
|
20
|
+
sources.forEach((ps) => {
|
|
21
|
+
const [s, t] = typeof ps === 'string' ? [ps, ''] : [ps.source, ps.mimeType]
|
|
22
|
+
if (DashPlayback.canPlay(s, t)) {
|
|
23
|
+
sv.dash = s
|
|
24
|
+
} else if (HlsPlayback.canPlay(s, t)) {
|
|
25
|
+
sv.hls = s
|
|
26
|
+
} else {
|
|
27
|
+
sv.master = s
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
return sv
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function buildSourcesPriorityList(
|
|
34
|
+
sources: SourceVariants,
|
|
35
|
+
priorityTransport: TransportPreference = 'auto',
|
|
36
|
+
): PlayerMediaSource[] {
|
|
37
|
+
const msl: string[] = []
|
|
38
|
+
switch (priorityTransport) {
|
|
39
|
+
case 'dash':
|
|
40
|
+
addDash()
|
|
41
|
+
break
|
|
42
|
+
case 'hls':
|
|
43
|
+
addHls()
|
|
44
|
+
break
|
|
45
|
+
case 'mpegts':
|
|
46
|
+
addMpegts()
|
|
47
|
+
break
|
|
48
|
+
case 'auto':
|
|
49
|
+
addDash()
|
|
50
|
+
addHls()
|
|
51
|
+
break
|
|
52
|
+
}
|
|
53
|
+
Object.values(sources).forEach((s) => {
|
|
54
|
+
if (s) {
|
|
55
|
+
msl.push(s)
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
return msl
|
|
59
|
+
|
|
60
|
+
function addMpegts() {
|
|
61
|
+
if (sources.mpegts) {
|
|
62
|
+
msl.push(sources.mpegts)
|
|
63
|
+
sources.mpegts = null
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function addHls() {
|
|
68
|
+
if (sources.hls && HlsPlayback.canPlay(sources.hls)) {
|
|
69
|
+
msl.push(sources.hls)
|
|
70
|
+
sources.hls = null
|
|
71
|
+
}
|
|
72
|
+
if (
|
|
73
|
+
sources.master?.endsWith('.m3u8') &&
|
|
74
|
+
HlsPlayback.canPlay(sources.master)
|
|
75
|
+
) {
|
|
76
|
+
msl.push(sources.master)
|
|
77
|
+
sources.master = null
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function addDash() {
|
|
82
|
+
if (sources.dash && DashPlayback.canPlay(sources.dash)) {
|
|
83
|
+
msl.push(sources.dash)
|
|
84
|
+
sources.dash = null
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function unwrapSource(s: PlayerMediaSource): string {
|
|
90
|
+
return typeof s === 'string' ? s : s.source
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function buildGcoreStreamSourcesList(
|
|
94
|
+
ms: StreamMediaSource,
|
|
95
|
+
priorityTransport: TransportPreference,
|
|
96
|
+
): PlayerMediaSource[] {
|
|
97
|
+
const sources: Record<'dash' | 'master' | 'hls' | 'mpegts', string | null> = {
|
|
98
|
+
dash: ms.sourceDash,
|
|
99
|
+
master: ms.source,
|
|
100
|
+
hls: ms.hlsCmafUrl,
|
|
101
|
+
mpegts: ms.hlsMpegtsUrl,
|
|
102
|
+
}
|
|
103
|
+
return buildSourcesPriorityList(sources, priorityTransport)
|
|
104
|
+
}
|