Fix screen flow (#40)

* Fix screen flow

* Update ice state
This commit is contained in:
giongto35 2019-05-25 14:14:14 +08:00 committed by GitHub
parent 16578795e1
commit 1d0bcfdfc5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 2 deletions

View file

@ -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);

2
static/js/global.js vendored
View file

@ -57,3 +57,5 @@ let menuTop = MENU_TOP_POSITION;
// Screen state
let isLayoutSwitched = false;
var gameReady = false;
var iceSuccess = true;

15
static/js/ws.js vendored
View file

@ -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";