castable-video
Advanced tools
Comparing version 0.1.0 to 0.2.0
/* global globalThis, chrome, cast */ | ||
class CastableVideo extends HTMLVideoElement { | ||
class CastableVideoElement extends HTMLVideoElement { | ||
static observedAttributes = ['cast-src']; | ||
@@ -90,3 +90,3 @@ static instances = new Set(); | ||
CastableVideo.instances.add(this); | ||
CastableVideoElement.instances.add(this); | ||
this.#init(); | ||
@@ -96,3 +96,3 @@ } | ||
get castPlayer() { | ||
if (CastableVideo.castElement === this) return this.#remotePlayer; | ||
if (CastableVideoElement.castElement === this) return this.#remotePlayer; | ||
return undefined; | ||
@@ -116,3 +116,3 @@ } | ||
#disconnect() { | ||
if (CastableVideo.#castElement !== this) return; | ||
if (CastableVideoElement.#castElement !== this) return; | ||
@@ -123,3 +123,3 @@ this.#remoteListeners.forEach(([event, listener]) => { | ||
CastableVideo.#castElement = undefined; | ||
CastableVideoElement.#castElement = undefined; | ||
@@ -134,3 +134,3 @@ this.muted = this.#remoteState.muted; | ||
#init() { | ||
if (!CastableVideo.#isCastFrameworkAvailable || this.#castAvailable) return; | ||
if (!CastableVideoElement.#isCastFrameworkAvailable || this.#castAvailable) return; | ||
this.#castAvailable = true; | ||
@@ -147,6 +147,6 @@ this.#setOptions(); | ||
const { CAST_STATE_CHANGED } = cast.framework.CastContextEventType; | ||
CastableVideo.#castContext.addEventListener(CAST_STATE_CHANGED, () => { | ||
CastableVideoElement.#castContext.addEventListener(CAST_STATE_CHANGED, () => { | ||
this.dispatchEvent( | ||
new CustomEvent('castchange', { | ||
detail: CastableVideo.#castContext.getCastState(), | ||
detail: CastableVideoElement.#castContext.getCastState(), | ||
}) | ||
@@ -158,3 +158,3 @@ ); | ||
new CustomEvent('castchange', { | ||
detail: CastableVideo.#castContext.getCastState(), | ||
detail: CastableVideoElement.#castContext.getCastState(), | ||
}) | ||
@@ -236,3 +236,3 @@ ); | ||
#setOptions(options) { | ||
return CastableVideo.#castContext.setOptions({ | ||
return CastableVideoElement.#castContext.setOptions({ | ||
// Set the receiver application ID to your own (created in the | ||
@@ -269,3 +269,3 @@ // Google Cast Developer Console), or optionally | ||
const activeTrackIds = | ||
CastableVideo.#currentSession?.getSessionObj().media[0].activeTrackIds; | ||
CastableVideoElement.#currentSession?.getSessionObj().media[0].activeTrackIds; | ||
@@ -298,3 +298,3 @@ const subtitles = [...this.textTracks].filter( | ||
); | ||
CastableVideo.#currentSession?.getSessionObj().media[0].editTracksInfo( | ||
CastableVideoElement.#currentSession?.getSessionObj().media[0].editTracksInfo( | ||
request, | ||
@@ -308,3 +308,3 @@ () => {}, | ||
this.#setOptions(options); | ||
CastableVideo.#castElement = this; | ||
CastableVideoElement.#castElement = this; | ||
@@ -317,5 +317,5 @@ this.#remoteListeners.forEach(([event, listener]) => { | ||
// Open browser cast menu. | ||
await CastableVideo.#castContext.requestSession(); | ||
await CastableVideoElement.#castContext.requestSession(); | ||
} catch (err) { | ||
CastableVideo.#castElement = undefined; | ||
CastableVideoElement.#castElement = undefined; | ||
// console.error(err); // Don't show an error if dismissing the menu. | ||
@@ -416,3 +416,3 @@ return; | ||
await CastableVideo.#currentSession?.loadMedia(request); | ||
await CastableVideoElement.#currentSession?.loadMedia(request); | ||
@@ -550,8 +550,8 @@ this.dispatchEvent(new Event('volumechange')); | ||
if (!customElements.get('castable-video')) { | ||
customElements.define('castable-video', CastableVideo, { extends: 'video' }); | ||
globalThis.CastableVideo = CastableVideo; | ||
customElements.define('castable-video', CastableVideoElement, { extends: 'video' }); | ||
globalThis.CastableVideoElement = CastableVideoElement; | ||
} | ||
CastableVideo.initCast(); | ||
CastableVideoElement.initCast(); | ||
export default CastableVideo; | ||
export default CastableVideoElement; |
{ | ||
"name": "castable-video", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Cast your video element to the big screen with ease!", | ||
@@ -5,0 +5,0 @@ "main": "castable-video.js", |
@@ -5,3 +5,3 @@ # `is="castable-video"` | ||
The lightweight `CastableVideo` class extends the native `HTMLVideoElement` API and adds casting functionality to any video element. The API was designed to have the feel of a native browser API similar to the other screen presentation API's. | ||
The lightweight `CastableVideoElement` class extends the native `HTMLVideoElement` API and adds casting functionality to any video element. The API was designed to have the feel of a native browser API similar to the other screen presentation API's. | ||
@@ -13,3 +13,3 @@ It was primarily built for use in [Media Chrome](https://github.com/muxinc/media-chrome) but it works great with any custom video controls as you can see in the example. | ||
<script src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1"></script> | ||
<script type="module" src="./castable-video.js"></script> | ||
<script type="module" src="https://cdn.jsdelivr.net/npm/castable-video"></script> | ||
@@ -25,3 +25,3 @@ <video | ||
<button onclick="window.castable.requestCast()">Request Cast</button> | ||
<button onclick="window.CastableVideo.exitCast()">Exit Cast</button> | ||
<button onclick="window.CastableVideoElement.exitCast()">Exit Cast</button> | ||
<script> | ||
@@ -39,8 +39,8 @@ window.castable.addEventListener('castchange', function (event) { | ||
- `video.requestCast(options)` | ||
- `CastableVideo.exitCast()` | ||
- `CastableVideoElement.exitCast()` | ||
### Properties | ||
- `CastableVideo.castElement` | ||
- `CastableVideo.castAvailable` | ||
- `CastableVideoElement.castElement` | ||
- `CastableVideoElement.castAvailable` | ||
@@ -47,0 +47,0 @@ ### Events |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49064