From 1d0bcfdfc5cb9b1a7c0553c6c8f4ce97543dae89 Mon Sep 17 00:00:00 2001 From: giongto35 Date: Sat, 25 May 2019 14:14:14 +0800 Subject: [PATCH] Fix screen flow (#40) * Fix screen flow * Update ice state --- static/js/controller.js | 2 +- static/js/global.js | 2 ++ static/js/ws.js | 15 ++++++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/static/js/controller.js b/static/js/controller.js index 762baa29..26e094b8 100644 --- a/static/js/controller.js +++ b/static/js/controller.js @@ -27,7 +27,7 @@ function showMenuScreen() { $("#btn-join").html("play"); // show menu scene - $("#game-screen").show().delay(DEBUG ? 0 : 500).fadeOut(DEBUG ? 0 : 0, function () { + $("#game-screen").show().delay(DEBUG ? 0 : 0).fadeOut(DEBUG ? 0 : 0, function () { log("Loading menu screen"); $("#menu-screen").fadeIn(DEBUG ? 0 : 0, function () { pickGame(gameIdx); diff --git a/static/js/global.js b/static/js/global.js index b463a7d9..b99ea75e 100644 --- a/static/js/global.js +++ b/static/js/global.js @@ -57,3 +57,5 @@ let menuTop = MENU_TOP_POSITION; // Screen state let isLayoutSwitched = false; +var gameReady = false; +var iceSuccess = true; diff --git a/static/js/ws.js b/static/js/ws.js index 6c5fa4fb..1451e275 100644 --- a/static/js/ws.js +++ b/static/js/ws.js @@ -171,8 +171,14 @@ function startWebRTC() { log(`iceConnectionState: ${pc.iceConnectionState}`); if (pc.iceConnectionState === "connected") { + gameReady = true + iceSuccess = true //conn.send(JSON.stringify({"id": "start", "data": ""})); } + else if (pc.iceConnectionState === "failed") { + gameReady = false + iceSuccess = false + } else if (pc.iceConnectionState === "disconnected") { stopInputTimer(); } @@ -182,7 +188,7 @@ function startWebRTC() { // video channel pc.ontrack = function (event) { document.getElementById("game-screen").srcObject = event.streams[0]; - $("#game-screen").show(); + //$("#game-screen").show(); } @@ -212,6 +218,13 @@ function startWebRTC() { } function startGame() { + if (!iceSuccess) { + popup("Game cannot load. Please refresh") + } + // TODO: Add while loop + if (!gameReady) { + popup("Game is not ready yet. Please wait") + } log("Starting game screen"); screenState = "game";