@mux/playback-core 0.7.1-canary.0-556dabf
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/CHANGELOG.md +91 -0
- package/README.md +9 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.js.map +7 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +7 -0
- package/dist/playback-core.js +30 -0
- package/dist/playback-core.js.map +7 -0
- package/dist/playback-core.mjs +30 -0
- package/dist/playback-core.mjs.map +7 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/autoplay.d.ts +15 -0
- package/dist/types/errors.d.ts +14 -0
- package/dist/types/index.d.ts +70 -0
- package/dist/types/tracks.d.ts +2 -0
- package/dist/types/util.d.ts +3 -0
- package/dist/types-ts3.4/autoplay.d.ts +15 -0
- package/dist/types-ts3.4/errors.d.ts +14 -0
- package/dist/types-ts3.4/index.d.ts +73 -0
- package/dist/types-ts3.4/tracks.d.ts +2 -0
- package/dist/types-ts3.4/util.d.ts +3 -0
- package/package.json +61 -0
- package/src/autoplay.ts +167 -0
- package/src/errors.ts +33 -0
- package/src/index.ts +503 -0
- package/src/tracks.ts +132 -0
- package/src/util.ts +6 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"program":{"fileNames":["../../../node_modules/typescript/lib/lib.es5.d.ts","../../../node_modules/typescript/lib/lib.es2015.d.ts","../../../node_modules/typescript/lib/lib.es2016.d.ts","../../../node_modules/typescript/lib/lib.es2017.d.ts","../../../node_modules/typescript/lib/lib.es2018.d.ts","../../../node_modules/typescript/lib/lib.es2019.d.ts","../../../node_modules/typescript/lib/lib.dom.d.ts","../../../node_modules/typescript/lib/lib.dom.iterable.d.ts","../../../node_modules/typescript/lib/lib.webworker.importscripts.d.ts","../../../node_modules/typescript/lib/lib.scripthost.d.ts","../../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../node_modules/typescript/lib/lib.es2019.full.d.ts","../../../node_modules/hls.js/dist/hls.js.d.ts","../src/autoplay.ts","../src/errors.ts","../src/tracks.ts","../src/util.ts","../src/index.ts","../../../types/mux-embed.d.ts","../../../types/mux.d.ts"],"fileInfos":[{"version":"3ac1b83264055b28c0165688fda6dfcc39001e9e7828f649299101c23ad0a0c3","affectsGlobalScope":true},"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9","5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06","e6b724280c694a9f588847f754198fb96c43d805f065c3a5b28bbc9594541c84",{"version":"72704b10d97777e15f1a581b73f88273037ef752d2e50b72287bd0a90af64fe6","affectsGlobalScope":true},{"version":"dbb73d4d99be496175cb432c74c2615f78c76f4272f1d83cba11ee0ed6dbddf0","affectsGlobalScope":true},{"version":"7fac8cb5fc820bc2a59ae11ef1c5b38d3832c6d0dfaec5acdb5569137d09a481","affectsGlobalScope":true},{"version":"097a57355ded99c68e6df1b738990448e0bf170e606707df5a7c0481ff2427cd","affectsGlobalScope":true},{"version":"d8996609230d17e90484a2dd58f22668f9a05a3bfe00bfb1d6271171e54a31fb","affectsGlobalScope":true},{"version":"43fb1d932e4966a39a41b464a12a81899d9ae5f2c829063f5571b6b87e6d2f9c","affectsGlobalScope":true},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true},{"version":"c5c05907c02476e4bde6b7e76a79ffcd948aedd14b6a8f56e4674221b0417398","affectsGlobalScope":true},{"version":"0d5f52b3174bee6edb81260ebcd792692c32c81fd55499d69531496f3f2b25e7","affectsGlobalScope":true},{"version":"810627a82ac06fb5166da5ada4159c4ec11978dfbb0805fe804c86406dab8357","affectsGlobalScope":true},{"version":"62d80405c46c3f4c527ee657ae9d43fda65a0bf582292429aea1e69144a522a6","affectsGlobalScope":true},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true},{"version":"75ec0bdd727d887f1b79ed6619412ea72ba3c81d92d0787ccb64bab18d261f14","affectsGlobalScope":true},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true},{"version":"12a310447c5d23c7d0d5ca2af606e3bd08afda69100166730ab92c62999ebb9d","affectsGlobalScope":true},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true},{"version":"0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a","affectsGlobalScope":true},{"version":"da233fc1c8a377ba9e0bed690a73c290d843c2c3d23a7bd7ec5cd3d7d73ba1e0","affectsGlobalScope":true},{"version":"d154ea5bb7f7f9001ed9153e876b2d5b8f5c2bb9ec02b3ae0d239ec769f1f2ae","affectsGlobalScope":true},{"version":"bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c","affectsGlobalScope":true},{"version":"c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8","affectsGlobalScope":true},{"version":"9d57b2b5d15838ed094aa9ff1299eecef40b190722eb619bac4616657a05f951","affectsGlobalScope":true},{"version":"6c51b5dd26a2c31dbf37f00cfc32b2aa6a92e19c995aefb5b97a3a64f1ac99de","affectsGlobalScope":true},{"version":"6e7997ef61de3132e4d4b2250e75343f487903ddf5370e7ce33cf1b9db9a63ed","affectsGlobalScope":true},{"version":"2ad234885a4240522efccd77de6c7d99eecf9b4de0914adb9a35c0c22433f993","affectsGlobalScope":true},"1f03b495671c3a1bd24510f38b8947f0991dfd6bf0278c68eca14af15b306e1f","ece0cccc693a3364f05f68d7feb4d472e05b9f2eaea80f19fc10b17a0a6aa14d","220ef4a7a23988997249b25f0561c317c059294c3b145426216a5af31de22721","2c90891ab2ef9273ebe2db728e271417f71625600221a13d11e19ec6f58fa673","daba6bbdb3eebc7c5c23813ea10bfd6a154de40e29fa9b4e470ab17031a87dcd","0a3f1571252fb6fa5d7b0b111836aae2dec501a1ba3ff1c381c1c61f5f7cd9f8","37b197bf33d00bb51ef3b7bf531733ede3c3ea00fae1041335ea4525bf156118","c5a4764697efe3b6b4eaf19b3dc1880cf3df665d30ec93e212233c29a2fa7207",{"version":"ee8e401f800f3d48020eda76c4fd27afd5bab992195252939329ae56dc9d1889","affectsGlobalScope":true}],"options":{"composite":true,"declaration":true,"emitDeclarationOnly":true,"esModuleInterop":true,"jsx":2,"module":5,"noImplicitAny":true,"outDir":"./types","rootDir":"../src","skipLibCheck":true,"sourceMap":true,"strict":true,"target":6},"fileIdsList":[[36],[36,37,38,39,40,42]],"referencedMap":[[37,1],[41,2],[39,1],[43,1]],"exportedModulesMap":[[37,1],[41,2],[39,1],[43,1]],"semanticDiagnosticsPerFile":[36,7,8,12,11,2,13,14,15,16,17,18,19,20,3,4,24,21,22,23,25,26,27,5,28,29,30,31,6,35,32,33,34,1,10,9,37,38,41,39,40,42,43]},"version":"4.6.4"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Hls from 'hls.js';
|
|
2
|
+
declare type PlaybackEngine = Hls;
|
|
3
|
+
export declare type AutoplayTypes = {
|
|
4
|
+
ANY: 'any';
|
|
5
|
+
MUTED: 'muted';
|
|
6
|
+
};
|
|
7
|
+
export declare const AutoplayTypes: AutoplayTypes;
|
|
8
|
+
declare type ValueOf<T> = T[keyof T];
|
|
9
|
+
declare type Maybe<T> = T | null | undefined;
|
|
10
|
+
export declare type Autoplay = boolean | ValueOf<AutoplayTypes>;
|
|
11
|
+
export declare type UpdateAutoplay = (newAutoplay: Maybe<string | boolean>) => void;
|
|
12
|
+
export declare const isAutoplayValue: (value: unknown) => value is Autoplay;
|
|
13
|
+
export declare const setupAutoplay: (mediaEl: HTMLMediaElement, maybeAutoplay: Maybe<string | boolean>, hls: PlaybackEngine | undefined) => UpdateAutoplay;
|
|
14
|
+
export declare const handleAutoplay: (mediaEl: HTMLMediaElement, autoplay: Autoplay) => void;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class MediaError extends Error {
|
|
2
|
+
static MEDIA_ERR_ABORTED: number;
|
|
3
|
+
static MEDIA_ERR_NETWORK: number;
|
|
4
|
+
static MEDIA_ERR_DECODE: number;
|
|
5
|
+
static MEDIA_ERR_SRC_NOT_SUPPORTED: number;
|
|
6
|
+
static MEDIA_ERR_ENCRYPTED: number;
|
|
7
|
+
static MEDIA_ERR_CUSTOM: number;
|
|
8
|
+
static defaultMessages: Record<number, string>;
|
|
9
|
+
name: string;
|
|
10
|
+
code: number;
|
|
11
|
+
fatal: boolean;
|
|
12
|
+
data?: any;
|
|
13
|
+
constructor(message?: string, code?: number, fatal?: boolean);
|
|
14
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import '@mux/polyfills';
|
|
2
|
+
import mux, { Options } from 'mux-embed';
|
|
3
|
+
import Hls, { HlsConfig } from 'hls.js';
|
|
4
|
+
import { AutoplayTypes, setupAutoplay } from './autoplay';
|
|
5
|
+
import { MediaError } from './errors';
|
|
6
|
+
import type { Autoplay, UpdateAutoplay } from './autoplay';
|
|
7
|
+
export declare type ValueOf<T> = T[keyof T];
|
|
8
|
+
export declare type Metadata = Partial<Options['data']>;
|
|
9
|
+
export declare type PlaybackEngine = Hls;
|
|
10
|
+
export { mux, Hls, MediaError, Autoplay, UpdateAutoplay, setupAutoplay };
|
|
11
|
+
export declare const generatePlayerInitTime: () => any;
|
|
12
|
+
export declare type StreamTypes = {
|
|
13
|
+
VOD: 'on-demand';
|
|
14
|
+
ON_DEMAND: 'on-demand';
|
|
15
|
+
LIVE: 'live';
|
|
16
|
+
LL_LIVE: 'll-live';
|
|
17
|
+
DVR: 'live:dvr';
|
|
18
|
+
LL_DVR: 'll-live:dvr';
|
|
19
|
+
};
|
|
20
|
+
export declare const StreamTypes: StreamTypes;
|
|
21
|
+
export declare type ExtensionMimeTypeMap = {
|
|
22
|
+
M3U8: 'application/vnd.apple.mpegurl';
|
|
23
|
+
MP4: 'video/mp4';
|
|
24
|
+
};
|
|
25
|
+
export declare const ExtensionMimeTypeMap: ExtensionMimeTypeMap;
|
|
26
|
+
export declare type MimeTypeShorthandMap = {
|
|
27
|
+
HLS: ExtensionMimeTypeMap['M3U8'];
|
|
28
|
+
};
|
|
29
|
+
export declare const MimeTypeShorthandMap: MimeTypeShorthandMap;
|
|
30
|
+
export declare const shorthandKeys: string[];
|
|
31
|
+
export declare type MediaTypes = ValueOf<ExtensionMimeTypeMap> | keyof MimeTypeShorthandMap
|
|
32
|
+
/** @TODO Figure out a way to "downgrade" derived types below to early TS syntax (e.g. 3.4) instead of explicit versions here (CJP) */
|
|
33
|
+
| 'hls';
|
|
34
|
+
export declare const allMediaTypes: MediaTypes[];
|
|
35
|
+
export declare type MuxMediaPropTypes = {
|
|
36
|
+
envKey: Options['data']['env_key'];
|
|
37
|
+
debug: Options['debug'] & Hls['config']['debug'];
|
|
38
|
+
metadata: Partial<Options['data']>;
|
|
39
|
+
customDomain: string;
|
|
40
|
+
beaconCollectionDomain: Options['beaconCollectionDomain'];
|
|
41
|
+
errorTranslator: Options['errorTranslator'];
|
|
42
|
+
playbackId: string;
|
|
43
|
+
playerInitTime: Options['data']['player_init_time'];
|
|
44
|
+
preferMse: boolean;
|
|
45
|
+
type: MediaTypes;
|
|
46
|
+
streamType: ValueOf<StreamTypes>;
|
|
47
|
+
startTime: HlsConfig['startPosition'];
|
|
48
|
+
autoPlay: boolean | ValueOf<AutoplayTypes>;
|
|
49
|
+
autoplay: boolean | ValueOf<AutoplayTypes>;
|
|
50
|
+
};
|
|
51
|
+
export declare type HTMLMediaElementProps = Partial<Pick<HTMLMediaElement, 'src'>>;
|
|
52
|
+
export declare type MuxMediaProps = HTMLMediaElementProps & MuxMediaPropTypes;
|
|
53
|
+
export declare type MuxMediaPropsInternal = MuxMediaProps & {
|
|
54
|
+
playerSoftwareName: Options['data']['player_software_name'];
|
|
55
|
+
playerSoftwareVersion: Options['data']['player_software_version'];
|
|
56
|
+
};
|
|
57
|
+
export declare const toPlaybackIdParts: (playbackIdWithOptionalParams: string) => [string, string?];
|
|
58
|
+
export declare const toMuxVideoURL: (playbackId?: string | undefined, { domain }?: {
|
|
59
|
+
domain?: string | undefined;
|
|
60
|
+
}) => string | undefined;
|
|
61
|
+
export declare const inferMimeTypeFromURL: (url: string) => "" | "application/vnd.apple.mpegurl" | "video/mp4";
|
|
62
|
+
export declare const getType: (props: Partial<Pick<MuxMediaProps, 'type' | 'src'>>) => "" | MediaTypes;
|
|
63
|
+
export declare const getStreamTypeConfig: (streamType?: ValueOf<StreamTypes> | undefined) => {};
|
|
64
|
+
export declare const getError: (mediaEl: HTMLMediaElement) => MediaError | undefined;
|
|
65
|
+
export declare const teardown: (mediaEl?: HTMLMediaElement | null | undefined, hls?: Pick<Hls, "destroy" | "detachMedia"> | undefined) => void;
|
|
66
|
+
export declare const setupHls: (props: Partial<Pick<MuxMediaProps, 'debug' | 'preferMse' | 'streamType' | 'type' | 'src' | 'startTime'>>, mediaEl?: Pick<HTMLMediaElement, "canPlayType"> | null | undefined) => Hls | undefined;
|
|
67
|
+
export declare const isMuxVideoSrc: ({ playbackId, src, customDomain, }: Partial<Pick<MuxMediaPropsInternal, 'playbackId' | 'src' | 'customDomain'>>) => boolean;
|
|
68
|
+
export declare const setupMux: (props: Partial<Pick<MuxMediaPropsInternal, 'envKey' | 'playerInitTime' | 'beaconCollectionDomain' | 'errorTranslator' | 'metadata' | 'debug' | 'playerSoftwareName' | 'playerSoftwareVersion' | 'playbackId' | 'src' | 'customDomain'>>, mediaEl?: HTMLMediaElement | null | undefined, hlsjs?: Hls | undefined) => void;
|
|
69
|
+
export declare const loadMedia: (props: Partial<Pick<MuxMediaProps, 'preferMse' | 'src' | 'type' | 'startTime' | 'streamType' | 'autoplay'>>, mediaEl?: HTMLMediaElement | null | undefined, hls?: Pick<Hls, "once" | "liveSyncPosition" | "on" | "subtitleTracks" | "subtitleTrack" | "config" | "destroy" | "attachMedia" | "loadSource" | "startLoad" | "stopLoad" | "recoverMediaError"> | undefined) => void;
|
|
70
|
+
export declare const initialize: (props: Partial<MuxMediaPropsInternal>, mediaEl?: HTMLMediaElement | null | undefined, hls?: Hls | undefined) => Hls | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Hls from 'hls.js';
|
|
2
|
+
declare type PlaybackEngine = Hls;
|
|
3
|
+
export declare type AutoplayTypes = {
|
|
4
|
+
ANY: 'any';
|
|
5
|
+
MUTED: 'muted';
|
|
6
|
+
};
|
|
7
|
+
export declare const AutoplayTypes: AutoplayTypes;
|
|
8
|
+
declare type ValueOf<T> = T[keyof T];
|
|
9
|
+
declare type Maybe<T> = T | null | undefined;
|
|
10
|
+
export declare type Autoplay = boolean | ValueOf<AutoplayTypes>;
|
|
11
|
+
export declare type UpdateAutoplay = (newAutoplay: Maybe<string | boolean>) => void;
|
|
12
|
+
export declare const isAutoplayValue: (value: unknown) => value is Autoplay;
|
|
13
|
+
export declare const setupAutoplay: (mediaEl: HTMLMediaElement, maybeAutoplay: Maybe<string | boolean>, hls: PlaybackEngine | undefined) => UpdateAutoplay;
|
|
14
|
+
export declare const handleAutoplay: (mediaEl: HTMLMediaElement, autoplay: Autoplay) => void;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class MediaError extends Error {
|
|
2
|
+
static MEDIA_ERR_ABORTED: number;
|
|
3
|
+
static MEDIA_ERR_NETWORK: number;
|
|
4
|
+
static MEDIA_ERR_DECODE: number;
|
|
5
|
+
static MEDIA_ERR_SRC_NOT_SUPPORTED: number;
|
|
6
|
+
static MEDIA_ERR_ENCRYPTED: number;
|
|
7
|
+
static MEDIA_ERR_CUSTOM: number;
|
|
8
|
+
static defaultMessages: Record<number, string>;
|
|
9
|
+
name: string;
|
|
10
|
+
code: number;
|
|
11
|
+
fatal: boolean;
|
|
12
|
+
data?: any;
|
|
13
|
+
constructor(message?: string, code?: number, fatal?: boolean);
|
|
14
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import '@mux/polyfills';
|
|
2
|
+
import mux, { Options } from 'mux-embed';
|
|
3
|
+
import Hls, { HlsConfig } from 'hls.js';
|
|
4
|
+
import { AutoplayTypes, setupAutoplay } from './autoplay';
|
|
5
|
+
import { MediaError } from './errors';
|
|
6
|
+
import { Autoplay, UpdateAutoplay } from './autoplay';
|
|
7
|
+
export declare type ValueOf<T> = T[keyof T];
|
|
8
|
+
export declare type Metadata = Partial<Options['data']>;
|
|
9
|
+
export declare type PlaybackEngine = Hls;
|
|
10
|
+
export { mux, Hls, MediaError, Autoplay, UpdateAutoplay, setupAutoplay };
|
|
11
|
+
export declare const generatePlayerInitTime: () => any;
|
|
12
|
+
export declare type StreamTypes = {
|
|
13
|
+
VOD: 'on-demand';
|
|
14
|
+
ON_DEMAND: 'on-demand';
|
|
15
|
+
LIVE: 'live';
|
|
16
|
+
LL_LIVE: 'll-live';
|
|
17
|
+
DVR: 'live:dvr';
|
|
18
|
+
LL_DVR: 'll-live:dvr';
|
|
19
|
+
};
|
|
20
|
+
export declare const StreamTypes: StreamTypes;
|
|
21
|
+
export declare type ExtensionMimeTypeMap = {
|
|
22
|
+
M3U8: 'application/vnd.apple.mpegurl';
|
|
23
|
+
MP4: 'video/mp4';
|
|
24
|
+
};
|
|
25
|
+
export declare const ExtensionMimeTypeMap: ExtensionMimeTypeMap;
|
|
26
|
+
export declare type MimeTypeShorthandMap = {
|
|
27
|
+
HLS: ExtensionMimeTypeMap['M3U8'];
|
|
28
|
+
};
|
|
29
|
+
export declare const MimeTypeShorthandMap: MimeTypeShorthandMap;
|
|
30
|
+
export declare const shorthandKeys: string[];
|
|
31
|
+
export declare type MediaTypes = ValueOf<ExtensionMimeTypeMap> | keyof MimeTypeShorthandMap
|
|
32
|
+
/** @TODO Figure out a way to "downgrade" derived types below to early TS syntax (e.g. 3.4) instead of explicit versions here (CJP) */
|
|
33
|
+
| 'hls';
|
|
34
|
+
export declare const allMediaTypes: MediaTypes[];
|
|
35
|
+
export declare type MuxMediaPropTypes = {
|
|
36
|
+
envKey: Options['data']['env_key'];
|
|
37
|
+
debug: Options['debug'] & Hls['config']['debug'];
|
|
38
|
+
metadata: Partial<Options['data']>;
|
|
39
|
+
customDomain: string;
|
|
40
|
+
beaconCollectionDomain: Options['beaconCollectionDomain'];
|
|
41
|
+
errorTranslator: Options['errorTranslator'];
|
|
42
|
+
playbackId: string;
|
|
43
|
+
playerInitTime: Options['data']['player_init_time'];
|
|
44
|
+
preferMse: boolean;
|
|
45
|
+
type: MediaTypes;
|
|
46
|
+
streamType: ValueOf<StreamTypes>;
|
|
47
|
+
startTime: HlsConfig['startPosition'];
|
|
48
|
+
autoPlay: boolean | ValueOf<AutoplayTypes>;
|
|
49
|
+
autoplay: boolean | ValueOf<AutoplayTypes>;
|
|
50
|
+
};
|
|
51
|
+
export declare type HTMLMediaElementProps = Partial<Pick<HTMLMediaElement, 'src'>>;
|
|
52
|
+
export declare type MuxMediaProps = HTMLMediaElementProps & MuxMediaPropTypes;
|
|
53
|
+
export declare type MuxMediaPropsInternal = MuxMediaProps & {
|
|
54
|
+
playerSoftwareName: Options['data']['player_software_name'];
|
|
55
|
+
playerSoftwareVersion: Options['data']['player_software_version'];
|
|
56
|
+
};
|
|
57
|
+
export declare const toPlaybackIdParts: (playbackIdWithOptionalParams: string) => [
|
|
58
|
+
string,
|
|
59
|
+
string?
|
|
60
|
+
];
|
|
61
|
+
export declare const toMuxVideoURL: (playbackId?: string | undefined, { domain }?: {
|
|
62
|
+
domain?: string | undefined;
|
|
63
|
+
}) => string | undefined;
|
|
64
|
+
export declare const inferMimeTypeFromURL: (url: string) => "" | "application/vnd.apple.mpegurl" | "video/mp4";
|
|
65
|
+
export declare const getType: (props: Partial<Pick<MuxMediaProps, 'type' | 'src'>>) => "" | MediaTypes;
|
|
66
|
+
export declare const getStreamTypeConfig: (streamType?: ValueOf<StreamTypes> | undefined) => {};
|
|
67
|
+
export declare const getError: (mediaEl: HTMLMediaElement) => MediaError | undefined;
|
|
68
|
+
export declare const teardown: (mediaEl?: HTMLMediaElement | null | undefined, hls?: Pick<Hls, "destroy" | "detachMedia"> | undefined) => void;
|
|
69
|
+
export declare const setupHls: (props: Partial<Pick<MuxMediaProps, 'debug' | 'preferMse' | 'streamType' | 'type' | 'src' | 'startTime'>>, mediaEl?: Pick<HTMLMediaElement, "canPlayType"> | null | undefined) => Hls | undefined;
|
|
70
|
+
export declare const isMuxVideoSrc: ({ playbackId, src, customDomain, }: Partial<Pick<MuxMediaPropsInternal, 'playbackId' | 'src' | 'customDomain'>>) => boolean;
|
|
71
|
+
export declare const setupMux: (props: Partial<Pick<MuxMediaPropsInternal, 'envKey' | 'playerInitTime' | 'beaconCollectionDomain' | 'errorTranslator' | 'metadata' | 'debug' | 'playerSoftwareName' | 'playerSoftwareVersion' | 'playbackId' | 'src' | 'customDomain'>>, mediaEl?: HTMLMediaElement | null | undefined, hlsjs?: Hls | undefined) => void;
|
|
72
|
+
export declare const loadMedia: (props: Partial<Pick<MuxMediaProps, 'preferMse' | 'src' | 'type' | 'startTime' | 'streamType' | 'autoplay'>>, mediaEl?: HTMLMediaElement | null | undefined, hls?: Pick<Hls, "once" | "liveSyncPosition" | "on" | "subtitleTracks" | "subtitleTrack" | "config" | "destroy" | "attachMedia" | "loadSource" | "startLoad" | "stopLoad" | "recoverMediaError"> | undefined) => void;
|
|
73
|
+
export declare const initialize: (props: Partial<MuxMediaPropsInternal>, mediaEl?: HTMLMediaElement | null | undefined, hls?: Hls | undefined) => Hls | undefined;
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mux/playback-core",
|
|
3
|
+
"version": "0.7.1-canary.0-556dabf",
|
|
4
|
+
"description": "Core library for media playback in the browser shared by mux elements",
|
|
5
|
+
"main": "./dist/index.cjs.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"browser": "./dist/index.mjs",
|
|
8
|
+
"unpkg": "./dist/playback-core.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.cjs.js",
|
|
12
|
+
"default": "./dist/index.cjs.js"
|
|
13
|
+
},
|
|
14
|
+
"types": "dist/types-ts3.4/index.d.ts",
|
|
15
|
+
"typesVersions": {
|
|
16
|
+
">=4.3.5": {
|
|
17
|
+
"*": [
|
|
18
|
+
"dist/types/index.d.ts"
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/muxinc/elements",
|
|
25
|
+
"directory": "packages/playback-core"
|
|
26
|
+
},
|
|
27
|
+
"author": "Mux, Inc.",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"scripts": {
|
|
30
|
+
"clean": "shx rm -rf dist/",
|
|
31
|
+
"dev:cjs": "open-process | yarn build:cjs --watch",
|
|
32
|
+
"dev:esm": "open-process | yarn build:esm --watch",
|
|
33
|
+
"dev:esm-module": "open-process | yarn build:esm-module --watch",
|
|
34
|
+
"dev:iife": "open-process | yarn build:iife --watch",
|
|
35
|
+
"dev:types": "yarn build:types -w",
|
|
36
|
+
"dev": "npm-run-all --parallel dev:types dev:cjs dev:esm dev:iife dev:esm-module",
|
|
37
|
+
"build:esm": "esbuild --metafile=./dist/esm.json src/index.ts --target=es2019 --bundle --sourcemap --format=esm --outdir=dist --out-extension:.js=.mjs --external:mux-embed --external:hls.js",
|
|
38
|
+
"build:esm-module": "esbuild --metafile=./dist/module.json src/index.ts --target=es2019 --bundle --sourcemap --format=esm --outfile=./dist/playback-core.mjs",
|
|
39
|
+
"build:cjs": "esbuild --metafile=./dist/cjs.json src/index.ts --target=es2019 --bundle --sourcemap --format=cjs --outdir=dist --out-extension:.js=.cjs.js --external:mux-embed --external:hls.js",
|
|
40
|
+
"build:iife": "esbuild --metafile=./dist/iife.json src/index.ts --target=es2019 --bundle --sourcemap --format=iife --outfile=./dist/playback-core.js",
|
|
41
|
+
"build:types": "tsc --declaration --emitDeclarationOnly --outDir './dist/types' && downlevel-dts ./dist/types ./dist/types-ts3.4 --to=3.4",
|
|
42
|
+
"build": "npm-run-all --parallel build:types 'build:esm -- --minify' 'build:iife -- --minify' 'build:cjs -- --minify' 'build:esm-module -- --minify'",
|
|
43
|
+
"prebuild": "yarn clean",
|
|
44
|
+
"prepublishOnly": "yarn build",
|
|
45
|
+
"create-release-notes": "create-release-notes ./CHANGELOG.md",
|
|
46
|
+
"publish-release": "../../scripts/publish.sh"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"hls.js": "1.1.5",
|
|
50
|
+
"mux-embed": "^4.7.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@mux/open-process": "0.1.0",
|
|
54
|
+
"@mux/polyfills": "0.1.0",
|
|
55
|
+
"downlevel-dts": "^0.9.0",
|
|
56
|
+
"esbuild": "^0.13.13",
|
|
57
|
+
"npm-run-all": "^4.1.5",
|
|
58
|
+
"shx": "^0.3.4",
|
|
59
|
+
"typescript": "^4.5.2"
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/autoplay.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import Hls from 'hls.js';
|
|
2
|
+
|
|
3
|
+
type PlaybackEngine = Hls;
|
|
4
|
+
|
|
5
|
+
// TODO add INVIEW_MUTED, INVIEW_ANY
|
|
6
|
+
export type AutoplayTypes = {
|
|
7
|
+
ANY: 'any';
|
|
8
|
+
MUTED: 'muted';
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const AutoplayTypes: AutoplayTypes = {
|
|
12
|
+
ANY: 'any',
|
|
13
|
+
MUTED: 'muted',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type ValueOf<T> = T[keyof T];
|
|
17
|
+
type Maybe<T> = T | null | undefined;
|
|
18
|
+
export type Autoplay = boolean | ValueOf<AutoplayTypes>;
|
|
19
|
+
export type UpdateAutoplay = (newAutoplay: Maybe<string | boolean>) => void;
|
|
20
|
+
|
|
21
|
+
const AutoplayTypeValues = Object.values(AutoplayTypes);
|
|
22
|
+
export const isAutoplayValue = (value: unknown): value is Autoplay => {
|
|
23
|
+
return (
|
|
24
|
+
typeof value === 'boolean' ||
|
|
25
|
+
(typeof value === 'string' && AutoplayTypeValues.includes(value as ValueOf<AutoplayTypes>))
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// Given a video element, will listen to lifecycle events to determine important
|
|
30
|
+
// things like whether the video is live or whether the video has played
|
|
31
|
+
// and then handles autoplaying the video as appropraite.
|
|
32
|
+
// It works with both the native video element or hls.js.
|
|
33
|
+
// This returns a method UpdateAutoplay, that allows the user to change
|
|
34
|
+
// the value of the autoplay attribute and it will react appropriately.
|
|
35
|
+
export const setupAutoplay = (
|
|
36
|
+
mediaEl: HTMLMediaElement,
|
|
37
|
+
maybeAutoplay: Maybe<string | boolean>,
|
|
38
|
+
hls: PlaybackEngine | undefined
|
|
39
|
+
) => {
|
|
40
|
+
let hasPlayed = false;
|
|
41
|
+
let isLive = false;
|
|
42
|
+
let autoplay: Autoplay = isAutoplayValue(maybeAutoplay) ? maybeAutoplay : !!maybeAutoplay;
|
|
43
|
+
|
|
44
|
+
const updateHasPlayed = () => {
|
|
45
|
+
// hasPlayed
|
|
46
|
+
mediaEl.addEventListener(
|
|
47
|
+
'playing',
|
|
48
|
+
() => {
|
|
49
|
+
hasPlayed = true;
|
|
50
|
+
},
|
|
51
|
+
{ once: true }
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
updateHasPlayed();
|
|
56
|
+
|
|
57
|
+
// on `loadstart`
|
|
58
|
+
// hasPlayed should default to false
|
|
59
|
+
// we should try and autoplay
|
|
60
|
+
mediaEl.addEventListener(
|
|
61
|
+
'loadstart',
|
|
62
|
+
() => {
|
|
63
|
+
hasPlayed = false;
|
|
64
|
+
updateHasPlayed();
|
|
65
|
+
handleAutoplay(mediaEl, autoplay);
|
|
66
|
+
},
|
|
67
|
+
{ once: true }
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
// on `loadedmetadata` we can check whether we're live in the case of native playback
|
|
71
|
+
mediaEl.addEventListener(
|
|
72
|
+
'loadedmetadata',
|
|
73
|
+
() => {
|
|
74
|
+
// only update isLive here if we're using native playback
|
|
75
|
+
if (!hls) {
|
|
76
|
+
isLive = !Number.isFinite(mediaEl.duration);
|
|
77
|
+
}
|
|
78
|
+
handleAutoplay(mediaEl, autoplay);
|
|
79
|
+
},
|
|
80
|
+
{ once: true }
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
// determine if we're live for hls.js
|
|
84
|
+
if (hls) {
|
|
85
|
+
hls.once(Hls.Events.LEVEL_LOADED, (e: any, data: any) => {
|
|
86
|
+
isLive = data.details.live ?? false;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// When we are not auto-playing, we should seek to the live sync position
|
|
91
|
+
// This will seek first play event of *any* live video including event-type,
|
|
92
|
+
// which probably shouldn't seek
|
|
93
|
+
if (!autoplay) {
|
|
94
|
+
const handleSeek = () => {
|
|
95
|
+
// don't seek if we're not live
|
|
96
|
+
if (!isLive) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
// seek to either hls.js's liveSyncPosition or the native seekable end
|
|
100
|
+
if (hls?.liveSyncPosition) {
|
|
101
|
+
mediaEl.currentTime = hls.liveSyncPosition;
|
|
102
|
+
} else {
|
|
103
|
+
if (Number.isFinite(mediaEl.seekable.end(0))) {
|
|
104
|
+
mediaEl.currentTime = mediaEl.seekable.end(0);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
mediaEl.addEventListener(
|
|
109
|
+
'play',
|
|
110
|
+
() => {
|
|
111
|
+
if (hls && mediaEl.preload === 'metadata') {
|
|
112
|
+
hls.once(Hls.Events.LEVEL_UPDATED, handleSeek);
|
|
113
|
+
} else if (hls) {
|
|
114
|
+
handleSeek();
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
{ once: true }
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// this method allows us to update the value of autoplay
|
|
122
|
+
// and try autoplaying appropriately.
|
|
123
|
+
const updateAutoplay: UpdateAutoplay = (newAutoplay) => {
|
|
124
|
+
if (!hasPlayed) {
|
|
125
|
+
autoplay = isAutoplayValue(newAutoplay) ? newAutoplay : !!newAutoplay;
|
|
126
|
+
handleAutoplay(mediaEl, autoplay);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
return updateAutoplay;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export const handleAutoplay = (mediaEl: HTMLMediaElement, autoplay: Autoplay) => {
|
|
134
|
+
if (!autoplay) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const oldMuted = mediaEl.muted;
|
|
139
|
+
const restoreMuted = () => (mediaEl.muted = oldMuted);
|
|
140
|
+
|
|
141
|
+
switch (autoplay) {
|
|
142
|
+
// ANY:
|
|
143
|
+
// try to play with current options
|
|
144
|
+
// if it fails, mute and try playing again
|
|
145
|
+
// if that fails, restore muted state and don't try playing again
|
|
146
|
+
case AutoplayTypes.ANY:
|
|
147
|
+
mediaEl.play().catch((error: Error) => {
|
|
148
|
+
mediaEl.muted = true;
|
|
149
|
+
mediaEl.play().catch(restoreMuted);
|
|
150
|
+
});
|
|
151
|
+
break;
|
|
152
|
+
|
|
153
|
+
// MUTED:
|
|
154
|
+
// mute the player and then try playing
|
|
155
|
+
// if that fails, restore muted state
|
|
156
|
+
case AutoplayTypes.MUTED:
|
|
157
|
+
mediaEl.muted = true;
|
|
158
|
+
mediaEl.play().catch(restoreMuted);
|
|
159
|
+
break;
|
|
160
|
+
|
|
161
|
+
// Default or if autoplay is a boolean attribute:
|
|
162
|
+
// Try playing the video and catch the failed autoplay warning
|
|
163
|
+
default:
|
|
164
|
+
mediaEl.play().catch(() => {});
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
};
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export class MediaError extends Error {
|
|
2
|
+
static MEDIA_ERR_ABORTED: number = 1;
|
|
3
|
+
static MEDIA_ERR_NETWORK: number = 2;
|
|
4
|
+
static MEDIA_ERR_DECODE: number = 3;
|
|
5
|
+
static MEDIA_ERR_SRC_NOT_SUPPORTED: number = 4;
|
|
6
|
+
static MEDIA_ERR_ENCRYPTED: number = 5;
|
|
7
|
+
// @see https://docs.mux.com/guides/data/monitor-html5-video-element#customize-error-tracking-behavior
|
|
8
|
+
static MEDIA_ERR_CUSTOM: number = 100;
|
|
9
|
+
|
|
10
|
+
static defaultMessages: Record<number, string> = {
|
|
11
|
+
1: 'You aborted the media playback',
|
|
12
|
+
2: 'A network error caused the media download to fail.',
|
|
13
|
+
3: 'A media error caused playback to be aborted. The media could be corrupt or your browser does not support this format.',
|
|
14
|
+
4: 'An unsupported error occurred. The server or network failed, or your browser does not support this format.',
|
|
15
|
+
5: 'The media is encrypted and there are no keys to decrypt it.',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
name: string;
|
|
19
|
+
code: number;
|
|
20
|
+
fatal: boolean;
|
|
21
|
+
data?: any;
|
|
22
|
+
|
|
23
|
+
constructor(message?: string, code: number = MediaError.MEDIA_ERR_CUSTOM, fatal?: boolean) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = 'MediaError';
|
|
26
|
+
this.code = code;
|
|
27
|
+
this.fatal = fatal ?? (code >= MediaError.MEDIA_ERR_NETWORK && code <= MediaError.MEDIA_ERR_ENCRYPTED);
|
|
28
|
+
|
|
29
|
+
if (!this.message) {
|
|
30
|
+
this.message = MediaError.defaultMessages[this.code] ?? '';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|