Skip to content

Commit 4be60c6

Browse files
committed
handle fullscreen for embed
1 parent 58f2908 commit 4be60c6

1 file changed

Lines changed: 50 additions & 2 deletions

File tree

‎src/containers/stage-header.jsx‎

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,56 @@ const mapDispatchToProps = dispatch => ({
9898
onSetStageLarge: () => dispatch(setStageSize(STAGE_SIZE_MODES.large)),
9999
onSetStageSmall: () => dispatch(setStageSize(STAGE_SIZE_MODES.small)),
100100
onSetStageFull: () => dispatch(setStageSize(STAGE_SIZE_MODES.full)),
101-
onSetStageFullScreen: () => dispatch(setFullScreen(true)),
102-
onSetStageUnFullScreen: () => dispatch(setFullScreen(false)),
101+
onSetStageFullScreen: () => {
102+
if (window.location.pathname === "/") {
103+
if (document.documentElement.requestFullscreen) {
104+
document.documentElement.requestFullscreen().then(() => {
105+
dispatch(setFullScreen(true));
106+
}).catch(err => {
107+
console.error('Failed to enter fullscreen:', err);
108+
});
109+
} else if (document.documentElement.webkitRequestFullscreen) { // Safari
110+
document.documentElement.webkitRequestFullscreen();
111+
dispatch(setFullScreen(true));
112+
} else if (document.documentElement.mozRequestFullScreen) { // Firefox
113+
document.documentElement.mozRequestFullScreen();
114+
dispatch(setFullScreen(true));
115+
} else if (document.documentElement.msRequestFullscreen) { // IE/Edge
116+
document.documentElement.msRequestFullscreen();
117+
dispatch(setFullScreen(true));
118+
} else {
119+
console.warn('Fullscreen API is not supported in this browser.');
120+
}
121+
} else {
122+
dispatch(setFullScreen(true));
123+
}
124+
},
125+
onSetStageUnFullScreen: () => {
126+
// Check if the document is currently in fullscreen
127+
if (document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement) {
128+
if (document.exitFullscreen) {
129+
document.exitFullscreen().then(() => {
130+
dispatch(setFullScreen(false));
131+
}).catch(err => {
132+
console.error('Failed to exit fullscreen:', err);
133+
});
134+
} else if (document.webkitExitFullscreen) { // Safari
135+
document.webkitExitFullscreen();
136+
dispatch(setFullScreen(false));
137+
} else if (document.mozCancelFullScreen) { // Firefox
138+
document.mozCancelFullScreen();
139+
dispatch(setFullScreen(false));
140+
} else if (document.msExitFullscreen) { // IE/Edge
141+
document.msExitFullscreen();
142+
dispatch(setFullScreen(false));
143+
} else {
144+
console.warn('Fullscreen API is not supported in this browser.');
145+
}
146+
} else {
147+
// Not in fullscreen, just dispatch the action
148+
dispatch(setFullScreen(false));
149+
}
150+
},
103151
onOpenSettings: () => dispatch(openSettingsModal())
104152
});
105153

0 commit comments

Comments
 (0)