@mux/mux-audio 0.5.7-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 +78 -0
- package/README.md +77 -0
- package/dist/index.cjs.js +25 -0
- package/dist/index.cjs.js.map +7 -0
- package/dist/index.mjs +25 -0
- package/dist/index.mjs.map +7 -0
- package/dist/mux-audio.js +53 -0
- package/dist/mux-audio.js.map +7 -0
- package/dist/mux-audio.mjs +53 -0
- package/dist/mux-audio.mjs.map +7 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/CustomAudioElement.d.ts +15 -0
- package/dist/types/env.d.ts +3 -0
- package/dist/types/index.d.ts +50 -0
- package/dist/types-ts3.4/CustomAudioElement.d.ts +11 -0
- package/dist/types-ts3.4/env.d.ts +3 -0
- package/dist/types-ts3.4/index.d.ts +41 -0
- package/package.json +68 -0
- package/src/CustomAudioElement.d.ts +15 -0
- package/src/CustomAudioElement.js +260 -0
- package/src/env.ts +15 -0
- package/src/index.ts +320 -0
- package/test/player.test.js +60 -0
- package/test/web-test-runner.config.mjs +30 -0
- package/tsconfig.json +21 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## [0.5.6](https://github.com/muxinc/elements/compare/@mux-elements/mux-audio@0.5.5...@mux-elements/mux-audio@0.5.6) (2022-06-23)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @mux-elements/mux-audio
|
|
9
|
+
|
|
10
|
+
## [0.5.5](https://github.com/muxinc/elements/compare/@mux-elements/mux-audio@0.5.4...@mux-elements/mux-audio@0.5.5) (2022-06-06)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @mux-elements/mux-audio
|
|
13
|
+
|
|
14
|
+
## [0.5.4](https://github.com/muxinc/elements/compare/@mux-elements/mux-audio@0.5.3...@mux-elements/mux-audio@0.5.4) (2022-05-26)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @mux-elements/mux-audio
|
|
17
|
+
|
|
18
|
+
## [0.5.3](https://github.com/muxinc/elements/compare/@mux-elements/mux-audio@0.5.2...@mux-elements/mux-audio@0.5.3) (2022-05-23)
|
|
19
|
+
|
|
20
|
+
**Note:** Version bump only for package @mux-elements/mux-audio
|
|
21
|
+
|
|
22
|
+
## [0.5.2](https://github.com/muxinc/elements/compare/@mux-elements/mux-audio@0.5.1...@mux-elements/mux-audio@0.5.2) (2022-05-20)
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
- switch cjs extension to .cjs.js ([30e83c3](https://github.com/muxinc/elements/commit/30e83c3ce0bd9bfda4817c30ffe0921e425619e4))
|
|
27
|
+
|
|
28
|
+
## [0.5.1](https://github.com/muxinc/elements/compare/@mux-elements/mux-audio@0.5.0...@mux-elements/mux-audio@0.5.1) (2022-05-10)
|
|
29
|
+
|
|
30
|
+
### Bug Fixes
|
|
31
|
+
|
|
32
|
+
- error message was not passed back to player ([ade8143](https://github.com/muxinc/elements/commit/ade81438834610a7bddfa158ff20ec671ccd508f))
|
|
33
|
+
- fix 3x init of playback-core if `src` used ([#213](https://github.com/muxinc/elements/issues/213)) ([1d3e465](https://github.com/muxinc/elements/commit/1d3e465f8cc40544f0fb2c17ff4fb435c9e9a807))
|
|
34
|
+
|
|
35
|
+
# [0.5.0](https://github.com/muxinc/elements/compare/@mux-elements/mux-audio@0.4.4...@mux-elements/mux-audio@0.5.0) (2022-05-03)
|
|
36
|
+
|
|
37
|
+
### Bug Fixes
|
|
38
|
+
|
|
39
|
+
- custom video events handling ([#203](https://github.com/muxinc/elements/issues/203)) ([a909f89](https://github.com/muxinc/elements/commit/a909f89a69ee0d4b67e9d9371ac0f80984016181))
|
|
40
|
+
- keep .hls but have it log a warning saying to use .\_hls ([11e6c10](https://github.com/muxinc/elements/commit/11e6c102a7e238bc8104c52ae9b94e7e3c2c7e19))
|
|
41
|
+
|
|
42
|
+
### Features
|
|
43
|
+
|
|
44
|
+
- add part=video/audio for mux-video/audio ([49e5b6f](https://github.com/muxinc/elements/commit/49e5b6f14fde14d429afae5c5a46d7595c4e027e)), closes [#125](https://github.com/muxinc/elements/issues/125)
|
|
45
|
+
- rename hls to \_hls ([2d53bc2](https://github.com/muxinc/elements/commit/2d53bc2517840d65a8fd5e2bb2d979ce8b491116))
|
|
46
|
+
|
|
47
|
+
## [0.4.4](https://github.com/muxinc/elements/compare/@mux-elements/mux-audio@0.4.3...@mux-elements/mux-audio@0.4.4) (2022-04-22)
|
|
48
|
+
|
|
49
|
+
### Bug Fixes
|
|
50
|
+
|
|
51
|
+
- point pkgjson#browser at mjs build for webpack 4 ([#191](https://github.com/muxinc/elements/issues/191)) ([a73a495](https://github.com/muxinc/elements/commit/a73a4951052bfc77cc24667b9bc0a05efbcbb355))
|
|
52
|
+
|
|
53
|
+
## [0.4.3](https://github.com/muxinc/elements/compare/@mux-elements/mux-audio@0.4.2...@mux-elements/mux-audio@0.4.3) (2022-04-18)
|
|
54
|
+
|
|
55
|
+
**Note:** Version bump only for package @mux-elements/mux-audio
|
|
56
|
+
|
|
57
|
+
## [0.4.2](https://github.com/muxinc/elements/compare/@mux-elements/mux-audio@0.4.1...@mux-elements/mux-audio@0.4.2) (2022-04-12)
|
|
58
|
+
|
|
59
|
+
### Bug Fixes
|
|
60
|
+
|
|
61
|
+
- clear some state on playbackId change ([#174](https://github.com/muxinc/elements/issues/174)) ([af0738e](https://github.com/muxinc/elements/commit/af0738ea5ae5a75861f75fc2ae3809ada735f3e2))
|
|
62
|
+
|
|
63
|
+
## [0.4.1](https://github.com/muxinc/elements/compare/@mux-elements/mux-audio@0.4.0...@mux-elements/mux-audio@0.4.1) (2022-04-01)
|
|
64
|
+
|
|
65
|
+
**Note:** Version bump only for package @mux-elements/mux-audio
|
|
66
|
+
|
|
67
|
+
# [0.4.0](https://github.com/muxinc/elements/compare/@mux-elements/mux-audio@0.3.0...@mux-elements/mux-audio@0.4.0) (2022-03-28)
|
|
68
|
+
|
|
69
|
+
### Bug Fixes
|
|
70
|
+
|
|
71
|
+
- **mux-audio:** Fix mux-audio, add shadow & props ([c74a448](https://github.com/muxinc/elements/commit/c74a448347cf6585944a08c977b138c560229e4e))
|
|
72
|
+
- **mux-audio:** use generateInitTime() instead of Date.now. ([6b67651](https://github.com/muxinc/elements/commit/6b67651245ee32ee864c8c114cdf480c618e2d8a))
|
|
73
|
+
- **mux-audio:** Use window polyfill for CustomAudioElement browser dependencies. ([2afb742](https://github.com/muxinc/elements/commit/2afb742911a29e708283faaca5fc966b9493670a))
|
|
74
|
+
- prettier format all elements files ([741d607](https://github.com/muxinc/elements/commit/741d607521ca9578cfad9f0a9216a6565b4c56a1))
|
|
75
|
+
|
|
76
|
+
### Features
|
|
77
|
+
|
|
78
|
+
- add beaconCollectionDomain option to replace beaconDomain ([a44b699](https://github.com/muxinc/elements/commit/a44b699ae3138590b9d953f693f95971694658df))
|
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<h1 align="center"><mux-audio/></h1>
|
|
3
|
+
<a href="https://npmcharts.com/compare/@mux/mux-audio?interval=30"><img src="https://img.shields.io/npm/dm/@mux/mux-audio.svg?sanitize=true" alt="Downloads"></a>
|
|
4
|
+
<a href="https://www.npmjs.com/package/@mux/mux-audio"><img src="https://img.shields.io/npm/v/@mux/mux-audio.svg?sanitize=true" alt="Version"></a>
|
|
5
|
+
<a href="https://www.npmjs.com/package/@mux/mux-audio"><img src="https://img.shields.io/npm/l/@mux/mux-audio.svg?sanitize=true" alt="License"></a>
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
# Introduction
|
|
9
|
+
|
|
10
|
+
`<mux-audio></mux-audio>` is a Mux-flavored HTML5 audio element.
|
|
11
|
+
|
|
12
|
+
If you are familiar with using `<audio />` + [Hls.js](https://github.com/video-dev/hls.js) in your application, then you'll feel right at home with this web component.
|
|
13
|
+
|
|
14
|
+
# Installation
|
|
15
|
+
|
|
16
|
+
If you're using `npm` or `yarn`, install that way:
|
|
17
|
+
|
|
18
|
+
## Package manager
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
yarn add @mux/mux-audio
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
or
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
npm i @mux/mux-audio
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Then, import the library into your application with either `import` or `require`:
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
import '@mux/mux-audio';
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
or
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
require('@mux/mux-audio');
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## CDN option
|
|
43
|
+
|
|
44
|
+
Alternatively, use the CDN hosted version of this package:
|
|
45
|
+
|
|
46
|
+
```html
|
|
47
|
+
<script src="https://unpkg.com/@mux/mux-audio@0.4"></script>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
If you are using ecmascript modules, you can also load the `mux-audio.mjs` file with `type=module`:
|
|
51
|
+
|
|
52
|
+
```html
|
|
53
|
+
<script type="module" src="https://unpkg.com/@mux/mux-audio@0.4/dist/mux-audio.mjs"></script>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Usage
|
|
57
|
+
|
|
58
|
+
`<mux-audio>` has all the same features, benefits and options as `<mux-video>`. View the documentation for [`<mux-video>`](../mux-video) for details.
|
|
59
|
+
|
|
60
|
+
### Advanced: Use with React+TypeScript
|
|
61
|
+
|
|
62
|
+
Even though we don't (yet!) have our own `React` version of `<mux-audio>`, you can still use it in your `React` app. However, if you're also using TypeScript, make sure you add the following TypeScript definitions, since custom elements (like as `<mux-audio>`) will not be recognized as [Intrinsic Elements](https://www.typescriptlang.org/docs/handbook/jsx.html#intrinsic-elements):
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
interface MuxAudioHTMLAttributes<T> extends React.AudioHTMLAttributes<T> {
|
|
66
|
+
debug?: boolean;
|
|
67
|
+
autoplay?: boolean;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
declare global {
|
|
71
|
+
namespace JSX {
|
|
72
|
+
interface IntrinsicElements {
|
|
73
|
+
'mux-audio': React.DetailedHTMLProps<MuxAudioHTMLAttributes<HTMLAudioElement>, HTMLAudioElement>;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var _=Object.create;var c=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var O=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty;var f=i=>c(i,"__esModule",{value:!0});var I=(i,t)=>{f(i);for(var s in t)c(i,s,{get:t[s],enumerable:!0})},P=(i,t,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of M(t))!C.call(i,e)&&e!=="default"&&c(i,e,{get:()=>t[e],enumerable:!(s=T(t,e))||s.enumerable});return i},x=i=>P(f(c(i!=null?_(O(i)):{},"default",i&&i.__esModule&&"default"in i?{get:()=>i.default,enumerable:!0}:{value:i,enumerable:!0})),i);I(exports,{AudioEvents:()=>m,MediaError:()=>r.MediaError,default:()=>w});var r=x(require("@mux/playback-core"));var v=()=>{try{return"0.5.7-canary.0-556dabf"}catch{}return"UNKNOWN"},D=v(),p=()=>D;var m=["abort","canplay","canplaythrough","durationchange","emptied","ended","error","loadeddata","loadedmetadata","loadstart","pause","play","playing","progress","ratechange","seeked","seeking","stalled","suspend","timeupdate","volumechange","waiting"],b=document.createElement("template");b.innerHTML=`
|
|
2
|
+
<style>
|
|
3
|
+
:host {
|
|
4
|
+
/* display:inline (like the native el) makes it so you can't fill
|
|
5
|
+
the container with the native el */
|
|
6
|
+
display: inline-block;
|
|
7
|
+
box-sizing: border-box;
|
|
8
|
+
|
|
9
|
+
width: auto;
|
|
10
|
+
height: auto;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
audio {
|
|
14
|
+
max-width: 100%;
|
|
15
|
+
max-height: 100%;
|
|
16
|
+
min-width: 100%;
|
|
17
|
+
min-height: 100%;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
</style>
|
|
21
|
+
|
|
22
|
+
<audio part="audio" crossorigin></audio>
|
|
23
|
+
<slot></slot>
|
|
24
|
+
`;var u=class extends HTMLElement{constructor(){super();this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(b.content.cloneNode(!0));let t=this.nativeEl=this.shadowRoot.querySelector("audio");Array.from(this.attributes).forEach(e=>{this.forwardAttribute(e.name,null,e.value)}),t.defaultMuted&&(t.muted=!0),m.forEach(e=>{t.addEventListener(e,n=>{this.dispatchEvent(new CustomEvent(n.type,{detail:n.detail}))})});let s=this.shadowRoot.querySelector("slot");s.addEventListener("slotchange",()=>{s.assignedElements().forEach(e=>{t.appendChild(e)})})}static get observedAttributes(){let t=[];Object.getOwnPropertyNames(this.prototype).forEach(e=>{let n=!1;try{typeof this.prototype[e]=="function"&&(n=!0)}catch{}!n&&e!==e.toUpperCase()&&t.push(e.toLowerCase())});let s=Object.getPrototypeOf(this).observedAttributes;return s&&(t=t.concat(s)),t}attributeChangedCallback(t,s,e){this.forwardAttribute(t,s,e)}forwardAttribute(t,s,e){let n=Object.getOwnPropertyNames(Object.getPrototypeOf(this)),o=S(n,t),l=Object.getPrototypeOf(this.constructor).toString().indexOf("function HTMLElement")===0;o&&!l?typeof this[o]=="boolean"?e===null?this[o]=!1:this[o]=!0:this[o]=e:e===null?this.nativeEl.removeAttribute(t):["id","class"].indexOf(t)===-1&&this.nativeEl.setAttribute(t,e)}connectedCallback(){}},A=[],y=document.createElement("audio"),R=["webkitDisplayingFullscreen","webkitSupportsFullscreen"];for(let i=Object.getPrototypeOf(y);i&&i!==HTMLElement.prototype;i=Object.getPrototypeOf(i))Object.keys(i).forEach(t=>{R.indexOf(t)===-1&&A.push(t)});A.forEach(i=>{if(typeof y[i]=="function")u.prototype[i]=function(){return this.nativeEl[i].apply(this.nativeEl,arguments)};else{let s={get(){return this.nativeEl[i]}};i!==i.toUpperCase()&&(s.set=function(e){this.nativeEl[i]=e}),Object.defineProperty(u.prototype,i,s)}});function S(i,t){let s=null;return i.forEach(e=>{e.toLowerCase()==t.toLowerCase()&&(s=e)}),s}globalThis.customElements.get("custom-audio")||(globalThis.customElements.define("custom-audio",u),globalThis.CustomAudioElement=u);var E=u;var a={ENV_KEY:"env-key",DEBUG:"debug",PLAYBACK_ID:"playback-id",METADATA_URL:"metadata-url",PREFER_MSE:"prefer-mse",METADATA_VIDEO_ID:"metadata-video-id",METADATA_VIDEO_TITLE:"metadata-video-title",METADATA_VIEWER_USER_ID:"metadata-viewer-user-id",BEACON_COLLECTION_DOMAIN:"beacon-collection-domain",TYPE:"type",STREAM_TYPE:"stream-type",START_TIME:"start-time"},L=Object.values(a),k=p(),N="mux-audio",h=class extends E{constructor(){super();this.__metadata={};this.__playerInitTime=(0,r.generatePlayerInitTime)()}static get observedAttributes(){var t;return[...L,...(t=E.observedAttributes)!=null?t:[]]}get playerInitTime(){return this.__playerInitTime}get playerSoftwareName(){return N}get playerSoftwareVersion(){return k}get hls(){return console.warn("<mux-audio>.hls is deprecated, please use ._hls instead"),this._hls}get _hls(){return this.__hls}get mux(){return this.nativeEl.mux}get src(){return this.getAttribute("src")}set src(t){t!==this.src&&(t==null?this.removeAttribute("src"):this.setAttribute("src",t))}get debug(){return this.getAttribute(a.DEBUG)!=null}set debug(t){t!==this.debug&&(t?this.setAttribute(a.DEBUG,""):this.removeAttribute(a.DEBUG))}get startTime(){let t=this.getAttribute(a.START_TIME);if(t==null)return;let s=+t;return Number.isNaN(s)?void 0:s}set startTime(t){t!==this.startTime&&(t==null?this.removeAttribute(a.START_TIME):this.setAttribute(a.START_TIME,`${t}`))}get playbackId(){var t;return(t=this.getAttribute(a.PLAYBACK_ID))!=null?t:void 0}set playbackId(t){t!==this.playbackId&&(t?this.setAttribute(a.PLAYBACK_ID,t):this.removeAttribute(a.PLAYBACK_ID))}get envKey(){var t;return(t=this.getAttribute(a.ENV_KEY))!=null?t:void 0}set envKey(t){t!==this.envKey&&(t?this.setAttribute(a.ENV_KEY,t):this.removeAttribute(a.ENV_KEY))}get beaconCollectionDomain(){var t;return(t=this.getAttribute(a.BEACON_COLLECTION_DOMAIN))!=null?t:void 0}set beaconCollectionDomain(t){t!==this.beaconCollectionDomain&&(t?this.setAttribute(a.BEACON_COLLECTION_DOMAIN,t):this.removeAttribute(a.BEACON_COLLECTION_DOMAIN))}get streamType(){var t;return(t=this.getAttribute(a.STREAM_TYPE))!=null?t:void 0}set streamType(t){t!==this.streamType&&(t?this.setAttribute(a.STREAM_TYPE,t):this.removeAttribute(a.STREAM_TYPE))}get preferMse(){return this.getAttribute(a.PREFER_MSE)!=null}set preferMse(t){t?this.setAttribute(a.PREFER_MSE,""):this.removeAttribute(a.PREFER_MSE)}get metadata(){return this.__metadata}set metadata(t){this.__metadata=t!=null?t:{},this.mux&&(console.info("Some metadata values may not be overridable at this time. Make sure you set all metadata to override before setting the src."),this.mux.emit("hb",this.__metadata))}load(){let t=(0,r.initialize)(this,this.nativeEl,this.__hls);this.__hls=t;let s=(0,r.setupAutoplay)(this.nativeEl,this.autoplay,t);this.__updateAutoplay=s}unload(){(0,r.teardown)(this.nativeEl,this.__hls),this.__hls=void 0}attributeChangedCallback(t,s,e){var n;switch(t){case"src":let o=!!s,l=!!e;!o&&l?this.load():o&&!l?this.unload():o&&l&&(this.unload(),this.load());break;case"autoplay":(n=this.__updateAutoplay)==null||n.call(this,e);break;case a.PLAYBACK_ID:this.src=(0,r.toMuxVideoURL)(e!=null?e:void 0);break;case a.DEBUG:let g=this.debug;this.mux&&console.info("Cannot toggle debug mode of mux data after initialization. Make sure you set all metadata to override before setting the src."),this._hls&&(this._hls.config.debug=g);break;case a.METADATA_URL:e&&fetch(e).then(d=>d.json()).then(d=>this.metadata=d).catch(d=>console.error(`Unable to load or parse metadata JSON from metadata-url ${e}!`));break;default:break}super.attributeChangedCallback(t,s,e)}disconnectedCallback(){this.unload()}};globalThis.customElements.get("mux-audio")||(globalThis.customElements.define("mux-audio",h),globalThis.MuxAudioElement=h);var w=h;
|
|
25
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts", "../src/env.ts", "../src/CustomAudioElement.js"],
|
|
4
|
+
"sourcesContent": ["import {\n initialize,\n setupAutoplay,\n MuxMediaProps,\n StreamTypes,\n ValueOf,\n toMuxVideoURL,\n teardown,\n Metadata,\n mux,\n generatePlayerInitTime,\n MediaError,\n} from '@mux/playback-core';\nimport type { PlaybackEngine, UpdateAutoplay, ExtensionMimeTypeMap } from '@mux/playback-core';\nimport { getPlayerVersion } from './env';\n// this must be imported after playback-core for the polyfill to be included\nimport CustomAudioElement, { AudioEvents } from './CustomAudioElement';\n\n/** @TODO make the relationship between name+value smarter and more deriveable (CJP) */\ntype AttributeNames = {\n ENV_KEY: 'env-key';\n DEBUG: 'debug';\n METADATA_URL: 'metadata-url';\n METADATA_VIDEO_ID: 'metadata-video-id';\n METADATA_VIDEO_TITLE: 'metadata-video-title';\n METADATA_VIEWER_USER_ID: 'metadata-viewer-user-id';\n BEACON_COLLECTION_DOMAIN: 'beacon-collection-domain';\n PLAYBACK_ID: 'playback-id';\n PREFER_MSE: 'prefer-mse';\n TYPE: 'type';\n STREAM_TYPE: 'stream-type';\n START_TIME: 'start-time';\n};\n\nconst Attributes: AttributeNames = {\n ENV_KEY: 'env-key',\n DEBUG: 'debug',\n PLAYBACK_ID: 'playback-id',\n METADATA_URL: 'metadata-url',\n PREFER_MSE: 'prefer-mse',\n METADATA_VIDEO_ID: 'metadata-video-id',\n METADATA_VIDEO_TITLE: 'metadata-video-title',\n METADATA_VIEWER_USER_ID: 'metadata-viewer-user-id',\n BEACON_COLLECTION_DOMAIN: 'beacon-collection-domain',\n TYPE: 'type',\n STREAM_TYPE: 'stream-type',\n START_TIME: 'start-time',\n};\n\nconst AttributeNameValues = Object.values(Attributes);\n\nconst playerSoftwareVersion = getPlayerVersion();\nconst playerSoftwareName = 'mux-audio';\n\nclass MuxAudioElement extends CustomAudioElement<HTMLAudioElement> implements Partial<MuxMediaProps> {\n static get observedAttributes() {\n return [...AttributeNameValues, ...(CustomAudioElement.observedAttributes ?? [])];\n }\n\n // Keeping this named \"__hls\" since it's exposed for unadvertised \"advanced usage\" via getter that assumes specifically hls.js (CJP)\n protected __hls?: PlaybackEngine;\n protected __playerInitTime: number;\n protected __metadata: Readonly<Metadata> = {};\n protected __updateAutoplay?: UpdateAutoplay;\n\n constructor() {\n super();\n this.__playerInitTime = generatePlayerInitTime();\n }\n\n get playerInitTime() {\n return this.__playerInitTime;\n }\n\n get playerSoftwareName() {\n return playerSoftwareName;\n }\n\n get playerSoftwareVersion() {\n return playerSoftwareVersion;\n }\n\n /**\n * @deprecated please use ._hls instead\n */\n get hls() {\n console.warn('<mux-audio>.hls is deprecated, please use ._hls instead');\n return this._hls;\n }\n\n get _hls() {\n return this.__hls;\n }\n\n get mux(): Readonly<HTMLAudioElement['mux']> | undefined {\n return this.nativeEl.mux;\n }\n\n get src() {\n // Use the attribute value as the source of truth.\n // No need to store it in two places.\n // This avoids needing a to read the attribute initially and update the src.\n return this.getAttribute('src') as string;\n }\n\n set src(val: string) {\n // If being set by attributeChangedCallback,\n // dont' cause an infinite loop\n if (val === this.src) return;\n\n if (val == null) {\n this.removeAttribute('src');\n } else {\n this.setAttribute('src', val);\n }\n }\n\n /** @TODO write a generic module for well defined primitive types -> attribute getter/setters/removers (CJP) */\n get debug(): boolean {\n return this.getAttribute(Attributes.DEBUG) != null;\n }\n\n set debug(val: boolean) {\n // dont' cause an infinite loop\n if (val === this.debug) return;\n\n if (val) {\n this.setAttribute(Attributes.DEBUG, '');\n } else {\n this.removeAttribute(Attributes.DEBUG);\n }\n }\n\n get startTime(): number | undefined {\n const val = this.getAttribute(Attributes.START_TIME);\n if (val == null) return undefined;\n const num = +val;\n return !Number.isNaN(num) ? num : undefined;\n }\n\n set startTime(val: number | undefined) {\n // dont' cause an infinite loop\n if (val === this.startTime) return;\n\n if (val == null) {\n this.removeAttribute(Attributes.START_TIME);\n } else {\n this.setAttribute(Attributes.START_TIME, `${val}`);\n }\n }\n\n get playbackId(): string | undefined {\n return this.getAttribute(Attributes.PLAYBACK_ID) ?? undefined;\n }\n\n set playbackId(val: string | undefined) {\n // dont' cause an infinite loop\n if (val === this.playbackId) return;\n\n if (val) {\n this.setAttribute(Attributes.PLAYBACK_ID, val);\n } else {\n this.removeAttribute(Attributes.PLAYBACK_ID);\n }\n }\n\n get envKey(): string | undefined {\n return this.getAttribute(Attributes.ENV_KEY) ?? undefined;\n }\n\n set envKey(val: string | undefined) {\n // dont' cause an infinite loop\n if (val === this.envKey) return;\n\n if (val) {\n this.setAttribute(Attributes.ENV_KEY, val);\n } else {\n this.removeAttribute(Attributes.ENV_KEY);\n }\n }\n\n get beaconCollectionDomain(): string | undefined {\n return this.getAttribute(Attributes.BEACON_COLLECTION_DOMAIN) ?? undefined;\n }\n\n set beaconCollectionDomain(val: string | undefined) {\n // dont' cause an infinite loop\n if (val === this.beaconCollectionDomain) return;\n\n if (val) {\n this.setAttribute(Attributes.BEACON_COLLECTION_DOMAIN, val);\n } else {\n this.removeAttribute(Attributes.BEACON_COLLECTION_DOMAIN);\n }\n }\n\n get streamType(): ValueOf<StreamTypes> | undefined {\n // getAttribute doesn't know that this attribute is well defined. Should explore extending for MuxVideo (CJP)\n return (this.getAttribute(Attributes.STREAM_TYPE) as ValueOf<StreamTypes>) ?? undefined;\n }\n\n set streamType(val: ValueOf<StreamTypes> | undefined) {\n // dont' cause an infinite loop\n if (val === this.streamType) return;\n\n if (val) {\n this.setAttribute(Attributes.STREAM_TYPE, val);\n } else {\n this.removeAttribute(Attributes.STREAM_TYPE);\n }\n }\n\n /** @TODO Followup: naming convention: all lower (common per HTMLElement props) vs. camel (common per JS convention) (CJP) */\n get preferMse(): boolean {\n return this.getAttribute(Attributes.PREFER_MSE) != null;\n }\n\n set preferMse(val: boolean) {\n if (val) {\n this.setAttribute(Attributes.PREFER_MSE, '');\n } else {\n this.removeAttribute(Attributes.PREFER_MSE);\n }\n }\n\n get metadata() {\n return this.__metadata;\n }\n\n set metadata(val: Readonly<Metadata> | undefined) {\n this.__metadata = val ?? {};\n if (!!this.mux) {\n /** @TODO Link to docs for a more detailed discussion (CJP) */\n console.info(\n 'Some metadata values may not be overridable at this time. Make sure you set all metadata to override before setting the src.'\n );\n this.mux.emit('hb', this.__metadata);\n }\n }\n\n load() {\n const nextHlsInstance = initialize(this as Partial<MuxMediaProps>, this.nativeEl, this.__hls);\n this.__hls = nextHlsInstance;\n const updateAutoplay = setupAutoplay(this.nativeEl, this.autoplay, nextHlsInstance);\n this.__updateAutoplay = updateAutoplay;\n }\n\n unload() {\n teardown(this.nativeEl, this.__hls);\n this.__hls = undefined;\n }\n\n attributeChangedCallback(attrName: string, oldValue: string | null, newValue: string | null) {\n switch (attrName) {\n case 'src':\n const hadSrc = !!oldValue;\n const hasSrc = !!newValue;\n if (!hadSrc && hasSrc) {\n this.load();\n } else if (hadSrc && !hasSrc) {\n this.unload();\n /** @TODO Test this thoroughly (async?) and confirm unload() necessary (CJP) */\n } else if (hadSrc && hasSrc) {\n this.unload();\n this.load();\n }\n break;\n case 'autoplay':\n this.__updateAutoplay?.(newValue);\n break;\n case Attributes.PLAYBACK_ID:\n /** @TODO Improv+Discuss - how should playback-id update wrt src attr changes (and vice versa) (CJP) */\n this.src = toMuxVideoURL(newValue ?? undefined) as string;\n break;\n case Attributes.DEBUG:\n const debug = this.debug;\n if (!!this.mux) {\n /** @TODO Link to docs for a more detailed discussion (CJP) */\n console.info(\n 'Cannot toggle debug mode of mux data after initialization. Make sure you set all metadata to override before setting the src.'\n );\n }\n if (!!this._hls) {\n this._hls.config.debug = debug;\n }\n break;\n case Attributes.METADATA_URL:\n if (newValue) {\n fetch(newValue)\n .then((resp) => resp.json())\n .then((json) => (this.metadata = json))\n .catch((_err) => console.error(`Unable to load or parse metadata JSON from metadata-url ${newValue}!`));\n }\n break;\n default:\n break;\n }\n\n super.attributeChangedCallback(attrName, oldValue, newValue);\n }\n\n disconnectedCallback() {\n this.unload();\n }\n}\n\ntype MuxAudioElementType = typeof MuxAudioElement;\ndeclare global {\n var MuxAudioElement: MuxAudioElementType;\n}\n\nif (!globalThis.customElements.get('mux-audio')) {\n globalThis.customElements.define('mux-audio', MuxAudioElement);\n /** @TODO consider externalizing this (breaks standard modularity) */\n globalThis.MuxAudioElement = MuxAudioElement;\n}\n\nexport { PlaybackEngine, PlaybackEngine as Hls, ExtensionMimeTypeMap as MimeTypes, MediaError, AudioEvents };\n\nexport default MuxAudioElement;\n", "export const isMaybeBrowser = () => typeof window != 'undefined';\n// @ts-ignore\nexport const isMaybeServer = () => typeof global != 'undefined';\n\nconst getEnvPlayerVersion = () => {\n try {\n // @ts-ignore\n return PLAYER_VERSION as string;\n } catch {}\n return 'UNKNOWN';\n};\n\nconst player_version: string = getEnvPlayerVersion();\n\nexport const getPlayerVersion = () => player_version;\n", "/**\n * Custom Audio Element\n * The goal is to create an element that works just like the audio element\n * but can be extended/sub-classed, because native elements cannot be\n * extended today across browsers.\n */\n\nexport const AudioEvents = [\n 'abort',\n 'canplay',\n 'canplaythrough',\n 'durationchange',\n 'emptied',\n 'ended',\n 'error',\n 'loadeddata',\n 'loadedmetadata',\n 'loadstart',\n 'pause',\n 'play',\n 'playing',\n 'progress',\n 'ratechange',\n 'seeked',\n 'seeking',\n 'stalled',\n 'suspend',\n 'timeupdate',\n 'volumechange',\n 'waiting',\n];\n\nconst template = document.createElement('template');\n// Could you get styles to apply by passing a global button from global to shadow?\n\ntemplate.innerHTML = `\n<style>\n :host {\n /* display:inline (like the native el) makes it so you can't fill\n the container with the native el */\n display: inline-block;\n box-sizing: border-box;\n\n width: auto;\n height: auto;\n }\n\n audio {\n max-width: 100%;\n max-height: 100%;\n min-width: 100%;\n min-height: 100%;\n }\n\n</style>\n\n<audio part=\"audio\" crossorigin></audio>\n<slot></slot>\n`;\n\nclass CustomAudioElement extends HTMLElement {\n constructor() {\n super();\n\n this.attachShadow({ mode: 'open' });\n this.shadowRoot.appendChild(template.content.cloneNode(true));\n const nativeEl = (this.nativeEl = this.shadowRoot.querySelector('audio'));\n\n // Initialize all the attribute properties\n // This is required before attributeChangedCallback is called after construction\n // so the initial state of all the attributes are forwarded to the native element.\n Array.from(this.attributes).forEach((attrNode) => {\n this.forwardAttribute(attrNode.name, null, attrNode.value);\n });\n\n // Neither Chrome or Firefox support setting the muted attribute\n // after using document.createElement.\n // One way to get around this would be to build the native tag as a string.\n // But just fixing it manually for now.\n // Apparently this may also be an issue with <input checked> for buttons\n if (nativeEl.defaultMuted) {\n nativeEl.muted = true;\n }\n\n // The audio events are dispatched on the CustomAudioElement instance.\n // This makes it possible to add event listeners before the element is upgraded.\n AudioEvents.forEach((type) => {\n nativeEl.addEventListener(type, (evt) => {\n this.dispatchEvent(new CustomEvent(evt.type, { detail: evt.detail }));\n });\n });\n\n const slotEl = this.shadowRoot.querySelector('slot');\n slotEl.addEventListener('slotchange', () => {\n slotEl.assignedElements().forEach((el) => {\n nativeEl.appendChild(el);\n });\n });\n }\n\n // observedAttributes is required to trigger attributeChangedCallback\n // for any attributes on the custom element.\n // Attributes need to be the lowercase word, e.g. crossorigin, not crossOrigin\n static get observedAttributes() {\n let attrs = [];\n\n // Instead of manually creating a list of all observed attributes,\n // observe any getter/setter prop name (lowercased)\n Object.getOwnPropertyNames(this.prototype).forEach((propName) => {\n let isFunc = false;\n\n // Non-func properties throw errors because it's not an instance\n try {\n if (typeof this.prototype[propName] === 'function') {\n isFunc = true;\n }\n } catch (e) {}\n\n // Exclude functions and constants\n if (!isFunc && propName !== propName.toUpperCase()) {\n attrs.push(propName.toLowerCase());\n }\n });\n\n // Include any attributes from the super class (recursive)\n const supAttrs = Object.getPrototypeOf(this).observedAttributes;\n\n if (supAttrs) {\n attrs = attrs.concat(supAttrs);\n }\n\n return attrs;\n }\n\n // We need to handle sub-class custom attributes differently from\n // attrs meant to be passed to the internal native el.\n attributeChangedCallback(attrName, oldValue, newValue) {\n this.forwardAttribute(attrName, oldValue, newValue);\n }\n\n forwardAttribute(attrName, oldValue, newValue) {\n // Find the matching prop for custom attributes\n const ownProps = Object.getOwnPropertyNames(Object.getPrototypeOf(this));\n const propName = arrayFindAnyCase(ownProps, attrName);\n\n // Check if this is the original custom native elemnt or a subclass\n const isBaseElement = Object.getPrototypeOf(this.constructor).toString().indexOf('function HTMLElement') === 0;\n\n // If this is a subclass custom attribute we want to set the\n // matching property on the subclass\n if (propName && !isBaseElement) {\n // Boolean props should never start as null\n if (typeof this[propName] == 'boolean') {\n // null is returned when attributes are removed i.e. boolean attrs\n if (newValue === null) {\n this[propName] = false;\n } else {\n // The new value might be an empty string, which is still true\n // for boolean attributes\n this[propName] = true;\n }\n } else {\n this[propName] = newValue;\n }\n } else {\n // When this is the original Custom Element, or the subclass doesn't\n // have a matching prop, pass it through.\n if (newValue === null) {\n this.nativeEl.removeAttribute(attrName);\n } else {\n // Ignore a few that don't need to be passed through just in case\n // it creates unexpected behavior.\n if (['id', 'class'].indexOf(attrName) === -1) {\n this.nativeEl.setAttribute(attrName, newValue);\n }\n }\n }\n }\n\n connectedCallback() {}\n}\n\n// Map all native element properties to the custom element\n// so that they're applied to the native element.\n// Skipping HTMLElement because of things like \"attachShadow\"\n// causing issues. Most of those props still need to apply to\n// the custom element.\n// But includign EventTarget props because most events emit from\n// the native element.\nlet nativeElProps = [];\n\n// Can't check typeof directly on element prototypes without\n// throwing Illegal Invocation errors, so creating an element\n// to check on instead.\nconst nativeElTest = document.createElement('audio');\n\n// Deprecated props throw warnings if used, so exclude them\nconst deprecatedProps = ['webkitDisplayingFullscreen', 'webkitSupportsFullscreen'];\n\n// Walk the prototype chain up to HTMLElement.\n// This will grab all super class props in between.\n// i.e. AudioElement and MediaElement\nfor (\n let proto = Object.getPrototypeOf(nativeElTest);\n proto && proto !== HTMLElement.prototype;\n proto = Object.getPrototypeOf(proto)\n) {\n Object.keys(proto).forEach((key) => {\n if (deprecatedProps.indexOf(key) === -1) {\n nativeElProps.push(key);\n }\n });\n}\n\n// Passthrough native el functions from the custom el to the native el\nnativeElProps.forEach((prop) => {\n const type = typeof nativeElTest[prop];\n\n if (type == 'function') {\n // Function\n CustomAudioElement.prototype[prop] = function () {\n return this.nativeEl[prop].apply(this.nativeEl, arguments);\n };\n } else {\n // Getter\n let config = {\n get() {\n return this.nativeEl[prop];\n },\n };\n\n if (prop !== prop.toUpperCase()) {\n // Setter (not a CONSTANT)\n config.set = function (val) {\n this.nativeEl[prop] = val;\n };\n }\n\n Object.defineProperty(CustomAudioElement.prototype, prop, config);\n }\n});\n\nfunction arrayFindAnyCase(arr, word) {\n let found = null;\n\n arr.forEach((item) => {\n if (item.toLowerCase() == word.toLowerCase()) {\n found = item;\n }\n });\n\n return found;\n}\n\nif (!globalThis.customElements.get('custom-audio')) {\n globalThis.customElements.define('custom-audio', CustomAudioElement);\n globalThis.CustomAudioElement = CustomAudioElement;\n}\n\nexport default CustomAudioElement;\n"],
|
|
5
|
+
"mappings": "mlBAAA,+EAYO,iCCRP,GAAM,GAAsB,IAAM,CAChC,GAAI,CAEF,MAAO,8BACP,EACF,MAAO,WAGH,EAAyB,IAElB,EAAmB,IAAM,ECP/B,GAAM,GAAc,CACzB,QACA,UACA,iBACA,iBACA,UACA,QACA,QACA,aACA,iBACA,YACA,QACA,OACA,UACA,WACA,aACA,SACA,UACA,UACA,UACA,aACA,eACA,WAGI,EAAW,SAAS,cAAc,YAGxC,EAAS,UAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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AAK,mBAAL,kBAAwB,GACxB,UACG,GAAW,YAEd,KAAK,IAAM,oBAAc,UAAY,QACrC,UACG,GAAW,MACd,GAAM,GAAQ,KAAK,MACnB,AAAM,KAAK,KAET,QAAQ,KACN,iIAGE,KAAK,MACT,MAAK,KAAK,OAAO,MAAQ,GAE3B,UACG,GAAW,aACd,AAAI,GACF,MAAM,GACH,KAAK,AAAC,GAAS,EAAK,QACpB,KAAK,AAAC,GAAU,KAAK,SAAW,GAChC,MAAM,AAAC,GAAS,QAAQ,MAAM,2DAA2D,OAE9F,cAEA,MAGJ,MAAM,yBAAyB,EAAU,EAAU,GAGrD,sBAAuB,CACrB,KAAK,WAST,AAAK,WAAW,eAAe,IAAI,cACjC,YAAW,eAAe,OAAO,YAAa,GAE9C,WAAW,gBAAkB,GAK/B,GAAO,GAAQ",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import{initialize as T,setupAutoplay as M,toMuxVideoURL as O,teardown as C,generatePlayerInitTime as I,MediaError as Y}from"@mux/playback-core";var A=()=>{try{return"0.5.7-canary.0-556dabf"}catch{}return"UNKNOWN"},y=A(),h=()=>y;var m=["abort","canplay","canplaythrough","durationchange","emptied","ended","error","loadeddata","loadedmetadata","loadstart","pause","play","playing","progress","ratechange","seeked","seeking","stalled","suspend","timeupdate","volumechange","waiting"],E=document.createElement("template");E.innerHTML=`
|
|
2
|
+
<style>
|
|
3
|
+
:host {
|
|
4
|
+
/* display:inline (like the native el) makes it so you can't fill
|
|
5
|
+
the container with the native el */
|
|
6
|
+
display: inline-block;
|
|
7
|
+
box-sizing: border-box;
|
|
8
|
+
|
|
9
|
+
width: auto;
|
|
10
|
+
height: auto;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
audio {
|
|
14
|
+
max-width: 100%;
|
|
15
|
+
max-height: 100%;
|
|
16
|
+
min-width: 100%;
|
|
17
|
+
min-height: 100%;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
</style>
|
|
21
|
+
|
|
22
|
+
<audio part="audio" crossorigin></audio>
|
|
23
|
+
<slot></slot>
|
|
24
|
+
`;var o=class extends HTMLElement{constructor(){super();this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(E.content.cloneNode(!0));let t=this.nativeEl=this.shadowRoot.querySelector("audio");Array.from(this.attributes).forEach(e=>{this.forwardAttribute(e.name,null,e.value)}),t.defaultMuted&&(t.muted=!0),m.forEach(e=>{t.addEventListener(e,r=>{this.dispatchEvent(new CustomEvent(r.type,{detail:r.detail}))})});let s=this.shadowRoot.querySelector("slot");s.addEventListener("slotchange",()=>{s.assignedElements().forEach(e=>{t.appendChild(e)})})}static get observedAttributes(){let t=[];Object.getOwnPropertyNames(this.prototype).forEach(e=>{let r=!1;try{typeof this.prototype[e]=="function"&&(r=!0)}catch{}!r&&e!==e.toUpperCase()&&t.push(e.toLowerCase())});let s=Object.getPrototypeOf(this).observedAttributes;return s&&(t=t.concat(s)),t}attributeChangedCallback(t,s,e){this.forwardAttribute(t,s,e)}forwardAttribute(t,s,e){let r=Object.getOwnPropertyNames(Object.getPrototypeOf(this)),n=_(r,t),u=Object.getPrototypeOf(this.constructor).toString().indexOf("function HTMLElement")===0;n&&!u?typeof this[n]=="boolean"?e===null?this[n]=!1:this[n]=!0:this[n]=e:e===null?this.nativeEl.removeAttribute(t):["id","class"].indexOf(t)===-1&&this.nativeEl.setAttribute(t,e)}connectedCallback(){}},f=[],p=document.createElement("audio"),g=["webkitDisplayingFullscreen","webkitSupportsFullscreen"];for(let a=Object.getPrototypeOf(p);a&&a!==HTMLElement.prototype;a=Object.getPrototypeOf(a))Object.keys(a).forEach(t=>{g.indexOf(t)===-1&&f.push(t)});f.forEach(a=>{if(typeof p[a]=="function")o.prototype[a]=function(){return this.nativeEl[a].apply(this.nativeEl,arguments)};else{let s={get(){return this.nativeEl[a]}};a!==a.toUpperCase()&&(s.set=function(e){this.nativeEl[a]=e}),Object.defineProperty(o.prototype,a,s)}});function _(a,t){let s=null;return a.forEach(e=>{e.toLowerCase()==t.toLowerCase()&&(s=e)}),s}globalThis.customElements.get("custom-audio")||(globalThis.customElements.define("custom-audio",o),globalThis.CustomAudioElement=o);var c=o;var i={ENV_KEY:"env-key",DEBUG:"debug",PLAYBACK_ID:"playback-id",METADATA_URL:"metadata-url",PREFER_MSE:"prefer-mse",METADATA_VIDEO_ID:"metadata-video-id",METADATA_VIDEO_TITLE:"metadata-video-title",METADATA_VIEWER_USER_ID:"metadata-viewer-user-id",BEACON_COLLECTION_DOMAIN:"beacon-collection-domain",TYPE:"type",STREAM_TYPE:"stream-type",START_TIME:"start-time"},P=Object.values(i),x=h(),v="mux-audio",d=class extends c{constructor(){super();this.__metadata={};this.__playerInitTime=I()}static get observedAttributes(){var t;return[...P,...(t=c.observedAttributes)!=null?t:[]]}get playerInitTime(){return this.__playerInitTime}get playerSoftwareName(){return v}get playerSoftwareVersion(){return x}get hls(){return console.warn("<mux-audio>.hls is deprecated, please use ._hls instead"),this._hls}get _hls(){return this.__hls}get mux(){return this.nativeEl.mux}get src(){return this.getAttribute("src")}set src(t){t!==this.src&&(t==null?this.removeAttribute("src"):this.setAttribute("src",t))}get debug(){return this.getAttribute(i.DEBUG)!=null}set debug(t){t!==this.debug&&(t?this.setAttribute(i.DEBUG,""):this.removeAttribute(i.DEBUG))}get startTime(){let t=this.getAttribute(i.START_TIME);if(t==null)return;let s=+t;return Number.isNaN(s)?void 0:s}set startTime(t){t!==this.startTime&&(t==null?this.removeAttribute(i.START_TIME):this.setAttribute(i.START_TIME,`${t}`))}get playbackId(){var t;return(t=this.getAttribute(i.PLAYBACK_ID))!=null?t:void 0}set playbackId(t){t!==this.playbackId&&(t?this.setAttribute(i.PLAYBACK_ID,t):this.removeAttribute(i.PLAYBACK_ID))}get envKey(){var t;return(t=this.getAttribute(i.ENV_KEY))!=null?t:void 0}set envKey(t){t!==this.envKey&&(t?this.setAttribute(i.ENV_KEY,t):this.removeAttribute(i.ENV_KEY))}get beaconCollectionDomain(){var t;return(t=this.getAttribute(i.BEACON_COLLECTION_DOMAIN))!=null?t:void 0}set beaconCollectionDomain(t){t!==this.beaconCollectionDomain&&(t?this.setAttribute(i.BEACON_COLLECTION_DOMAIN,t):this.removeAttribute(i.BEACON_COLLECTION_DOMAIN))}get streamType(){var t;return(t=this.getAttribute(i.STREAM_TYPE))!=null?t:void 0}set streamType(t){t!==this.streamType&&(t?this.setAttribute(i.STREAM_TYPE,t):this.removeAttribute(i.STREAM_TYPE))}get preferMse(){return this.getAttribute(i.PREFER_MSE)!=null}set preferMse(t){t?this.setAttribute(i.PREFER_MSE,""):this.removeAttribute(i.PREFER_MSE)}get metadata(){return this.__metadata}set metadata(t){this.__metadata=t!=null?t:{},this.mux&&(console.info("Some metadata values may not be overridable at this time. Make sure you set all metadata to override before setting the src."),this.mux.emit("hb",this.__metadata))}load(){let t=T(this,this.nativeEl,this.__hls);this.__hls=t;let s=M(this.nativeEl,this.autoplay,t);this.__updateAutoplay=s}unload(){C(this.nativeEl,this.__hls),this.__hls=void 0}attributeChangedCallback(t,s,e){var r;switch(t){case"src":let n=!!s,u=!!e;!n&&u?this.load():n&&!u?this.unload():n&&u&&(this.unload(),this.load());break;case"autoplay":(r=this.__updateAutoplay)==null||r.call(this,e);break;case i.PLAYBACK_ID:this.src=O(e!=null?e:void 0);break;case i.DEBUG:let b=this.debug;this.mux&&console.info("Cannot toggle debug mode of mux data after initialization. Make sure you set all metadata to override before setting the src."),this._hls&&(this._hls.config.debug=b);break;case i.METADATA_URL:e&&fetch(e).then(l=>l.json()).then(l=>this.metadata=l).catch(l=>console.error(`Unable to load or parse metadata JSON from metadata-url ${e}!`));break;default:break}super.attributeChangedCallback(t,s,e)}disconnectedCallback(){this.unload()}};globalThis.customElements.get("mux-audio")||(globalThis.customElements.define("mux-audio",d),globalThis.MuxAudioElement=d);var j=d;export{m as AudioEvents,Y as MediaError,j as default};
|
|
25
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts", "../src/env.ts", "../src/CustomAudioElement.js"],
|
|
4
|
+
"sourcesContent": ["import {\n initialize,\n setupAutoplay,\n MuxMediaProps,\n StreamTypes,\n ValueOf,\n toMuxVideoURL,\n teardown,\n Metadata,\n mux,\n generatePlayerInitTime,\n MediaError,\n} from '@mux/playback-core';\nimport type { PlaybackEngine, UpdateAutoplay, ExtensionMimeTypeMap } from '@mux/playback-core';\nimport { getPlayerVersion } from './env';\n// this must be imported after playback-core for the polyfill to be included\nimport CustomAudioElement, { AudioEvents } from './CustomAudioElement';\n\n/** @TODO make the relationship between name+value smarter and more deriveable (CJP) */\ntype AttributeNames = {\n ENV_KEY: 'env-key';\n DEBUG: 'debug';\n METADATA_URL: 'metadata-url';\n METADATA_VIDEO_ID: 'metadata-video-id';\n METADATA_VIDEO_TITLE: 'metadata-video-title';\n METADATA_VIEWER_USER_ID: 'metadata-viewer-user-id';\n BEACON_COLLECTION_DOMAIN: 'beacon-collection-domain';\n PLAYBACK_ID: 'playback-id';\n PREFER_MSE: 'prefer-mse';\n TYPE: 'type';\n STREAM_TYPE: 'stream-type';\n START_TIME: 'start-time';\n};\n\nconst Attributes: AttributeNames = {\n ENV_KEY: 'env-key',\n DEBUG: 'debug',\n PLAYBACK_ID: 'playback-id',\n METADATA_URL: 'metadata-url',\n PREFER_MSE: 'prefer-mse',\n METADATA_VIDEO_ID: 'metadata-video-id',\n METADATA_VIDEO_TITLE: 'metadata-video-title',\n METADATA_VIEWER_USER_ID: 'metadata-viewer-user-id',\n BEACON_COLLECTION_DOMAIN: 'beacon-collection-domain',\n TYPE: 'type',\n STREAM_TYPE: 'stream-type',\n START_TIME: 'start-time',\n};\n\nconst AttributeNameValues = Object.values(Attributes);\n\nconst playerSoftwareVersion = getPlayerVersion();\nconst playerSoftwareName = 'mux-audio';\n\nclass MuxAudioElement extends CustomAudioElement<HTMLAudioElement> implements Partial<MuxMediaProps> {\n static get observedAttributes() {\n return [...AttributeNameValues, ...(CustomAudioElement.observedAttributes ?? [])];\n }\n\n // Keeping this named \"__hls\" since it's exposed for unadvertised \"advanced usage\" via getter that assumes specifically hls.js (CJP)\n protected __hls?: PlaybackEngine;\n protected __playerInitTime: number;\n protected __metadata: Readonly<Metadata> = {};\n protected __updateAutoplay?: UpdateAutoplay;\n\n constructor() {\n super();\n this.__playerInitTime = generatePlayerInitTime();\n }\n\n get playerInitTime() {\n return this.__playerInitTime;\n }\n\n get playerSoftwareName() {\n return playerSoftwareName;\n }\n\n get playerSoftwareVersion() {\n return playerSoftwareVersion;\n }\n\n /**\n * @deprecated please use ._hls instead\n */\n get hls() {\n console.warn('<mux-audio>.hls is deprecated, please use ._hls instead');\n return this._hls;\n }\n\n get _hls() {\n return this.__hls;\n }\n\n get mux(): Readonly<HTMLAudioElement['mux']> | undefined {\n return this.nativeEl.mux;\n }\n\n get src() {\n // Use the attribute value as the source of truth.\n // No need to store it in two places.\n // This avoids needing a to read the attribute initially and update the src.\n return this.getAttribute('src') as string;\n }\n\n set src(val: string) {\n // If being set by attributeChangedCallback,\n // dont' cause an infinite loop\n if (val === this.src) return;\n\n if (val == null) {\n this.removeAttribute('src');\n } else {\n this.setAttribute('src', val);\n }\n }\n\n /** @TODO write a generic module for well defined primitive types -> attribute getter/setters/removers (CJP) */\n get debug(): boolean {\n return this.getAttribute(Attributes.DEBUG) != null;\n }\n\n set debug(val: boolean) {\n // dont' cause an infinite loop\n if (val === this.debug) return;\n\n if (val) {\n this.setAttribute(Attributes.DEBUG, '');\n } else {\n this.removeAttribute(Attributes.DEBUG);\n }\n }\n\n get startTime(): number | undefined {\n const val = this.getAttribute(Attributes.START_TIME);\n if (val == null) return undefined;\n const num = +val;\n return !Number.isNaN(num) ? num : undefined;\n }\n\n set startTime(val: number | undefined) {\n // dont' cause an infinite loop\n if (val === this.startTime) return;\n\n if (val == null) {\n this.removeAttribute(Attributes.START_TIME);\n } else {\n this.setAttribute(Attributes.START_TIME, `${val}`);\n }\n }\n\n get playbackId(): string | undefined {\n return this.getAttribute(Attributes.PLAYBACK_ID) ?? undefined;\n }\n\n set playbackId(val: string | undefined) {\n // dont' cause an infinite loop\n if (val === this.playbackId) return;\n\n if (val) {\n this.setAttribute(Attributes.PLAYBACK_ID, val);\n } else {\n this.removeAttribute(Attributes.PLAYBACK_ID);\n }\n }\n\n get envKey(): string | undefined {\n return this.getAttribute(Attributes.ENV_KEY) ?? undefined;\n }\n\n set envKey(val: string | undefined) {\n // dont' cause an infinite loop\n if (val === this.envKey) return;\n\n if (val) {\n this.setAttribute(Attributes.ENV_KEY, val);\n } else {\n this.removeAttribute(Attributes.ENV_KEY);\n }\n }\n\n get beaconCollectionDomain(): string | undefined {\n return this.getAttribute(Attributes.BEACON_COLLECTION_DOMAIN) ?? undefined;\n }\n\n set beaconCollectionDomain(val: string | undefined) {\n // dont' cause an infinite loop\n if (val === this.beaconCollectionDomain) return;\n\n if (val) {\n this.setAttribute(Attributes.BEACON_COLLECTION_DOMAIN, val);\n } else {\n this.removeAttribute(Attributes.BEACON_COLLECTION_DOMAIN);\n }\n }\n\n get streamType(): ValueOf<StreamTypes> | undefined {\n // getAttribute doesn't know that this attribute is well defined. Should explore extending for MuxVideo (CJP)\n return (this.getAttribute(Attributes.STREAM_TYPE) as ValueOf<StreamTypes>) ?? undefined;\n }\n\n set streamType(val: ValueOf<StreamTypes> | undefined) {\n // dont' cause an infinite loop\n if (val === this.streamType) return;\n\n if (val) {\n this.setAttribute(Attributes.STREAM_TYPE, val);\n } else {\n this.removeAttribute(Attributes.STREAM_TYPE);\n }\n }\n\n /** @TODO Followup: naming convention: all lower (common per HTMLElement props) vs. camel (common per JS convention) (CJP) */\n get preferMse(): boolean {\n return this.getAttribute(Attributes.PREFER_MSE) != null;\n }\n\n set preferMse(val: boolean) {\n if (val) {\n this.setAttribute(Attributes.PREFER_MSE, '');\n } else {\n this.removeAttribute(Attributes.PREFER_MSE);\n }\n }\n\n get metadata() {\n return this.__metadata;\n }\n\n set metadata(val: Readonly<Metadata> | undefined) {\n this.__metadata = val ?? {};\n if (!!this.mux) {\n /** @TODO Link to docs for a more detailed discussion (CJP) */\n console.info(\n 'Some metadata values may not be overridable at this time. Make sure you set all metadata to override before setting the src.'\n );\n this.mux.emit('hb', this.__metadata);\n }\n }\n\n load() {\n const nextHlsInstance = initialize(this as Partial<MuxMediaProps>, this.nativeEl, this.__hls);\n this.__hls = nextHlsInstance;\n const updateAutoplay = setupAutoplay(this.nativeEl, this.autoplay, nextHlsInstance);\n this.__updateAutoplay = updateAutoplay;\n }\n\n unload() {\n teardown(this.nativeEl, this.__hls);\n this.__hls = undefined;\n }\n\n attributeChangedCallback(attrName: string, oldValue: string | null, newValue: string | null) {\n switch (attrName) {\n case 'src':\n const hadSrc = !!oldValue;\n const hasSrc = !!newValue;\n if (!hadSrc && hasSrc) {\n this.load();\n } else if (hadSrc && !hasSrc) {\n this.unload();\n /** @TODO Test this thoroughly (async?) and confirm unload() necessary (CJP) */\n } else if (hadSrc && hasSrc) {\n this.unload();\n this.load();\n }\n break;\n case 'autoplay':\n this.__updateAutoplay?.(newValue);\n break;\n case Attributes.PLAYBACK_ID:\n /** @TODO Improv+Discuss - how should playback-id update wrt src attr changes (and vice versa) (CJP) */\n this.src = toMuxVideoURL(newValue ?? undefined) as string;\n break;\n case Attributes.DEBUG:\n const debug = this.debug;\n if (!!this.mux) {\n /** @TODO Link to docs for a more detailed discussion (CJP) */\n console.info(\n 'Cannot toggle debug mode of mux data after initialization. Make sure you set all metadata to override before setting the src.'\n );\n }\n if (!!this._hls) {\n this._hls.config.debug = debug;\n }\n break;\n case Attributes.METADATA_URL:\n if (newValue) {\n fetch(newValue)\n .then((resp) => resp.json())\n .then((json) => (this.metadata = json))\n .catch((_err) => console.error(`Unable to load or parse metadata JSON from metadata-url ${newValue}!`));\n }\n break;\n default:\n break;\n }\n\n super.attributeChangedCallback(attrName, oldValue, newValue);\n }\n\n disconnectedCallback() {\n this.unload();\n }\n}\n\ntype MuxAudioElementType = typeof MuxAudioElement;\ndeclare global {\n var MuxAudioElement: MuxAudioElementType;\n}\n\nif (!globalThis.customElements.get('mux-audio')) {\n globalThis.customElements.define('mux-audio', MuxAudioElement);\n /** @TODO consider externalizing this (breaks standard modularity) */\n globalThis.MuxAudioElement = MuxAudioElement;\n}\n\nexport { PlaybackEngine, PlaybackEngine as Hls, ExtensionMimeTypeMap as MimeTypes, MediaError, AudioEvents };\n\nexport default MuxAudioElement;\n", "export const isMaybeBrowser = () => typeof window != 'undefined';\n// @ts-ignore\nexport const isMaybeServer = () => typeof global != 'undefined';\n\nconst getEnvPlayerVersion = () => {\n try {\n // @ts-ignore\n return PLAYER_VERSION as string;\n } catch {}\n return 'UNKNOWN';\n};\n\nconst player_version: string = getEnvPlayerVersion();\n\nexport const getPlayerVersion = () => player_version;\n", "/**\n * Custom Audio Element\n * The goal is to create an element that works just like the audio element\n * but can be extended/sub-classed, because native elements cannot be\n * extended today across browsers.\n */\n\nexport const AudioEvents = [\n 'abort',\n 'canplay',\n 'canplaythrough',\n 'durationchange',\n 'emptied',\n 'ended',\n 'error',\n 'loadeddata',\n 'loadedmetadata',\n 'loadstart',\n 'pause',\n 'play',\n 'playing',\n 'progress',\n 'ratechange',\n 'seeked',\n 'seeking',\n 'stalled',\n 'suspend',\n 'timeupdate',\n 'volumechange',\n 'waiting',\n];\n\nconst template = document.createElement('template');\n// Could you get styles to apply by passing a global button from global to shadow?\n\ntemplate.innerHTML = `\n<style>\n :host {\n /* display:inline (like the native el) makes it so you can't fill\n the container with the native el */\n display: inline-block;\n box-sizing: border-box;\n\n width: auto;\n height: auto;\n }\n\n audio {\n max-width: 100%;\n max-height: 100%;\n min-width: 100%;\n min-height: 100%;\n }\n\n</style>\n\n<audio part=\"audio\" crossorigin></audio>\n<slot></slot>\n`;\n\nclass CustomAudioElement extends HTMLElement {\n constructor() {\n super();\n\n this.attachShadow({ mode: 'open' });\n this.shadowRoot.appendChild(template.content.cloneNode(true));\n const nativeEl = (this.nativeEl = this.shadowRoot.querySelector('audio'));\n\n // Initialize all the attribute properties\n // This is required before attributeChangedCallback is called after construction\n // so the initial state of all the attributes are forwarded to the native element.\n Array.from(this.attributes).forEach((attrNode) => {\n this.forwardAttribute(attrNode.name, null, attrNode.value);\n });\n\n // Neither Chrome or Firefox support setting the muted attribute\n // after using document.createElement.\n // One way to get around this would be to build the native tag as a string.\n // But just fixing it manually for now.\n // Apparently this may also be an issue with <input checked> for buttons\n if (nativeEl.defaultMuted) {\n nativeEl.muted = true;\n }\n\n // The audio events are dispatched on the CustomAudioElement instance.\n // This makes it possible to add event listeners before the element is upgraded.\n AudioEvents.forEach((type) => {\n nativeEl.addEventListener(type, (evt) => {\n this.dispatchEvent(new CustomEvent(evt.type, { detail: evt.detail }));\n });\n });\n\n const slotEl = this.shadowRoot.querySelector('slot');\n slotEl.addEventListener('slotchange', () => {\n slotEl.assignedElements().forEach((el) => {\n nativeEl.appendChild(el);\n });\n });\n }\n\n // observedAttributes is required to trigger attributeChangedCallback\n // for any attributes on the custom element.\n // Attributes need to be the lowercase word, e.g. crossorigin, not crossOrigin\n static get observedAttributes() {\n let attrs = [];\n\n // Instead of manually creating a list of all observed attributes,\n // observe any getter/setter prop name (lowercased)\n Object.getOwnPropertyNames(this.prototype).forEach((propName) => {\n let isFunc = false;\n\n // Non-func properties throw errors because it's not an instance\n try {\n if (typeof this.prototype[propName] === 'function') {\n isFunc = true;\n }\n } catch (e) {}\n\n // Exclude functions and constants\n if (!isFunc && propName !== propName.toUpperCase()) {\n attrs.push(propName.toLowerCase());\n }\n });\n\n // Include any attributes from the super class (recursive)\n const supAttrs = Object.getPrototypeOf(this).observedAttributes;\n\n if (supAttrs) {\n attrs = attrs.concat(supAttrs);\n }\n\n return attrs;\n }\n\n // We need to handle sub-class custom attributes differently from\n // attrs meant to be passed to the internal native el.\n attributeChangedCallback(attrName, oldValue, newValue) {\n this.forwardAttribute(attrName, oldValue, newValue);\n }\n\n forwardAttribute(attrName, oldValue, newValue) {\n // Find the matching prop for custom attributes\n const ownProps = Object.getOwnPropertyNames(Object.getPrototypeOf(this));\n const propName = arrayFindAnyCase(ownProps, attrName);\n\n // Check if this is the original custom native elemnt or a subclass\n const isBaseElement = Object.getPrototypeOf(this.constructor).toString().indexOf('function HTMLElement') === 0;\n\n // If this is a subclass custom attribute we want to set the\n // matching property on the subclass\n if (propName && !isBaseElement) {\n // Boolean props should never start as null\n if (typeof this[propName] == 'boolean') {\n // null is returned when attributes are removed i.e. boolean attrs\n if (newValue === null) {\n this[propName] = false;\n } else {\n // The new value might be an empty string, which is still true\n // for boolean attributes\n this[propName] = true;\n }\n } else {\n this[propName] = newValue;\n }\n } else {\n // When this is the original Custom Element, or the subclass doesn't\n // have a matching prop, pass it through.\n if (newValue === null) {\n this.nativeEl.removeAttribute(attrName);\n } else {\n // Ignore a few that don't need to be passed through just in case\n // it creates unexpected behavior.\n if (['id', 'class'].indexOf(attrName) === -1) {\n this.nativeEl.setAttribute(attrName, newValue);\n }\n }\n }\n }\n\n connectedCallback() {}\n}\n\n// Map all native element properties to the custom element\n// so that they're applied to the native element.\n// Skipping HTMLElement because of things like \"attachShadow\"\n// causing issues. Most of those props still need to apply to\n// the custom element.\n// But includign EventTarget props because most events emit from\n// the native element.\nlet nativeElProps = [];\n\n// Can't check typeof directly on element prototypes without\n// throwing Illegal Invocation errors, so creating an element\n// to check on instead.\nconst nativeElTest = document.createElement('audio');\n\n// Deprecated props throw warnings if used, so exclude them\nconst deprecatedProps = ['webkitDisplayingFullscreen', 'webkitSupportsFullscreen'];\n\n// Walk the prototype chain up to HTMLElement.\n// This will grab all super class props in between.\n// i.e. AudioElement and MediaElement\nfor (\n let proto = Object.getPrototypeOf(nativeElTest);\n proto && proto !== HTMLElement.prototype;\n proto = Object.getPrototypeOf(proto)\n) {\n Object.keys(proto).forEach((key) => {\n if (deprecatedProps.indexOf(key) === -1) {\n nativeElProps.push(key);\n }\n });\n}\n\n// Passthrough native el functions from the custom el to the native el\nnativeElProps.forEach((prop) => {\n const type = typeof nativeElTest[prop];\n\n if (type == 'function') {\n // Function\n CustomAudioElement.prototype[prop] = function () {\n return this.nativeEl[prop].apply(this.nativeEl, arguments);\n };\n } else {\n // Getter\n let config = {\n get() {\n return this.nativeEl[prop];\n },\n };\n\n if (prop !== prop.toUpperCase()) {\n // Setter (not a CONSTANT)\n config.set = function (val) {\n this.nativeEl[prop] = val;\n };\n }\n\n Object.defineProperty(CustomAudioElement.prototype, prop, config);\n }\n});\n\nfunction arrayFindAnyCase(arr, word) {\n let found = null;\n\n arr.forEach((item) => {\n if (item.toLowerCase() == word.toLowerCase()) {\n found = item;\n }\n });\n\n return found;\n}\n\nif (!globalThis.customElements.get('custom-audio')) {\n globalThis.customElements.define('custom-audio', CustomAudioElement);\n globalThis.CustomAudioElement = CustomAudioElement;\n}\n\nexport default CustomAudioElement;\n"],
|
|
5
|
+
"mappings": "AAAA,gJCIA,GAAM,GAAsB,IAAM,CAChC,GAAI,CAEF,MAAO,8BACP,EACF,MAAO,WAGH,EAAyB,IAElB,EAAmB,IAAM,ECP/B,GAAM,GAAc,CACzB,QACA,UACA,iBACA,iBACA,UACA,QACA,QACA,aACA,iBACA,YACA,QACA,OACA,UACA,WACA,aACA,SACA,UACA,UACA,UACA,aACA,eACA,WAGI,EAAW,SAAS,cAAc,YAGxC,EAAS,UAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBrB,mBAAiC,YAAY,CAC3C,aAAc,CACZ,QAEA,KAAK,aAAa,CAAE,KAAM,SAC1B,KAAK,WAAW,YAAY,EAAS,QAAQ,UAAU,KACvD,GAAM,GAAY,KAAK,SAAW,KAAK,WAAW,cAAc,SAKhE,MAAM,KAAK,KAAK,YAAY,QAAQ,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