From 7d2bd2f69816595cb3a4c499d7eeb5601fc91709 Mon Sep 17 00:00:00 2001 From: giongto35 Date: Fri, 7 Jun 2019 22:50:46 +0800 Subject: [PATCH] Use audioReady --- static/js/global.js | 2 ++ static/js/ws.js | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/static/js/global.js b/static/js/global.js index f2ce2309..df544354 100644 --- a/static/js/global.js +++ b/static/js/global.js @@ -59,6 +59,8 @@ let menuTop = MENU_TOP_POSITION; let isLayoutSwitched = false; var gameReady = false; +var inputReady = false; +var audioReady = false; var iceSuccess = true; var iceSent = false; // TODO: set to false in some init event var defaultICE = [{urls: "stun:stun.l.google.com:19302"}] diff --git a/static/js/ws.js b/static/js/ws.js index 1b1f7d45..e1cd5f2a 100644 --- a/static/js/ws.js +++ b/static/js/ws.js @@ -110,7 +110,10 @@ function startWebRTC() { negotiated: true, id: 0, }); - inputChannel.onopen = () => log('inputChannel has opened'); + inputChannel.onopen = () => { + log('inputChannel has opened'); + inputReady = true; + } inputChannel.onclose = () => log('inputChannel has closed'); @@ -155,7 +158,10 @@ function startWebRTC() { id: 1, maxRetransmits: 0 }) - audioChannel.onopen = () => log('audioChannel has opened'); + audioChannel.onopen = () => { + log('audioChannel has opened'); + audioReady = true; + } audioChannel.onclose = () => log('audioChannel has closed'); audioChannel.onmessage = (e) => { @@ -243,7 +249,7 @@ function startGame() { return; } // TODO: Add while loop - if (!gameReady) { + if (!gameReady || !inputReady || !audioReady) { popup("Game is not ready yet. Please wait"); return; }