|
|
@@ -2,15 +2,26 @@ import {useEffect, useRef, useState} from "react";
|
|
|
import {ROUTE_PATH} from "@constants/routes";
|
|
|
import {openFullScreen} from "@utils/helpers";
|
|
|
import {useNavigate} from "react-router-dom";
|
|
|
-
|
|
|
+const objInfo={
|
|
|
+ closeCount:0
|
|
|
+}
|
|
|
const useGameIFrame = () => {
|
|
|
const iFrameRef = useRef(null);
|
|
|
const [isGameLoad,setIsGameLoad]=useState(false);
|
|
|
const navigate = useNavigate();
|
|
|
const onBack=()=>{
|
|
|
// dispatch(reqGameInfo());
|
|
|
+ if (iFrameRef.extBackFunc!=null){
|
|
|
+ iFrameRef.extBackFunc();
|
|
|
+ return;
|
|
|
+ }
|
|
|
navigate(ROUTE_PATH.BACK);
|
|
|
}
|
|
|
+ const checkCloseCount=()=>{
|
|
|
+ if (objInfo.closeCount>=2){
|
|
|
+ onBack();
|
|
|
+ }
|
|
|
+ }
|
|
|
const receiveMessage=(event)=>{
|
|
|
let data=event.data;
|
|
|
// console.log(data);
|
|
|
@@ -30,6 +41,8 @@ const useGameIFrame = () => {
|
|
|
}
|
|
|
else if (data.cmd==="closeLoading"){
|
|
|
setIsGameLoad(true);
|
|
|
+ objInfo.closeCount++;
|
|
|
+ checkCloseCount();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -55,6 +68,7 @@ const useGameIFrame = () => {
|
|
|
},5000);
|
|
|
}
|
|
|
window.addEventListener("message", receiveMessage, false);
|
|
|
+ objInfo.closeCount=0;
|
|
|
}
|
|
|
const removeGameEvent=()=>{
|
|
|
const gameFrame = iFrameRef.current;
|
|
|
@@ -63,6 +77,7 @@ const useGameIFrame = () => {
|
|
|
clearGameTimeout();
|
|
|
}
|
|
|
window.removeEventListener("message", receiveMessage);
|
|
|
+ objInfo.closeCount=0;
|
|
|
}
|
|
|
useEffect(() => {
|
|
|
initGameEvent();
|