Skip to content

Commit 1cf5cad

Browse files
authored
feat(Cast): Transfer side-loaded text/thumbnail/chapter tracks (#8553)
1 parent 95e6d01 commit 1cf5cad

File tree

3 files changed

+88
-3
lines changed

3 files changed

+88
-3
lines changed

lib/cast/cast_proxy.js

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ shaka.cast.CastProxy = class extends shaka.util.FakeEventTarget {
7777
/** @private {boolean} */
7878
this.androidReceiverCompatible_ = androidReceiverCompatible;
7979

80+
/** @private {!Array<?>} */
81+
this.addThumbnailsTrackCalls_ = [];
82+
83+
/** @private {!Array<?>} */
84+
this.addTextTrackAsyncCalls_ = [];
85+
86+
/** @private {!Array<?>} */
87+
this.addChaptersTrackCalls_ = [];
88+
8089
/** @private {!Map} */
8190
this.compiledToExternNames_ = new Map();
8291

@@ -205,7 +214,6 @@ shaka.cast.CastProxy = class extends shaka.util.FakeEventTarget {
205214
return;
206215
}
207216
// TODO: transfer manually-selected tracks?
208-
// TODO: transfer side-loaded text tracks?
209217

210218
await this.sender_.cast();
211219
if (!this.localPlayer_) {
@@ -450,6 +458,9 @@ shaka.cast.CastProxy = class extends shaka.util.FakeEventTarget {
450458
'playerAfterLoad': {},
451459
'manifest': this.localPlayer_.getAssetUri(),
452460
'startTime': null,
461+
'addThumbnailsTrackCalls': this.addThumbnailsTrackCalls_,
462+
'addTextTrackAsyncCalls': this.addTextTrackAsyncCalls_,
463+
'addChaptersTrackCalls': this.addChaptersTrackCalls_,
453464
};
454465

455466
// Pause local playback before capturing state.
@@ -517,6 +528,12 @@ shaka.cast.CastProxy = class extends shaka.util.FakeEventTarget {
517528
/** @type {Object} */(this.localPlayer_)[setter](value);
518529
}
519530

531+
const addThumbnailsTrackCalls = this.addThumbnailsTrackCalls_;
532+
const addTextTrackAsyncCalls = this.addTextTrackAsyncCalls_;
533+
const addChaptersTrackCalls = this.addChaptersTrackCalls_;
534+
535+
this.resetExternalTracks();
536+
520537
// Get the most recent manifest URI and ended state.
521538
const assetUri = this.sender_.get('player', 'getAssetUri')();
522539
const ended = this.sender_.get('video', 'ended');
@@ -562,6 +579,16 @@ shaka.cast.CastProxy = class extends shaka.util.FakeEventTarget {
562579
return;
563580
}
564581

582+
for (const args of addThumbnailsTrackCalls) {
583+
this.localPlayer_.addThumbnailsTrack(...args);
584+
}
585+
for (const args of addTextTrackAsyncCalls) {
586+
this.localPlayer_.addTextTrackAsync(...args);
587+
}
588+
for (const args of addChaptersTrackCalls) {
589+
this.localPlayer_.addChaptersTrack(...args);
590+
}
591+
565592
for (const name of shaka.cast.CastUtils.VideoInitStateAttributes) {
566593
this.localVideo_[name] = videoState[name];
567594
}
@@ -672,10 +699,11 @@ shaka.cast.CastProxy = class extends shaka.util.FakeEventTarget {
672699

673700
/**
674701
* @param {string} name
702+
* @param {boolean} dontRecordCalls
675703
* @return {?}
676704
* @private
677705
*/
678-
playerProxyGet_(name) {
706+
playerProxyGet_(name, dontRecordCalls = false) {
679707
// If name is a shortened compiled name, get the original version
680708
// from our map.
681709
if (this.compiledToExternNames_.has(name)) {
@@ -739,6 +767,27 @@ shaka.cast.CastProxy = class extends shaka.util.FakeEventTarget {
739767
return (container) => this.localPlayer_.setVideoContainer(container);
740768
}
741769

770+
if (!dontRecordCalls) {
771+
if (name == 'addThumbnailsTrack') {
772+
return (...args) => {
773+
this.addThumbnailsTrackCalls_.push(args);
774+
return this.playerProxyGet_(name, /* dontRecordCalls= */ true)(args);
775+
};
776+
}
777+
if (name == 'addTextTrackAsync') {
778+
return (...args) => {
779+
this.addTextTrackAsyncCalls_.push(args);
780+
return this.playerProxyGet_(name, /* dontRecordCalls= */ true)(args);
781+
};
782+
}
783+
if (name == 'addChaptersTrack') {
784+
return (...args) => {
785+
this.addChaptersTrackCalls_.push(args);
786+
return this.playerProxyGet_(name, /* dontRecordCalls= */ true)(args);
787+
};
788+
}
789+
}
790+
742791
if (this.sender_.isCasting()) {
743792
// These methods are unavailable or otherwise stubbed during casting.
744793
if (name == 'getManifest' || name == 'drmInfo') {
@@ -820,7 +869,19 @@ shaka.cast.CastProxy = class extends shaka.util.FakeEventTarget {
820869
if (targetName == 'video') {
821870
this.videoEventTarget_.dispatchEvent(event);
822871
} else if (targetName == 'player') {
872+
if (event.type == shaka.util.FakeEvent.EventName.Unloading) {
873+
this.resetExternalTracks();
874+
}
823875
this.playerEventTarget_.dispatchEvent(event);
824876
}
825877
}
878+
879+
/**
880+
* Reset external tracks
881+
*/
882+
resetExternalTracks() {
883+
this.addThumbnailsTrackCalls_ = [];
884+
this.addTextTrackAsyncCalls_ = [];
885+
this.addChaptersTrackCalls_ = [];
886+
}
826887
};

lib/cast/cast_receiver.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,21 @@ shaka.cast.CastReceiver = class extends shaka.util.FakeEventTarget {
393393
this.video_.autoplay = false;
394394
try {
395395
await this.player_.load(initState['manifest'], initState['startTime']);
396+
if (initState['addThumbnailsTrackCalls']) {
397+
for (const args of initState['addThumbnailsTrackCalls']) {
398+
this.player_.addThumbnailsTrack(...args);
399+
}
400+
}
401+
if (initState['addTextTrackAsyncCalls']) {
402+
for (const args of initState['addTextTrackAsyncCalls']) {
403+
this.player_.addTextTrackAsync(...args);
404+
}
405+
}
406+
if (initState['addChaptersTrackCalls']) {
407+
for (const args of initState['addChaptersTrackCalls']) {
408+
this.player_.addChaptersTrack(...args);
409+
}
410+
}
396411
} catch (error) {
397412
// Pass any errors through to the app.
398413
goog.asserts.assert(error instanceof shaka.util.Error,

lib/cast/cast_utils.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,10 @@ shaka.cast.CastUtils.PlayerPromiseMethods = [
438438
* video: Object,
439439
* player: Object,
440440
* manifest: ?string,
441-
* startTime: ?number
441+
* startTime: ?number,
442+
* addThumbnailsTrackCalls: !Array<?>,
443+
* addTextTrackAsyncCalls: !Array<?>,
444+
* addChaptersTrackCalls: !Array<?>
442445
* }}
443446
* @property {Object} video
444447
* Dictionary of video properties to be set.
@@ -448,6 +451,12 @@ shaka.cast.CastUtils.PlayerPromiseMethods = [
448451
* The currently-selected manifest, if present.
449452
* @property {?number} startTime
450453
* The playback start time, if currently playing.
454+
* @property {!Array<?>} addThumbnailsTrackCalls
455+
* List of parameters with which addThumbnailsTrack was called.
456+
* @property {!Array<?>} addTextTrackAsyncCalls
457+
* List of parameters with which addTextTrackAsync was called.
458+
* @property {!Array<?>} addChaptersTrackCalls
459+
* List of parameters with which addChaptersTrack was called.
451460
*/
452461
shaka.cast.CastUtils.InitStateType;
453462

0 commit comments

Comments
 (0)