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

fix(FEC-7266): reposition & resize captions when changing to/from full screen #155

Merged
merged 9 commits into from
Nov 1, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
42 changes: 41 additions & 1 deletion src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ const OFF: string = 'off';
*/
const DURATION_OFFSET: number = 0.1;

/**
* The toggle fullscreen rendering timeout value
* @type {number}
* @const
*/
const REPOSITION_CUES_TIMEOUT: number = 1000;

/**
* The HTML5 player class.
* @classdesc
Expand Down Expand Up @@ -286,7 +293,12 @@ export default class Player extends FakeEventTarget {
* @private
*/
_fullscreen: boolean;

/**
* holds false or an id for the timeout the reposition the text cues after togelling full screen
* @type {any}
* @private
*/
_repositionCuesTimeout: any;
/**
* @param {Object} config - The configuration for the player instance.
* @constructor
Expand All @@ -309,6 +321,7 @@ export default class Player extends FakeEventTarget {
this._createPlayerContainer();
this._appendPosterEl();
this.configure(config);
this._repositionCuesTimeout = false;
}

// <editor-fold desc="Public API">
Expand Down Expand Up @@ -1157,7 +1170,34 @@ export default class Player extends FakeEventTarget {
this._eventManager.listen(this, Html5Events.RATE_CHANGE, () => {
this._playbackAttributesState.rate = this.playbackRate;
});
this._eventManager.listen(this, CustomEvents.ENTER_FULLSCREEN, () => {
this._resetTextCuesAndReposition();
});
this._eventManager.listen(this, CustomEvents.EXIT_FULLSCREEN, () => {
this._resetTextCuesAndReposition();
});
}
}

/**
* Reset the active cues hasBeenReset = true and then reposition it, timeout here is for the screen to
* finish render the fullscreen
* @returns {void}
* @private
*/
_resetTextCuesAndReposition(): void {
this._updateTextDisplay([]);
for (let i = 0; i < this._activeTextCues.length; i++) {
this._activeTextCues[i].hasBeenReset = true;
}
// handling only the last reposition
if (this._repositionCuesTimeout) {
clearTimeout(this._repositionCuesTimeout);
}
this._repositionCuesTimeout = setTimeout(() => {
processCues(window, this._activeTextCues, this._textDisplayEl);
this._repositionCuesTimeout = false;
}, REPOSITION_CUES_TIMEOUT);
}

/**
Expand Down
24 changes: 24 additions & 0 deletions test/src/player.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2648,3 +2648,27 @@ describe('_getLanguage', function () {
player._getLanguage(configuredLanguage, offTrack, "text").should.equals(gerTrack.language);
});
});


describe('_resetTextCuesAndReposition', function () {
let config, player, sandbox;

beforeEach(() => {
sandbox = sinon.sandbox.create();
config = getConfigStructure();
player = new Player(config);
});

afterEach(() => {
sandbox.restore();
player.destroy();
});

it('should reset the active text cues', () => {
player._activeTextCues[0]={};
player._resetTextCuesAndReposition();
let cue = player._activeTextCues[0];
cue.hasBeenReset.should.equals(true);
});
});