From 0bc8129159c17893dd8a1fe60ebb4ab5d91c69ad Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Mon, 9 Nov 2020 01:11:13 +0100 Subject: [PATCH] Disable the present button while setting up a presentation. Users sometimes click on the button multiple times. --- static/sfu.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/static/sfu.js b/static/sfu.js index 48b8292..9fba61a 100644 --- a/static/sfu.js +++ b/static/sfu.js @@ -349,9 +349,21 @@ setViewportHeight(); addEventListener('resize', setViewportHeight); addEventListener('orientationchange', setViewportHeight); -getButtonElement('presentbutton').onclick = function(e) { +getButtonElement('presentbutton').onclick = async function(e) { e.preventDefault(); - addLocalMedia(); + let button = this; + if(!(button instanceof HTMLButtonElement)) + throw new Error('Unexpected type for this.'); + // there's a potential race condition here: the user might click the + // button a second time before the stream is set up and the button hidden. + button.disabled = true; + try { + let id = findUpMedia('local'); + if(!id) + await addLocalMedia(); + } finally { + button.disabled = false; + } }; getButtonElement('unpresentbutton').onclick = function(e) {