2020-05-21 15:28:19 +02:00
|
|
|
import playbackManager from 'playbackManager';
|
|
|
|
import layoutManager from 'layoutManager';
|
|
|
|
import events from 'events';
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-05-21 15:28:19 +02:00
|
|
|
var orientationLocked;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-21 15:28:19 +02:00
|
|
|
function onOrientationChangeSuccess() {
|
|
|
|
orientationLocked = true;
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-05-21 15:28:19 +02:00
|
|
|
function onOrientationChangeError(err) {
|
|
|
|
orientationLocked = false;
|
|
|
|
console.error('error locking orientation: ' + err);
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-21 15:28:19 +02:00
|
|
|
events.on(playbackManager, 'playbackstart', function (e, player, state) {
|
|
|
|
var isLocalVideo = player.isLocalPlayer && !player.isExternalPlayer && playbackManager.isPlayingVideo(player);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-21 15:28:19 +02:00
|
|
|
if (isLocalVideo && layoutManager.mobile) {
|
|
|
|
/* eslint-disable-next-line compat/compat */
|
2020-08-25 10:12:35 +09:00
|
|
|
var lockOrientation = window.screen.lockOrientation || window.screen.mozLockOrientation || window.screen.msLockOrientation || (window.screen.orientation && window.screen.orientation.lock);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-21 15:28:19 +02:00
|
|
|
if (lockOrientation) {
|
|
|
|
try {
|
|
|
|
var promise = lockOrientation('landscape');
|
|
|
|
if (promise.then) {
|
|
|
|
promise.then(onOrientationChangeSuccess, onOrientationChangeError);
|
|
|
|
} else {
|
|
|
|
// returns a boolean
|
|
|
|
orientationLocked = promise;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2020-05-21 15:28:19 +02:00
|
|
|
} catch (err) {
|
|
|
|
onOrientationChangeError(err);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
2020-05-21 15:28:19 +02:00
|
|
|
}
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-21 15:28:19 +02:00
|
|
|
events.on(playbackManager, 'playbackstop', function (e, playbackStopInfo) {
|
|
|
|
if (orientationLocked && !playbackStopInfo.nextMediaType) {
|
|
|
|
/* eslint-disable-next-line compat/compat */
|
2020-08-25 10:12:35 +09:00
|
|
|
var unlockOrientation = window.screen.unlockOrientation || window.screen.mozUnlockOrientation || window.screen.msUnlockOrientation || (window.screen.orientation && window.screen.orientation.unlock);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-21 15:28:19 +02:00
|
|
|
if (unlockOrientation) {
|
|
|
|
try {
|
|
|
|
unlockOrientation();
|
|
|
|
} catch (err) {
|
|
|
|
console.error('error unlocking orientation: ' + err);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2020-05-21 15:28:19 +02:00
|
|
|
orientationLocked = false;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2020-05-21 15:28:19 +02:00
|
|
|
}
|
2020-02-22 11:47:03 -05:00
|
|
|
});
|