From 4c9762931da63d165509c199c1862ea533b84581 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Tue, 24 Nov 2020 16:29:19 +0100 Subject: [PATCH] Prevent multiple connections. --- static/sfu.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/static/sfu.js b/static/sfu.js index 7c21fca..60f1911 100644 --- a/static/sfu.js +++ b/static/sfu.js @@ -1922,12 +1922,21 @@ function displayMessage(message) { return displayError(message, "info"); } -document.getElementById('userform').onsubmit = function(e) { +let connecting = false; + +document.getElementById('userform').onsubmit = async function(e) { e.preventDefault(); - let username = getInputElement('username').value.trim(); - let password = getInputElement('password').value; - storeUserPass(username, password); - serverConnect(); + if(connecting) + return; + connecting = true; + try { + let username = getInputElement('username').value.trim(); + let password = getInputElement('password').value; + storeUserPass(username, password); + serverConnect(); + } finally { + connecting = false; + } }; document.getElementById('disconnectbutton').onclick = function(e) { @@ -2027,6 +2036,8 @@ window.onclick = function(event) { }; async function serverConnect() { + if(serverConnection && serverConnection.socket) + serverConnection.close(); serverConnection = new ServerConnection(); serverConnection.onconnected = gotConnected; serverConnection.onclose = gotClose;