New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@mux/mux-player

Package Overview
Dependencies
Maintainers
2
Versions
601
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mux/mux-player - npm Package Compare versions

Comparing version 0.1.0-canary.10-2039108 to 0.1.0-canary.10-2d61f80

src/media-theme-mux/icons/cast-enter.svg

20

CHANGELOG.md

@@ -6,2 +6,22 @@ # Change Log

# [0.1.0-beta.24](https://github.com/muxinc/elements/compare/@mux/mux-player@0.1.0-beta.23...@mux/mux-player@0.1.0-beta.24) (2022-07-21)
### Bug Fixes
- add Mux flavor cast icon & fix xs size bug ([#299](https://github.com/muxinc/elements/issues/299)) ([8374ff1](https://github.com/muxinc/elements/commit/8374ff17e294cbe3ad899749ab0361b78ffe0274))
- **mux-player:** Clean up how metadata is set from mux-player to underlying mux-video element. Force upgrades and init when setting metadata. ([d3b2347](https://github.com/muxinc/elements/commit/d3b2347b1d4d7ebbbd882879f69e9d082f12dd80))
- upgrade MC to v0.8.0 and adjust time range styles ([#294](https://github.com/muxinc/elements/issues/294)) ([030fdc6](https://github.com/muxinc/elements/commit/030fdc649517a538fc89c5b3d9edca42e58634ef))
- upgrade MC v0.8.1 ([#298](https://github.com/muxinc/elements/issues/298)) ([fc4a74c](https://github.com/muxinc/elements/commit/fc4a74cfaadf90ee8d4ed89751755d56e77df79e))
### Features
- add ability to choose a Media Theme via attribute ([#269](https://github.com/muxinc/elements/issues/269)) ([77d0386](https://github.com/muxinc/elements/commit/77d0386606d5ecccb7c322ce487c9287d16374fd))
- add defaultMuted, defaultPlaybackRate props ([#252](https://github.com/muxinc/elements/issues/252)) ([1a72165](https://github.com/muxinc/elements/commit/1a7216545cba27b34bc743cf5dd6225d4dcae738))
- **mux-player:** Add textTracks prop alongside add/remove tracks methods. ([c041a72](https://github.com/muxinc/elements/commit/c041a72ce414fc52fcd90e22cc7730ef2e349c31))
- **playback-core, mux-player:** Add support to removeTextTrack. Remove all identified tracks on hls destroy. Add methods to mux-player. ([d090b06](https://github.com/muxinc/elements/commit/d090b060a8b8b3772e74762176af9881299bf894))
# [0.1.0-beta.23](https://github.com/muxinc/elements/compare/@mux/mux-player@0.1.0-beta.22...@mux/mux-player@0.1.0-beta.23) (2022-07-11)
**Note:** Version bump only for package @mux/mux-player
# [0.1.0-beta.22](https://github.com/muxinc/elements/compare/@mux/mux-player@0.1.0-beta.21...@mux/mux-player@0.1.0-beta.22) (2022-07-05)

@@ -8,0 +28,0 @@

4

dist/types-ts3.4/helpers.d.ts

@@ -16,6 +16,4 @@ import MuxPlayerElement from '.';

}) => string;
export declare function castThemeName(themeName?: string): string | undefined;
export declare function toPropName(attrName: string): string;
export declare const getTestMediaEl: (nodeName?: string) => HTMLMediaElement | undefined;
export declare const hasVolumeSupportAsync: (mediaEl?: HTMLMediaElement | undefined) => Promise<boolean>;
export declare function getCcSubTracks(el: MuxPlayerElement): TextTrack[];
export declare const getLiveTime: (el: MuxPlayerElement) => number | undefined;

@@ -22,0 +20,0 @@ export declare const seekToLive: (el: MuxPlayerElement) => void;

@@ -19,1 +19,6 @@ import { TemplateInstance, NodeTemplatePart } from '@github/template-parts';

export declare function createTemplateInstance(content: string, props?: any): TemplateInstance;
export declare const unsafeStatic: (...values: any[]) => {
$static$: (TemplateResult | {
strings: any[];
})[];
};

@@ -12,5 +12,2 @@ import '@mux/playback-core';

};
declare type MediaController = Element & {
media: HTMLVideoElement;
};
declare class MuxPlayerElement extends VideoApiElement {

@@ -179,4 +176,7 @@ private "MuxPlayerElement.#private";

storyboardToken: string | undefined;
addTextTrack(kind: TextTrackKind, label: string, lang?: string, id?: string): TextTrack | undefined;
removeTextTrack(track: TextTrack): void;
readonly textTracks: TextTrackList | undefined;
}
export declare function getVideoAttribute(el: MuxPlayerElement, name: string): string | null;
export default MuxPlayerElement;
export declare const Airplay: () => import("@github/template-parts").TemplateInstance;
export declare const CaptionsOff: () => import("@github/template-parts").TemplateInstance;
export declare const CaptionsOn: () => import("@github/template-parts").TemplateInstance;
export declare const CastEnter: () => import("@github/template-parts").TemplateInstance;
export declare const CastExit: () => import("@github/template-parts").TemplateInstance;
export declare const FullscreenEnter: () => import("@github/template-parts").TemplateInstance;

@@ -5,0 +7,0 @@ export declare const FullscreenExit: () => import("@github/template-parts").TemplateInstance;

@@ -1,15 +0,19 @@

import 'media-chrome';
import { MediaTheme } from 'media-chrome';
import '../media-chrome/time-display';
declare type ThemeMuxTemplateProps = {
streamType: string;
streamType: string | null;
audio: boolean;
playerSize: string;
playerSize: string | null;
defaultHiddenCaptions: boolean;
hasCaptions: boolean;
forwardSeekOffset: number;
backwardSeekOffset: number;
forwardSeekOffset: string | null;
backwardSeekOffset: string | null;
};
export default class MediaThemeMux extends MediaTheme {
static readonly observedAttributes: string[];
attributeChangedCallback(): void;
render(): void;
}
export declare const AudioVodChrome: (props: ThemeMuxTemplateProps) => import("../html").TemplateResult;
export declare const AudioDvrChrome: (props: ThemeMuxTemplateProps) => import("../html").TemplateResult;
export declare const AudioLiveChrome: (_props: ThemeMuxTemplateProps) => import("../html").TemplateResult;
export declare const AudioLiveChrome: () => import("../html").TemplateResult;
export declare const VodChromeExtraSmall: (props: ThemeMuxTemplateProps) => import("../html").TemplateResult;

@@ -24,7 +28,2 @@ export declare const VodChromeSmall: (props: ThemeMuxTemplateProps) => import("../html").TemplateResult;

export declare const DvrChromeLarge: (props: ThemeMuxTemplateProps) => import("../html").TemplateResult;
declare class MediaThemeMux extends HTMLElement {
static readonly observedAttributes: string[];
constructor();
attributeChangedCallback(): void;
}
export default MediaThemeMux;
export {};

@@ -46,2 +46,3 @@ import MuxVideoElement from '@mux/mux-video';

playbackRate: number;
defaultPlaybackRate: number;
crossOrigin: string | null;

@@ -51,2 +52,3 @@ autoplay: boolean;

muted: boolean;
defaultMuted: boolean;
playsInline: boolean;

@@ -53,0 +55,0 @@ preload: string | null;

@@ -16,6 +16,4 @@ import type MuxPlayerElement from '.';

}) => string;
export declare function castThemeName(themeName?: string): string | undefined;
export declare function toPropName(attrName: string): string;
export declare const getTestMediaEl: (nodeName?: string) => HTMLMediaElement | undefined;
export declare const hasVolumeSupportAsync: (mediaEl?: HTMLMediaElement | undefined) => Promise<boolean>;
export declare function getCcSubTracks(el: MuxPlayerElement): TextTrack[];
export declare const getLiveTime: (el: MuxPlayerElement) => number | undefined;

@@ -22,0 +20,0 @@ export declare const seekToLive: (el: MuxPlayerElement) => void;

@@ -19,1 +19,6 @@ import { TemplateInstance, NodeTemplatePart } from '@github/template-parts';

export declare function createTemplateInstance(content: string, props?: any): TemplateInstance;
export declare const unsafeStatic: (...values: any[]) => {
$static$: (TemplateResult | {
strings: any[];
})[];
};

@@ -12,5 +12,2 @@ import '@mux/playback-core';

};
declare type MediaController = Element & {
media: HTMLVideoElement;
};
declare class MuxPlayerElement extends VideoApiElement {

@@ -198,4 +195,7 @@ #private;

set storyboardToken(val: string | undefined);
addTextTrack(kind: TextTrackKind, label: string, lang?: string, id?: string): TextTrack | undefined;
removeTextTrack(track: TextTrack): void;
get textTracks(): TextTrackList | undefined;
}
export declare function getVideoAttribute(el: MuxPlayerElement, name: string): string | null;
export default MuxPlayerElement;
export declare const Airplay: () => import("@github/template-parts").TemplateInstance;
export declare const CaptionsOff: () => import("@github/template-parts").TemplateInstance;
export declare const CaptionsOn: () => import("@github/template-parts").TemplateInstance;
export declare const CastEnter: () => import("@github/template-parts").TemplateInstance;
export declare const CastExit: () => import("@github/template-parts").TemplateInstance;
export declare const FullscreenEnter: () => import("@github/template-parts").TemplateInstance;

@@ -5,0 +7,0 @@ export declare const FullscreenExit: () => import("@github/template-parts").TemplateInstance;

@@ -1,15 +0,19 @@

import 'media-chrome';
import { MediaTheme } from 'media-chrome';
import '../media-chrome/time-display';
declare type ThemeMuxTemplateProps = {
streamType: string;
streamType: string | null;
audio: boolean;
playerSize: string;
playerSize: string | null;
defaultHiddenCaptions: boolean;
hasCaptions: boolean;
forwardSeekOffset: number;
backwardSeekOffset: number;
forwardSeekOffset: string | null;
backwardSeekOffset: string | null;
};
export default class MediaThemeMux extends MediaTheme {
static get observedAttributes(): string[];
attributeChangedCallback(): void;
render(): void;
}
export declare const AudioVodChrome: (props: ThemeMuxTemplateProps) => import("../html").TemplateResult;
export declare const AudioDvrChrome: (props: ThemeMuxTemplateProps) => import("../html").TemplateResult;
export declare const AudioLiveChrome: (_props: ThemeMuxTemplateProps) => import("../html").TemplateResult;
export declare const AudioLiveChrome: () => import("../html").TemplateResult;
export declare const VodChromeExtraSmall: (props: ThemeMuxTemplateProps) => import("../html").TemplateResult;

@@ -24,7 +28,2 @@ export declare const VodChromeSmall: (props: ThemeMuxTemplateProps) => import("../html").TemplateResult;

export declare const DvrChromeLarge: (props: ThemeMuxTemplateProps) => import("../html").TemplateResult;
declare class MediaThemeMux extends HTMLElement {
static get observedAttributes(): string[];
constructor();
attributeChangedCallback(): void;
}
export default MediaThemeMux;
export {};

@@ -51,2 +51,4 @@ import type MuxVideoElement from '@mux/mux-video';

set playbackRate(val: number);
get defaultPlaybackRate(): number;
set defaultPlaybackRate(val: number);
get crossOrigin(): string | null;

@@ -60,2 +62,4 @@ set crossOrigin(val: string | null);

set muted(val: boolean);
get defaultMuted(): boolean;
set defaultMuted(val: boolean);
get playsInline(): boolean;

@@ -62,0 +66,0 @@ set playsInline(val: boolean);

{
"name": "@mux/mux-player",
"version": "0.1.0-canary.10-2039108",
"version": "0.1.0-canary.10-2d61f80",
"description": "An open source Mux player web component that Just Works™",

@@ -54,5 +54,5 @@ "main": "./dist/index.cjs.js",

"@github/template-parts": "^0.5.3",
"@mux/mux-video": "0.8.1",
"@mux/playback-core": "0.8.0",
"media-chrome": "0.6.9"
"@mux/mux-video": "0.8.2",
"@mux/playback-core": "0.9.0",
"media-chrome": "0.8.1"
},

@@ -59,0 +59,0 @@ "devDependencies": {

@@ -81,3 +81,2 @@ <p align="center">

stream-type="on-demand"
controls
></mux-player>

@@ -99,3 +98,2 @@ </body>

metadata-viewer-user-id="user-id-1234"
controls
>

@@ -136,3 +134,2 @@ </mux-player>

prefer-mse
controls
>

@@ -168,6 +165,7 @@ </mux-player>

| `autoplay` | `boolean` | Toggles whether or not media should auto-play when initially loaded | false |
| `playback-rate` | `number` | Applies a multiplier to the media's playback rate, either speeding it up or slowing it down. | `1` |
| `playbackrate` | `number` | Applies a multiplier to the media's playback rate, either speeding it up or slowing it down. | `1` |
| `loop` | `boolean` | Automatically loop playback of your media when it finishes. | `false` |
| `poster` | `string` (URL) | Assigns a poster image URL. Will use the automatically generated poster based on your playback-id by default. | Derived |
| `beacon-collection-domain` | `string` (domain name) | Assigns a custom domain to be used for Mux Data collection. | N/A |
| `custom-domain` | `string` (domain name) | Assigns a custom domain to be used for Mux Video. | N/A |

@@ -185,10 +183,11 @@ ### Methods

| --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| `autoplay` | A `Boolean` that reflects the autoplay HTML attribute, indicating whether playback should automatically begin as soon as enough media is available to do so without interruption. | `false` |
| `autoplay` | A `Boolean` that reflects the `autoplay` HTML attribute, indicating whether playback should automatically begin as soon as enough media is available to do so without interruption. | `false` |
| `buffered` <sub><sup>Read only</sup></sub> | Returns a `TimeRanges` object that indicates the ranges of the media source that the browser has buffered (if any) at the moment the buffered property is accessed. | `undefined` |
| `controls` | Is a Boolean that reflects the controls HTML attribute, indicating whether user interface items for controlling the resource should be displayed. | `false` |
| `crossOrigin` | A DOMString indicating the CORS setting for this media element. | `null` |
| `currentTime` | A double-precision floating-point value indicating the current playback time in seconds; if the media has not started to play and has not been seeked, this value is the media's initial playback time. Setting this value seeks the media to the new time. The time is specified relative to the media's timeline. | `0` |
| `defaultMuted` | Is a `Boolean` that reflects the `muted` HTML attribute, determines whether audio is muted by default. `true` if the audio output should be muted by default and `false` otherwise. | `false` |
| `defaultPlaybackRate` | Is a double that reflects the `playbackrate` HTML attribute, it indicates the default playback rate for the media. | `1` |
| `duration` <sub><sup>Read only</sup></sub> | A read-only double-precision floating-point value indicating the total duration of the media in seconds. If no media data is available, the returned value is `NaN`. If the media is of indefinite length (such as streamed live media, a WebRTC call's media, or similar), the value is `+Infinity`. | `NaN` |
| `ended` <sub><sup>Read only</sup></sub> | Returns a `Boolean` that indicates whether the media element has finished playing. | `false` |
| `loop` | A `Boolean` that reflects the loop HTML attribute, which indicates whether the media element should start over when it reaches the end. | `false` |
| `loop` | A `Boolean` that reflects the `loop` HTML attribute, which indicates whether the media element should start over when it reaches the end. | `false` |
| `metadata` | The metadata property can be used to set the Mux Data metadata properties in an easy way. Take a look at the [metadata guide](https://docs.mux.com/guides/data/make-your-data-actionable-with-metadata) to view an exhaustive list of available values. | `{}` |

@@ -199,4 +198,4 @@ | `muted` | Is a `Boolean` that determines whether audio is muted. `true` if the audio is muted and `false` otherwise. | `false` |

| `playsInline` | A Boolean attribute indicating that the video is to be played "inline", that is within the element's playback area. Note that the absence of this attribute does not imply that the video will always be played in fullscreen. | `false` |
| `preload` | Is a `DOMString` that reflects the preload HTML attribute, indicating what data should be preloaded, if any. Possible values are: `none`, `metadata`, `auto`. | `undefined` |
| `src` | Is a `String` that reflects the src HTML attribute, which contains the URL of a media resource to use. | `undefined` |
| `preload` | Is a `DOMString` that reflects the `preload` HTML attribute, indicating what data should be preloaded, if any. Possible values are: `none`, `metadata`, `auto`. | `undefined` |
| `src` | Is a `String` that reflects the `src` HTML attribute, which contains the URL of a media resource to use. | `undefined` |
| `startTime` | `Number` that specifies where in the media's timeline you want playback to start (in seconds). | `0` |

@@ -208,2 +207,3 @@ | `thumbnailTime` | `Number` offset (in seconds) for the poster image you want to show before loading media. If no `thumbnailTime` is specified, `startTime` will be used by default. NOTE: This feature currently cannot be used with `tokens.thumbnail`. | `0` |

| `volume` | Is a double indicating the audio volume, from 0.0 (silent) to 1.0 (loudest). | `1` |
| `customDomain` | Is a `String` that assigns a custom domain to be used for Mux Video. | `undefined` |

@@ -210,0 +210,0 @@ ### Events

@@ -59,2 +59,9 @@ import { toQuery, camelCase } from './utils';

export function castThemeName(themeName?: string): string | undefined {
if (themeName && /^media-theme-[\w-]+$/.test(themeName)) {
return themeName;
}
return undefined;
}
const attrToPropNameMap: Record<string, string> = {

@@ -69,26 +76,2 @@ crossorigin: 'crossOrigin',

let testMediaEl: HTMLMediaElement | undefined;
export const getTestMediaEl = (nodeName = 'video') => {
if (testMediaEl) return testMediaEl;
if (typeof window !== 'undefined') {
testMediaEl = document.createElement(nodeName as 'video' | 'audio');
}
return testMediaEl;
};
export const hasVolumeSupportAsync = async (mediaEl: HTMLMediaElement | undefined = getTestMediaEl()) => {
if (!mediaEl) return false;
const prevVolume = mediaEl.volume;
mediaEl.volume = prevVolume / 2 + 0.1;
return new Promise<boolean>((resolve, reject) => {
setTimeout(() => {
resolve(mediaEl.volume !== prevVolume);
}, 0);
});
};
export function getCcSubTracks(el: MuxPlayerElement) {
return Array.from(el.media?.textTracks ?? []).filter(({ kind }) => kind === 'subtitles' || kind === 'captions');
}
export const getLiveTime = (el: MuxPlayerElement) => {

@@ -95,0 +78,0 @@ const { media } = el;

@@ -152,4 +152,45 @@ import { TemplateInstance, NodeTemplatePart, createProcessor, AttributeTemplatePart } from '@github/template-parts';

const stringsCache = new Map();
const defaultProcessor = createProcessor(processPart);
export function html(strings: TemplateStringsArray, ...values: unknown[]): TemplateResult {
const staticStrings: any = [''];
const dynamicValues: any[] = [];
let staticValues;
let hasStatics = false;
// Here the unsafe static values are moved from the string expressions
// to the static strings so they can be used in the cache key and later
// be used to generate the HTML via the <template> element.
const join = (strs: TemplateStringsArray, vals: any[] = []) => {
staticStrings[staticStrings.length - 1] = staticStrings[staticStrings.length - 1] + strs[0];
vals.forEach((dynamicValue, i) => {
if ((staticValues = dynamicValue?.$static$) !== undefined) {
staticValues.forEach((staticValue: TemplateResult) => {
join(staticValue.strings, staticValue.values);
});
staticStrings[staticStrings.length - 1] = staticStrings[staticStrings.length - 1] + strs[i + 1];
hasStatics = true;
} else {
dynamicValues.push(dynamicValue);
staticStrings.push(strs[i + 1]);
}
});
};
join(strings, values);
if (hasStatics) {
// Tagged template literals with the same static strings return the same
// TemplateStringsArray, aka they are cached. emulate this behavior w/ a Map.
const key = staticStrings.join('$$html$$');
strings = stringsCache.get(key);
if (strings === undefined) {
(staticStrings as any).raw = staticStrings;
stringsCache.set(key, (strings = staticStrings));
}
values = dynamicValues;
}
return new TemplateResult(strings, values, defaultProcessor);

@@ -167,1 +208,10 @@ }

}
export const unsafeStatic = (...values: any[]) => ({
['$static$']: values.map((value) => {
if (value instanceof TemplateResult) return value;
// Only allow word characters and dashes for security.
if (!/\w-/.test(value)) return { strings: [] };
return { strings: [value] };
}),
});

@@ -5,14 +5,6 @@ // import playback-core here to make sure that the polyfill is loaded

import { MediaController } from 'media-chrome';
import MediaThemeMux from './media-theme-mux/media-theme-mux';
import MuxVideoElement, { MediaError } from '@mux/mux-video';
import { Metadata, StreamTypes } from '@mux/playback-core';
import { Metadata, StreamTypes, addTextTrack, removeTextTrack } from '@mux/playback-core';
import VideoApiElement, { initVideoApi } from './video-api';
import {
getCcSubTracks,
getPlayerVersion,
hasVolumeSupportAsync,
isInLiveWindow,
seekToLive,
toPropName,
} from './helpers';
import { getPlayerVersion, isInLiveWindow, seekToLive, toPropName } from './helpers';
import { template } from './template';

@@ -32,4 +24,2 @@ import { render } from './html';

type MediaController = Element & { media: HTMLVideoElement };
const streamTypeValues = Object.values(StreamTypes);

@@ -97,2 +87,3 @@

poster: el.getAttribute('poster'),
theme: el.getAttribute('theme'),
thumbnailTime: !el.tokens.thumbnail && el.thumbnailTime,

@@ -125,3 +116,2 @@ autoplay: el.autoplay,

playerSize: getPlayerSize(el.mediaController ?? el),
hasCaptions: !!getCcSubTracks(el).length,
// NOTE: In order to guarantee all expected metadata props are set "from the outside" when used

@@ -154,4 +144,2 @@ // and to guarantee they'll all be set *before* the playback id is set, using attr values here (CJP)

...initialState,
supportsAirPlay: false,
supportsVolume: false,
onCloseErrorDialog: () => this.#setState({ dialog: undefined, isDialogOpen: false }),

@@ -193,15 +181,21 @@ onInitFocusDialog: (e) => {

// even before they are connected to the main document.
customElements.upgrade(this.theme as Node);
if (!(this.theme instanceof MediaThemeMux)) {
logger.error('<media-theme-mux> failed to upgrade!');
try {
customElements.upgrade(this.theme as Node);
if (!(this.theme instanceof HTMLElement)) throw '';
} catch (error) {
logger.error(`<${this.theme?.localName}> failed to upgrade!`);
}
customElements.upgrade(this.media as Node);
if (!(this.media instanceof MuxVideoElement)) {
try {
customElements.upgrade(this.media as Node);
if (!(this.media instanceof MuxVideoElement)) throw '';
} catch (error) {
logger.error('<mux-video> failed to upgrade!');
}
customElements.upgrade(this.mediaController as Node);
if (!(this.mediaController instanceof MediaController)) {
logger.error('<media-controller> failed to upgrade!');
try {
customElements.upgrade(this.mediaController as Node);
if (!(this.mediaController instanceof MediaController)) throw '';
} catch (error) {
logger.error(`<media-controller> failed to upgrade!`);
}

@@ -222,4 +216,2 @@

this.#setUpCaptionsButton();
this.#setUpAirplayButton();
this.#setUpVolumeRange();
this.#monitorLiveWindow();

@@ -502,18 +494,2 @@ this.#userInactive = this.mediaController?.hasAttribute('user-inactive') ?? true;

#setUpAirplayButton() {
if (!!(globalThis as any).WebKitPlaybackTargetAvailabilityEvent) {
const onPlaybackTargetAvailability = (evt: any) => {
const supportsAirPlay = evt.availability === 'available';
this.#setState({ supportsAirPlay });
};
this.media?.addEventListener('webkitplaybacktargetavailabilitychanged', onPlaybackTargetAvailability);
}
}
async #setUpVolumeRange() {
const supportsVolume = await hasVolumeSupportAsync();
this.#setState({ supportsVolume });
}
attributeChangedCallback(attrName: string, oldValue: string | null, newValue: string) {

@@ -881,3 +857,11 @@ if (!this.#isInit) {

set metadata(val: Readonly<Metadata> | undefined) {
if (this.media) this.media.metadata = val;
if (!this.#isInit) {
this.#init();
}
// NOTE: This condition should never be met. If it is, there is a bug (CJP)
if (!this.media) {
logger.error('underlying media element missing when trying to set metadata. metadata will not be set.');
return;
}
this.media.metadata = val;
}

@@ -948,2 +932,18 @@

}
addTextTrack(kind: TextTrackKind, label: string, lang?: string, id?: string) {
const mediaEl = this.media?.nativeEl;
if (!mediaEl) return;
return addTextTrack(mediaEl, kind, label, lang, id);
}
removeTextTrack(track: TextTrack) {
const mediaEl = this.media?.nativeEl;
if (!mediaEl) return;
return removeTextTrack(mediaEl, track);
}
get textTracks() {
return this.media?.textTracks;
}
}

@@ -950,0 +950,0 @@

@@ -6,2 +6,4 @@ // @ts-nocheck

import captionsOnIcon from './icons/captions-on.svg';
import castEnter from './icons/cast-enter.svg';
import castExit from './icons/cast-exit.svg';
import fullscreenEnter from './icons/fullscreen-enter.svg';

@@ -23,2 +25,4 @@ import fullscreenExit from './icons/fullscreen-exit.svg';

export const CaptionsOn = () => createTemplateInstance(captionsOnIcon);
export const CastEnter = () => createTemplateInstance(castEnter);
export const CastExit = () => createTemplateInstance(castExit);
export const FullscreenEnter = () => createTemplateInstance(fullscreenEnter);

@@ -25,0 +29,0 @@ export const FullscreenExit = () => createTemplateInstance(fullscreenExit);

@@ -1,2 +0,2 @@

import 'media-chrome';
import { MediaTheme } from 'media-chrome';
import { html, render } from '../html';

@@ -17,24 +17,57 @@ import '../media-chrome/time-display';

type ThemeMuxTemplateProps = {
streamType: string;
streamType: string | null;
audio: boolean;
playerSize: string;
playerSize: string | null;
defaultHiddenCaptions: boolean;
hasCaptions: boolean;
forwardSeekOffset: number;
backwardSeekOffset: number;
forwardSeekOffset: string | null;
backwardSeekOffset: string | null;
};
const template = (props: ThemeMuxTemplateProps) => html`
<style>
${cssStr}
</style>
export default class MediaThemeMux extends MediaTheme {
static get observedAttributes() {
return [
'audio',
'stream-type',
'player-size',
'default-hidden-captions',
'forward-seek-offset',
'backward-seek-offset',
];
}
<media-controller audio="${props.audio || false}" class="size-${props.playerSize}">
<slot name="media" slot="media"></slot>
<media-loading-indicator slot="centered-chrome" no-auto-hide></media-loading-indicator>
${ChromeRenderer(props)}
<slot></slot>
</media-controller>
`;
attributeChangedCallback() {
this.render();
}
render() {
const props = {
audio: this.hasAttribute('audio'),
streamType: this.getAttribute('stream-type'),
playerSize: this.getAttribute('player-size'),
defaultHiddenCaptions: this.hasAttribute('default-hidden-captions'),
forwardSeekOffset: this.getAttribute('forward-seek-offset'),
backwardSeekOffset: this.getAttribute('backward-seek-offset'),
};
render(
html`
<style>
${cssStr}
</style>
<media-controller audio="${props.audio || false}" class="size-${props.playerSize}">
<slot name="media" slot="media"></slot>
<media-loading-indicator slot="centered-chrome" no-auto-hide></media-loading-indicator>
${ChromeRenderer(props)}
<slot></slot>
</media-controller>
`,
this.shadowRoot as Node
);
}
}
if (!customElements.get('media-theme-mux')) {
customElements.define('media-theme-mux', MediaThemeMux);
}
const ChromeRenderer = (props: ThemeMuxTemplateProps) => {

@@ -46,3 +79,3 @@ const { streamType, playerSize, audio } = props;

case StreamTypes.LL_LIVE: {
return AudioLiveChrome(props);
return AudioLiveChrome();
}

@@ -157,2 +190,9 @@ case StreamTypes.DVR:

// prettier-ignore
const MediaCastButton = () => html`
<media-cast-button>
${icons.CastEnter()}
${icons.CastExit()}
</media-cast-button>`;
export const AudioVodChrome = (props: ThemeMuxTemplateProps) => html`

@@ -166,4 +206,3 @@ <media-control-bar>

<media-playback-rate-button></media-playback-rate-button>
${MediaAirplayButton()}
<media-cast-button></media-cast-button>
${MediaAirplayButton()} ${MediaCastButton()}
</media-control-bar>

@@ -182,8 +221,7 @@ `;

<media-playback-rate-button></media-playback-rate-button>
${MediaAirplayButton()}
<media-cast-button></media-cast-button>
${MediaAirplayButton()} ${MediaCastButton()}
</media-control-bar>
`;
export const AudioLiveChrome = (_props: ThemeMuxTemplateProps) => html`
export const AudioLiveChrome = () => html`
<media-control-bar>

@@ -194,4 +232,3 @@ ${MediaPlayButton()}

<media-volume-range></media-volume-range>
${MediaAirplayButton()}
<media-cast-button></media-cast-button>
${MediaAirplayButton()} ${MediaCastButton()}
</media-control-bar>

@@ -203,6 +240,6 @@ `;

<media-control-bar slot="top-chrome">
${props.hasCaptions ? MediaCaptionsButton(props) : html``}
${MediaCaptionsButton(props)}
<div class="mxp-spacer"></div>
${MediaAirplayButton()}
<media-cast-button></media-cast-button>
${MediaCastButton()}
${MediaPipButton()}

@@ -223,5 +260,5 @@ </media-control-bar>

<media-control-bar slot="top-chrome" style="justify-content: flex-end;">
${props.hasCaptions ? MediaCaptionsButton(props) : html``}
${MediaCaptionsButton(props)}
${MediaAirplayButton()}
<media-cast-button></media-cast-button>
${MediaCastButton()}
${MediaPipButton()}

@@ -261,5 +298,5 @@ </media-control-bar>

<media-playback-rate-button></media-playback-rate-button>
${props.hasCaptions ? MediaCaptionsButton(props) : html``}
${MediaCaptionsButton(props)}
${MediaAirplayButton()}
<media-cast-button></media-cast-button>
${MediaCastButton()}
${MediaPipButton()}

@@ -279,5 +316,5 @@ ${MediaFullscreenButton()}

<div class="mxp-spacer"></div>
${props.hasCaptions ? MediaCaptionsButton(props) : html``}
${MediaCaptionsButton(props)}
${MediaAirplayButton()}
<media-cast-button></media-cast-button>
${MediaCastButton()}
${MediaPipButton()}

@@ -308,5 +345,5 @@ </media-control-bar>

<div class="mxp-spacer"></div>
${props.hasCaptions ? MediaCaptionsButton(props) : html``}
${MediaCaptionsButton(props)}
${MediaAirplayButton()}
<media-cast-button></media-cast-button>
${MediaCastButton()}
${MediaPipButton()}

@@ -323,5 +360,5 @@ ${MediaFullscreenButton()}

<media-control-bar slot="top-chrome" style="justify-content: flex-end;">
${props.hasCaptions ? MediaCaptionsButton(props) : html``}
${MediaCaptionsButton(props)}
${MediaAirplayButton()}
<media-cast-button></media-cast-button>
${MediaCastButton()}
${MediaPipButton()}

@@ -359,5 +396,5 @@ </media-control-bar>

<div class="mxp-spacer"></div>
${props.hasCaptions ? MediaCaptionsButton(props) : html``}
${MediaCaptionsButton(props)}
${MediaAirplayButton()}
<media-cast-button></media-cast-button>
${MediaCastButton()}
${MediaPipButton()}

@@ -368,45 +405,1 @@ ${MediaFullscreenButton()}

`;
function getProps(el: MediaThemeMux, state?: any): ThemeMuxTemplateProps {
return {
audio: el.hasAttribute('audio'),
streamType: el.getAttribute('stream-type'),
playerSize: el.getAttribute('player-size'),
defaultHiddenCaptions: el.hasAttribute('default-hidden-captions'),
hasCaptions: el.hasAttribute('has-captions'),
forwardSeekOffset: el.getAttribute('forward-seek-offset'),
backwardSeekOffset: el.getAttribute('backward-seek-offset'),
...state,
};
}
class MediaThemeMux extends HTMLElement {
static get observedAttributes() {
return [
'audio',
'stream-type',
'player-size',
'default-hidden-captions',
'has-captions',
'forward-seek-offset',
'backward-seek-offset',
];
}
constructor() {
super();
this.attachShadow({ mode: 'open' });
render(template(getProps(this)), this.shadowRoot as Node);
}
attributeChangedCallback() {
render(template(getProps(this)), this.shadowRoot as Node);
}
}
if (!customElements.get('media-theme-mux')) {
customElements.define('media-theme-mux', MediaThemeMux);
}
export default MediaThemeMux;
import './media-theme-mux/media-theme-mux';
import './dialog';
import { getSrcFromPlaybackId, getPosterURLFromPlaybackId, getStoryboardURLFromPlaybackId } from './helpers';
import { html } from './html';
import {
castThemeName,
getSrcFromPlaybackId,
getPosterURLFromPlaybackId,
getStoryboardURLFromPlaybackId,
} from './helpers';
import { html, unsafeStatic } from './html';
// @ts-ignore

@@ -20,14 +25,13 @@ import cssStr from './styles.css';

export const content = (props: MuxTemplateProps) => html`
<media-theme-mux
<${unsafeStatic(castThemeName(props.theme) ?? 'media-theme-mux')}
audio="${props.audio || false}"
style="${stylePropsToString({
'--primary-color': props.primaryColor,
'--secondary-color': props.secondaryColor,
'--mux-time-range-padding': props.secondaryColor ? '0' : null,
'--media-range-track-border-radius': props.secondaryColor ? '0' : null,
}) ?? false}"
class="size-${props.playerSize}"
style="${
stylePropsToString({
'--primary-color': props.primaryColor,
'--secondary-color': props.secondaryColor,
}) ?? false
}"
class="size-${props.playerSize}${props.secondaryColor ? ' two-tone' : ''}"
stream-type="${props.streamType}"
player-size="${props.playerSize}"
has-captions="${props.hasCaptions}"
default-hidden-captions="${props.defaultHiddenCaptions}"

@@ -48,5 +52,5 @@ forward-seek-offset="${props.forwardSeekOffset}"

start-time="${props.startTime != null ? props.startTime : false}"
metadata-video-id="${props.metadataVideoId ?? props.metadata?.video_id ?? false}"
metadata-video-title="${props.metadataVideoTitle ?? props.metadata?.video_title ?? false}"
metadata-viewer-user-id="${props.metadataViewerUserId ?? props.metadata?.viewer_user_id ?? false}"
metadata-video-id="${props.metadataVideoId ?? false}"
metadata-video-title="${props.metadataVideoTitle ?? false}"
metadata-viewer-user-id="${props.metadataViewerUserId ?? false}"
beacon-collection-domain="${props.beaconCollectionDomain ?? false}"

@@ -58,36 +62,44 @@ player-software-name="${props.playerSoftwareName}"

custom-domain="${props.customDomain ?? false}"
src="${!!props.src
? props.src
: props.playbackId
? getSrcFromPlaybackId(props.playbackId, { domain: props.customDomain, token: props.tokens.playback })
: false}"
poster="${!!props.poster
? props.poster
: props.playbackId && !props.audio
? getPosterURLFromPlaybackId(props.playbackId, {
domain: props.customDomain,
thumbnailTime: props.thumbnailTime ?? props.startTime,
token: props.tokens.thumbnail,
})
: false}"
cast-src="${!!props.src
? props.src
: props.playbackId
? getSrcFromPlaybackId(props.playbackId, { domain: props.customDomain, token: props.tokens.playback })
: false}"
src="${
!!props.src
? props.src
: props.playbackId
? getSrcFromPlaybackId(props.playbackId, { domain: props.customDomain, token: props.tokens.playback })
: false
}"
poster="${
!!props.poster
? props.poster
: props.playbackId && !props.audio
? getPosterURLFromPlaybackId(props.playbackId, {
domain: props.customDomain,
thumbnailTime: props.thumbnailTime ?? props.startTime,
token: props.tokens.thumbnail,
})
: false
}"
cast-src="${
!!props.src
? props.src
: props.playbackId
? getSrcFromPlaybackId(props.playbackId, { domain: props.customDomain, token: props.tokens.playback })
: false
}"
cast-stream-type="${[StreamTypes.LIVE, StreamTypes.LL_LIVE].includes(props.streamType as any) ? 'live' : false}"
>
${props.playbackId &&
!props.audio &&
![StreamTypes.LIVE, StreamTypes.LL_LIVE, StreamTypes.DVR, StreamTypes.LL_DVR].includes(props.streamType as any)
? html`<track
label="thumbnails"
default
kind="metadata"
src="${getStoryboardURLFromPlaybackId(props.playbackId, {
domain: props.customDomain,
token: props.tokens.storyboard,
})}"
/>`
: html``}
${
props.playbackId &&
!props.audio &&
![StreamTypes.LIVE, StreamTypes.LL_LIVE, StreamTypes.DVR, StreamTypes.LL_DVR].includes(props.streamType as any)
? html`<track
label="thumbnails"
default
kind="metadata"
src="${getStoryboardURLFromPlaybackId(props.playbackId, {
domain: props.customDomain,
token: props.tokens.storyboard,
})}"
/>`
: html``
}
</mux-video>

@@ -117,14 +129,16 @@ <button

${props.dialog?.message}
${props.dialog?.linkUrl
? html`<a
href="${props.dialog.linkUrl}"
target="_blank"
rel="external noopener"
aria-label="${props.dialog.linkText ?? ''} ${i18n(`(opens in a new window)`)}"
>${props.dialog.linkText ?? props.dialog.linkUrl}</a
>`
: html``}
${
props.dialog?.linkUrl
? html`<a
href="${props.dialog.linkUrl}"
target="_blank"
rel="external noopener"
aria-label="${props.dialog.linkText ?? ''} ${i18n(`(opens in a new window)`)}"
>${props.dialog.linkText ?? props.dialog.linkUrl}</a
>`
: html``
}
</p>
</mxp-dialog>
</media-theme-mux>
</${unsafeStatic(castThemeName(props.theme) ?? 'media-theme-mux')}>
`;

@@ -9,7 +9,5 @@ import type MuxVideoElement, { MediaError } from '@mux/mux-video';

audio: boolean;
theme?: string;
playerSize: string;
showLoading: boolean;
hasCaptions: boolean;
supportsAirPlay: boolean;
supportsVolume: boolean;
thumbnailTime: number;

@@ -16,0 +14,0 @@ primaryColor: string;

import { VideoEvents } from '@mux/mux-video';
import type MuxVideoElement from '@mux/mux-video';
import * as logger from './logger';
import { toNumberOrUndefined } from './utils';

@@ -102,2 +103,3 @@ export type CastOptions = {

this.media.muted = newValue != null;
this.media.defaultMuted = newValue != null;
}

@@ -117,2 +119,3 @@ return;

this.media.playbackRate = val;
this.media.defaultPlaybackRate = val;
}

@@ -222,2 +225,15 @@ return;

get defaultPlaybackRate() {
return toNumberOrUndefined(this.getAttribute(CustomVideoAttributes.PLAYBACKRATE)) ?? 1;
}
set defaultPlaybackRate(val) {
if (val != null) {
this.setAttribute(CustomVideoAttributes.PLAYBACKRATE, `${val}`);
} else {
// Remove boolean attribute if false, 0, '', null, undefined.
this.removeAttribute(CustomVideoAttributes.PLAYBACKRATE);
}
}
get crossOrigin() {

@@ -258,6 +274,16 @@ return getVideoAttribute(this, AllowedVideoAttributes.CROSSORIGIN);

get muted() {
return this.media?.muted ?? false;
}
set muted(val) {
if (this.media) {
this.media.muted = Boolean(val);
}
}
get defaultMuted() {
return getVideoAttribute(this, AllowedVideoAttributes.MUTED) != null;
}
set muted(val) {
set defaultMuted(val) {
if (val) {

@@ -264,0 +290,0 @@ this.setAttribute(AllowedVideoAttributes.MUTED, '');

@@ -286,2 +286,6 @@ import { fixture, assert, aTimeout, waitUntil } from '@open-wc/testing';

assert(player.defaultMuted, 'player.defaultMuted is true');
assert(muxVideo.defaultMuted, 'muxVideo.defaultMuted is true');
assert(nativeVideo.defaultMuted, 'nativeVideo.defaultMuted is true');
player.removeAttribute('muted');

@@ -293,2 +297,6 @@

assert(!player.defaultMuted, 'player.defaultMuted is false');
assert(!muxVideo.defaultMuted, 'muxVideo.defaultMuted is false');
assert(!nativeVideo.defaultMuted, 'nativeVideo.defaultMuted is false');
player.setAttribute('muted', '');

@@ -299,2 +307,6 @@

assert(nativeVideo.muted, 'nativeVideo.muted is true');
assert(player.defaultMuted, 'player.defaultMuted is true');
assert(muxVideo.defaultMuted, 'muxVideo.defaultMuted is true');
assert(nativeVideo.defaultMuted, 'nativeVideo.defaultMuted is true');
});

@@ -348,2 +360,24 @@

it('defaultPlaybackRate property behaves like expected', async function () {
const player = await fixture(`<mux-player
playback-id="DS00Spx1CV902MCtPj5WknGlR102V5HFkDe"
stream-type="on-demand"
></mux-player>`);
assert.equal(player.defaultPlaybackRate, 1);
const muxVideo = player.media;
const nativeVideo = muxVideo.shadowRoot.querySelector('video');
assert.equal(player.defaultPlaybackRate, 1, 'player.defaultPlaybackRate is 1');
assert.equal(muxVideo.defaultPlaybackRate, 1, 'muxVideo.defaultPlaybackRate is 1');
assert.equal(nativeVideo.defaultPlaybackRate, 1, 'nativeVideo.defaultPlaybackRate is 1');
player.defaultPlaybackRate = 0.7;
assert.equal(player.defaultPlaybackRate, 0.7, 'player.defaultPlaybackRate is 0.7');
assert.equal(muxVideo.defaultPlaybackRate, 0.7, 'muxVideo.defaultPlaybackRate is 0.7');
assert.equal(nativeVideo.defaultPlaybackRate, 0.7, 'nativeVideo.defaultPlaybackRate is 0.7');
});
it("signing tokens generate correct asset URL's", async function () {

@@ -350,0 +384,0 @@ // tokens expire in 10 years

@@ -14,3 +14,3 @@ import { assert } from '@open-wc/testing';

minify(div.innerHTML),
'<media-theme-mux class="size-" stream-type="" player-size="" has-captions="" default-hidden-captions="" forward-seek-offset="" backward-seek-offset=""><mux-video slot="media" crossorigin="" playsinline="" player-software-name="" player-software-version=""></mux-video><button slot="seek-to-live-button" aria-disabled="" class="mxp-seek-to-live-button">\n Live\n </button><mxp-dialog no-auto-hide="" open=""><p></p></mxp-dialog></media-theme-mux>'
'<media-theme-mux class="size-" stream-type="" player-size="" default-hidden-captions="" forward-seek-offset="" backward-seek-offset=""><mux-video slot="media" crossorigin="" playsinline="" player-software-name="" player-software-version=""></mux-video><button slot="seek-to-live-button" aria-disabled="" class="mxp-seek-to-live-button">\n Live\n </button><mxp-dialog no-auto-hide="" open=""><p></p></mxp-dialog></media-theme-mux>'
);

@@ -33,3 +33,3 @@ });

minify(div.innerHTML),
'<media-theme-mux class="size-extra-small" stream-type="on-demand" player-size="extra-small" has-captions="" default-hidden-captions="" forward-seek-offset="" backward-seek-offset=""><mux-video slot="media" crossorigin="" playsinline="" player-software-name="" player-software-version="" stream-type="on-demand"></mux-video><button slot="seek-to-live-button" aria-disabled="" class="mxp-seek-to-live-button">\n Live\n </button><mxp-dialog no-auto-hide="" open=""><h3>Errr</h3><p></p></mxp-dialog></media-theme-mux>'
'<media-theme-mux class="size-extra-small" stream-type="on-demand" player-size="extra-small" default-hidden-captions="" forward-seek-offset="" backward-seek-offset=""><mux-video slot="media" crossorigin="" playsinline="" player-software-name="" player-software-version="" stream-type="on-demand"></mux-video><button slot="seek-to-live-button" aria-disabled="" class="mxp-seek-to-live-button">\n Live\n </button><mxp-dialog no-auto-hide="" open=""><h3>Errr</h3><p></p></mxp-dialog></media-theme-mux>'
);

@@ -50,3 +50,3 @@ });

minify(div.innerHTML),
'<media-theme-mux class="size-large" stream-type="on-demand" player-size="large" has-captions="" default-hidden-captions="" forward-seek-offset="" backward-seek-offset=""><mux-video slot="media" crossorigin="" playsinline="" player-software-name="" player-software-version="" stream-type="on-demand"></mux-video><button slot="seek-to-live-button" aria-disabled="" class="mxp-seek-to-live-button">\n Live\n </button><mxp-dialog no-auto-hide="" open=""><p></p></mxp-dialog></media-theme-mux>'
'<media-theme-mux class="size-large" stream-type="on-demand" player-size="large" default-hidden-captions="" forward-seek-offset="" backward-seek-offset=""><mux-video slot="media" crossorigin="" playsinline="" player-software-name="" player-software-version="" stream-type="on-demand"></mux-video><button slot="seek-to-live-button" aria-disabled="" class="mxp-seek-to-live-button">\n Live\n </button><mxp-dialog no-auto-hide="" open=""><p></p></mxp-dialog></media-theme-mux>'
);

@@ -53,0 +53,0 @@ });

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc