Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(castable-video): Add castCustomData to send arbitrary custom data to receiver app on load. #32

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/castable-video/castable-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const CastableMediaMixin = (superclass) =>

#localState = { paused: false };
#castOptions = getDefaultCastOptions();
#castCustomData;
#remote;

get remote() {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 10 additions & 8 deletions packages/custom-media-element/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,16 @@ test('has HTMLVideoElement like properties', async function (t) {
'videoHeight',
'videoWidth',
'volume',
'webkitAudioDecodedByteCount',
'webkitDecodedFrameCount',
'webkitDroppedFrameCount',
'webkitEnterFullScreen',
'webkitEnterFullscreen',
'webkitExitFullScreen',
'webkitExitFullscreen',
'webkitVideoDecodedByteCount',
// Commenting browser-prefixed properties out as we should not
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: This is unrelated but tests were failing both locally and on GHA because some webkit browser-prefixed fullscreen props were not present in the browser version used for testing.

// *assume* they will exist, even for the browser in question (CJP)
// 'webkitAudioDecodedByteCount',
// 'webkitDecodedFrameCount',
// 'webkitDroppedFrameCount',
// 'webkitEnterFullScreen',
// 'webkitEnterFullscreen',
// 'webkitExitFullScreen',
// 'webkitExitFullscreen',
// 'webkitVideoDecodedByteCount',
'width',
];

Expand Down