Use audioReady

This commit is contained in:
giongto35 2019-06-07 22:50:46 +08:00
parent 5f373c932f
commit 7d2bd2f698
2 changed files with 11 additions and 3 deletions

2
static/js/global.js vendored
View file

@ -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"}]

12
static/js/ws.js vendored
View file

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