- redirect if websocket is disconnect in gane
Site    - fix bug tv on homa page
This commit is contained in:
Kum1ta
2024-10-09 11:14:43 +02:00
parent 4407901a4a
commit e5c232e207
3 changed files with 23 additions and 7 deletions

View File

@ -6,13 +6,14 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/25 00:00:21 by edbernar #+# #+# */
/* Updated: 2024/10/06 23:49:15 by edbernar ### ########.fr */
/* Updated: 2024/10/09 11:12:43 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
import { MultiOnlineGamePage } from "/static/javascript/multiOnlineGame/multiOnlineGamePage.js"
import { multiLocalGamePage } from "/static/javascript/multiLocalGame/multiLocalGamePage.js"
import { TournamentPage } from "/static/javascript/tournamentPage/TournamentPage.js"
import { createNotification as CN } from "/static/javascript/notification/main.js";
import { settingsPage } from "/static/javascript/settingsPage/settingsPage.js"
import { WaitingGamePage } from "/static/javascript/waitingGame/main.js"
import { ProfilPage } from "/static/javascript/profilPage/main.js";
@ -144,7 +145,15 @@ class Page
window.location.href = '/';
throw Error(error);
});
}
disconnect()
{
if (this.actualPage == MultiOnlineGamePage || this.actualPage == WaitingGamePage)
this.changePage('lobbyPage');
setTimeout(() => {
CN.new("Error", "Connection lost");
}, 1000)
}
};

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/22 17:19:17 by edbernar #+# #+# */
/* Updated: 2024/10/06 23:37:28 by edbernar ### ########.fr */
/* Updated: 2024/10/09 10:51:31 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
@ -47,10 +47,11 @@ class Home3D
static dispose()
{
document.addEventListener('scroll', mouseTracker);
document.removeEventListener('scroll', mouseTracker);
window.removeEventListener('resize', windowUpdater);
document.removeEventListener('mousemove', mouseTracker);
document.removeEventListener('click', redirection);
alreadRedirected = false;
if (!disable3D)
{
@ -127,7 +128,7 @@ function home3D()
scene.add(spotLight);
spotLight.target = screen.screen;
if (Math.random() % 100 > 0.99)
if (Math.random() % 100 > 0.995)
video.pong = files.easterEggVideo;
putObject(files.lampModel, -2.5, 0, 2.5, 3, 0, Math.PI + Math.PI / 8, 0);
putObject(files.plantModel, 1.5, 0, 3, 0.5, 0, 0, 0);
@ -223,7 +224,7 @@ function home3D()
{
raycaster.setFromCamera( mouse, camera );
const intersects = raycaster.intersectObjects( scene.children, false );
if (!screen.canvasVideo)
{
composer.render();
@ -398,9 +399,13 @@ function redirection()
}
moveCamera();
}
let alreadRedirected = false;
function moveCamera()
{
if (alreadRedirected)
return ;
alreadRedirected = true;
const targetPosition = screen.tv.position;
const initialPosition = camera.position.clone();
const startTime = Date.now();

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/31 22:17:24 by edbernar #+# #+# */
/* Updated: 2024/10/08 03:12:29 by edbernar ### ########.fr */
/* Updated: 2024/10/09 11:03:11 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
@ -29,6 +29,7 @@ import { typeChangePfp } from "/static/javascript/typeResponse/typeChangePfp.js"
import { typeUserInfo } from "/static/javascript/typeResponse/typeUserInfo.js";
import { typeLogin } from "/static/javascript/typeResponse/typeLogin.js";
import { typeGame } from "/static/javascript/typeResponse/typeGame.js"
import { pageRenderer } from "/static/javascript/main.js";
let socket = null;
let status = 0;
@ -93,6 +94,8 @@ function launchSocket()
socket.onclose = () => {
status = 0;
console.log('Disconnected');
if (pageRenderer)
pageRenderer.disconnect();
if (lastError != 9013)
{
setTimeout(() => {
@ -110,7 +113,6 @@ function sendRequest(type, content) {
console.warn('Not connected');
return ;
}
console.log(`Send request ${type} content: `, content);
if (content instanceof Object)
coc = JSON.stringify(content);
else