Guard unsupported web orientation methods

This commit is contained in:
2026-08-12 14:15:50 -07:00
parent 42608bd8d1
commit a1579eebad

View File

@@ -139,16 +139,20 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
navigationUI: 'hide', navigationUI: 'hide',
}); });
if (orientation === 'all' || !orientation || autorotate) { if (orientation === 'all' || !orientation || autorotate) {
if (typeof screen.orientation?.unlock === 'function') {
screen.orientation.unlock(); screen.orientation.unlock();
} else { }
} else if (typeof screen.orientation?.lock === 'function') {
await screen.orientation.lock(orientation); await screen.orientation.lock(orientation);
} }
} else { } else {
if (document.fullscreenElement) { if (document.fullscreenElement) {
await document.exitFullscreen(); await document.exitFullscreen();
} }
if (typeof screen.orientation?.unlock === 'function') {
screen.orientation.unlock(); screen.orientation.unlock();
} }
}
} catch (e) { } catch (e) {
// Changing fullscreen status without a button click is not allowed so it throws. // Changing fullscreen status without a button click is not allowed so it throws.
// Some browsers also used to throw when locking screen orientation was not supported. // Some browsers also used to throw when locking screen orientation was not supported.