From 2b3d78186cd8e75bad723c4bd50967ad15cd676c Mon Sep 17 00:00:00 2001 From: Christian Pillsbury Date: Tue, 13 Aug 2024 09:39:31 -0500 Subject: [PATCH] feat(castable-video): Add castCustomData to send arbitrary custom data to receiver app on load. --- packages/castable-video/castable-mixin.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/castable-video/castable-mixin.js b/packages/castable-video/castable-mixin.js index 02c4eb4..1a48f78 100644 --- a/packages/castable-video/castable-mixin.js +++ b/packages/castable-video/castable-mixin.js @@ -30,6 +30,7 @@ export const CastableMediaMixin = (superclass) => #localState = { paused: false }; #castOptions = getDefaultCastOptions(); + #castCustomData; #remote; get remote() { @@ -89,6 +90,7 @@ export const CastableMediaMixin = (superclass) => if (!this.#castPlayer) return super.load(); const mediaInfo = new chrome.cast.media.MediaInfo(this.castSrc, this.castContentType); + mediaInfo.customData = this.castCustomData; // Manually add text tracks with a `src` attribute. // M3U8's load text tracks in the receiver, handle these in the media loaded event. @@ -221,6 +223,21 @@ export const CastableMediaMixin = (superclass) => this.setAttribute('cast-stream-type', `${val}`); } + get castCustomData() { + return this.#castCustomData; + } + + set castCustomData(val) { + console.log('setting castCustomData', val); + const valType = typeof val; + if (!['object', 'undefined'].includes(valType)) { + console.error(`castCustomData must be nullish or an object but value was of type ${valType}`); + return; + } + + this.#castCustomData = val; + } + get readyState() { if (this.#castPlayer) { switch (this.#castPlayer.playerState) {