diff --git a/src/js/player.js b/src/js/player.js index 0c87623531..c9650696d1 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -1177,8 +1177,7 @@ class Player extends Component { 'playerElIngest': this.playerElIngest_ || false, 'vtt.js': this.options_['vtt.js'], 'canOverridePoster': !!this.options_.techCanOverridePoster, - 'enableSourceset': this.options_.enableSourceset, - 'Promise': this.options_.Promise + 'enableSourceset': this.options_.enableSourceset }; TRACK_TYPES.names.forEach((name) => { @@ -2364,15 +2363,9 @@ class Player extends Component { * the promise from play is fulfilled. */ play() { - const PromiseClass = this.options_.Promise || window.Promise; - - if (PromiseClass) { - return new PromiseClass((resolve) => { - this.play_(resolve); - }); - } - - return this.play_(); + return new Promise((resolve) => { + this.play_(resolve); + }); } /** @@ -2860,38 +2853,32 @@ class Player extends Component { * @fires Player#fullscreenchange */ requestFullscreen(fullscreenOptions) { - const PromiseClass = this.options_.Promise || window.Promise; + const self = this; - if (PromiseClass) { - const self = this; - - return new PromiseClass((resolve, reject) => { - function offHandler() { - self.off('fullscreenerror', errorHandler); - self.off('fullscreenchange', changeHandler); - } - function changeHandler() { - offHandler(); - resolve(); - } - function errorHandler(e, err) { - offHandler(); - reject(err); - } - - self.one('fullscreenchange', changeHandler); - self.one('fullscreenerror', errorHandler); + return new Promise((resolve, reject) => { + function offHandler() { + self.off('fullscreenerror', errorHandler); + self.off('fullscreenchange', changeHandler); + } + function changeHandler() { + offHandler(); + resolve(); + } + function errorHandler(e, err) { + offHandler(); + reject(err); + } - const promise = self.requestFullscreenHelper_(fullscreenOptions); + self.one('fullscreenchange', changeHandler); + self.one('fullscreenerror', errorHandler); - if (promise) { - promise.then(offHandler, offHandler); - promise.then(resolve, reject); - } - }); - } + const promise = self.requestFullscreenHelper_(fullscreenOptions); - return this.requestFullscreenHelper_(); + if (promise) { + promise.then(offHandler, offHandler); + promise.then(resolve, reject); + } + }); } requestFullscreenHelper_(fullscreenOptions) { @@ -2916,6 +2903,7 @@ class Player extends Component { if (this.fsApi_.requestFullscreen) { const promise = this.el_[this.fsApi_.requestFullscreen](fsOptions); + // Even on browsers with promise support this may not return a promise if (promise) { promise.then(() => this.isFullscreen(true), () => this.isFullscreen(false)); } @@ -2938,45 +2926,40 @@ class Player extends Component { * @fires Player#fullscreenchange */ exitFullscreen() { - const PromiseClass = this.options_.Promise || window.Promise; - - if (PromiseClass) { - const self = this; + const self = this; - return new PromiseClass((resolve, reject) => { - function offHandler() { - self.off('fullscreenerror', errorHandler); - self.off('fullscreenchange', changeHandler); - } - function changeHandler() { - offHandler(); - resolve(); - } - function errorHandler(e, err) { - offHandler(); - reject(err); - } - - self.one('fullscreenchange', changeHandler); - self.one('fullscreenerror', errorHandler); + return new Promise((resolve, reject) => { + function offHandler() { + self.off('fullscreenerror', errorHandler); + self.off('fullscreenchange', changeHandler); + } + function changeHandler() { + offHandler(); + resolve(); + } + function errorHandler(e, err) { + offHandler(); + reject(err); + } - const promise = self.exitFullscreenHelper_(); + self.one('fullscreenchange', changeHandler); + self.one('fullscreenerror', errorHandler); - if (promise) { - promise.then(offHandler, offHandler); - // map the promise to our resolve/reject methods - promise.then(resolve, reject); - } - }); - } + const promise = self.exitFullscreenHelper_(); - return this.exitFullscreenHelper_(); + if (promise) { + promise.then(offHandler, offHandler); + // map the promise to our resolve/reject methods + promise.then(resolve, reject); + } + }); } exitFullscreenHelper_() { if (this.fsApi_.requestFullscreen) { const promise = document[this.fsApi_.exitFullscreen](); + // Even on browsers with promise support this may not return a promise if (promise) { // we're splitting the promise here, so, we want to catch the // potential error so that this chain doesn't have unhandled errors @@ -3564,9 +3547,7 @@ class Player extends Component { * and calls `reset` on the `tech`. */ reset() { - const PromiseClass = this.options_.Promise || window.Promise; - - if (this.paused() || !PromiseClass) { + if (this.paused()) { this.doReset_(); } else { const playPromise = this.play(); diff --git a/src/js/tech/tech.js b/src/js/tech/tech.js index 53a1077903..e3ecdca22e 100644 --- a/src/js/tech/tech.js +++ b/src/js/tech/tech.js @@ -831,11 +831,7 @@ class Tech extends Component { * @abstract */ requestPictureInPicture() { - const PromiseClass = this.options_.Promise || window.Promise; - - if (PromiseClass) { - return PromiseClass.reject(); - } + return Promise.reject(); } /** diff --git a/test/unit/utils/promise.test.js b/test/unit/utils/promise.test.js index 2171024fc1..bafd76fadb 100644 --- a/test/unit/utils/promise.test.js +++ b/test/unit/utils/promise.test.js @@ -5,12 +5,6 @@ import * as promise from '../../../src/js/utils/promise'; QUnit.module('utils/promise'); QUnit.test('can correctly identify a native Promise (if supported)', function(assert) { - - // If Promises aren't supported, skip this. - if (!window.Promise) { - return assert.expect(0); - } - assert.ok(promise.isPromise(new window.Promise((resolve) => resolve())), 'a native Promise was recognized'); });