Skip to content

Commit

Permalink
Only support unprefixed orientation API
Browse files Browse the repository at this point in the history
Prefixed versions of the screen orientation API are not compatible
with the unprefixed version.  Until there is demand for prefixed
versions, only use the unprefixed version (Chrome & Firefox).
Prefixed versions should be supported through a polyfill, if at all.

This also fixes a bug in the demo app that caused the screen
orientation exception to be silently ignored.

Closes #1111

Change-Id: I9a6e963e6312983bc4bf629ecb2b8e1ad782c49c
  • Loading branch information
joeyparrish committed Dec 4, 2017
1 parent 1c0a644 commit c24cf79
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
26 changes: 7 additions & 19 deletions demo/common/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,8 @@ ShakaControls.prototype.init = function(castProxy, onError, notifyCastStatus) {
this.castProxy_.addEventListener(
'caststatuschanged', this.onCastStatusChange_.bind(this));

var screenOrientation = this.getScreenOrientation_();
if (screenOrientation) {
screenOrientation.addEventListener(
if (screen.orientation) {
screen.orientation.addEventListener(
'change', this.onScreenRotation_.bind(this));
}
};
Expand All @@ -208,31 +207,20 @@ ShakaControls.prototype.init = function(castProxy, onError, notifyCastStatus) {
* @private
*/
ShakaControls.prototype.onScreenRotation_ = function() {
var orientation = this.getScreenOrientation_();
if (!this.video_ || this.video_.readyState == 0 || !orientation ||
if (!this.video_ ||
this.video_.readyState == 0 ||
this.castProxy_.isCasting()) return;
if (orientation.type.indexOf('landscape') >= 0 &&

if (screen.orientation.type.indexOf('landscape') >= 0 &&
!document.fullscreenElement) {
this.videoContainer_.requestFullscreen();
} else if (orientation.type.indexOf('portrait') >= 0 &&
} else if (screen.orientation.type.indexOf('portrait') >= 0 &&
document.fullscreenElement) {
document.exitFullscreen();
}
};


/**
* Get screen orientation.
* Screen Orientation is implemented with a prefix for some browsers.
* https://developer.mozilla.org/en-US/docs/Web/API/Screen/orientation
* @return {?ScreenOrientation}
* @private
*/
ShakaControls.prototype.getScreenOrientation_ = function() {
return screen.orientation || screen.mozOrientation || screen.msOrientation;
};


/**
* Initializes minimal player controls. Used on both sender (indirectly) and
* receiver (directly).
Expand Down
4 changes: 4 additions & 0 deletions demo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ shakaDemo.init = function() {
shakaDemo.postBrowserCheckParams_(params);
window.addEventListener('hashchange', shakaDemo.updateFromHash_);
});
}).catch(function(error) {
// Some part of the setup of the demo app threw an error.
// Notify the user of this.
shakaDemo.onError_(/** @type {!shaka.util.Error} */ (error));
});
}
};
Expand Down

0 comments on commit c24cf79

Please sign in to comment.