1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-22 08:35:57 +01:00

Let setLocal and SharedMedia take the new state as an explicit parameter.

This commit is contained in:
Juliusz Chroboczek 2020-05-04 20:50:24 +02:00
parent ac50973a99
commit 3fec035132

View file

@ -123,12 +123,12 @@ function setConnected(connected) {
document.getElementById('presenterbox').onchange = function(e) { document.getElementById('presenterbox').onchange = function(e) {
e.preventDefault(); e.preventDefault();
setLocalMedia(); setLocalMedia(this.checked);
} }
document.getElementById('sharebox').onchange = function(e) { document.getElementById('sharebox').onchange = function(e) {
e.preventDefault(); e.preventDefault();
setShareMedia(); setShareMedia(this.checked);
} }
async function updateStats(conn, sender) { async function updateStats(conn, sender) {
@ -195,11 +195,11 @@ function displayStats(id) {
let localMediaId = null; let localMediaId = null;
async function setLocalMedia() { async function setLocalMedia(setup) {
if(!getUserPass()) if(!getUserPass())
return; return;
if(!document.getElementById('presenterbox').checked) { if(!setup) {
if(localMediaId) { if(localMediaId) {
up[localMediaId].close(true); up[localMediaId].close(true);
delete(up[localMediaId]); delete(up[localMediaId]);
@ -218,7 +218,7 @@ async function setLocalMedia() {
} catch(e) { } catch(e) {
console.error(e); console.error(e);
document.getElementById('presenterbox').checked = false; document.getElementById('presenterbox').checked = false;
await setLocalMedia(); await setLocalMedia(false);
return; return;
} }
localMediaId = await newUpStream(); localMediaId = await newUpStream();
@ -240,11 +240,11 @@ async function setLocalMedia() {
let shareMediaId = null; let shareMediaId = null;
async function setShareMedia() { async function setShareMedia(setup) {
if(!getUserPass()) if(!getUserPass())
return; return;
if(!document.getElementById('sharebox').checked) { if(!setup) {
if(shareMediaId) { if(shareMediaId) {
up[shareMediaId].close(true); up[shareMediaId].close(true);
delete(up[shareMediaId]); delete(up[shareMediaId]);
@ -262,7 +262,7 @@ async function setShareMedia() {
} catch(e) { } catch(e) {
console.error(e); console.error(e);
document.getElementById('sharebox').checked = false; document.getElementById('sharebox').checked = false;
await setShareMedia(); await setShareMedia(false);
return; return;
} }
shareMediaId = await newUpStream(); shareMediaId = await newUpStream();
@ -273,7 +273,7 @@ async function setShareMedia() {
let sender = c.pc.addTrack(t, stream); let sender = c.pc.addTrack(t, stream);
t.onended = e => { t.onended = e => {
document.getElementById('sharebox').checked = false; document.getElementById('sharebox').checked = false;
setShareMedia(); setShareMedia(false);
} }
c.setInterval(() => { c.setInterval(() => {
updateStats(c, sender); updateStats(c, sender);
@ -408,10 +408,10 @@ function serverConnect() {
setConnected(false); setConnected(false);
document.getElementById('presenterbox').checked = false; document.getElementById('presenterbox').checked = false;
document.getElementById('presenterbox').disabled = true; document.getElementById('presenterbox').disabled = true;
setLocalMedia(); setLocalMedia(false);
document.getElementById('sharebox').checked = false; document.getElementById('sharebox').checked = false;
document.getElementById('sharebox').disabled = true; document.getElementById('sharebox').disabled = true;
setShareMedia(); setShareMedia(false);
for(let id in down) { for(let id in down) {
let c = down[id]; let c = down[id];
delete(down[id]); delete(down[id]);
@ -541,10 +541,10 @@ function gotAbort(id) {
throw new Error('unknown up stream in abort'); throw new Error('unknown up stream in abort');
if(id === localMediaId) { if(id === localMediaId) {
document.getElementById('presenterbox').checked = false; document.getElementById('presenterbox').checked = false;
setLocalMedia(); setLocalMedia(false);
} else if(id === shareMediaId) { } else if(id === shareMediaId) {
document.getElementById('sharebox').checked = false; document.getElementById('sharebox').checked = false;
setShareMedia(); setShareMedia(false);
} else { } else {
console.error('Strange stream in abort'); console.error('Strange stream in abort');
delMedia(id); delMedia(id);
@ -967,8 +967,8 @@ async function getIceServers() {
async function doConnect() { async function doConnect() {
await serverConnect(); await serverConnect();
await setLocalMedia(); await setLocalMedia(document.getElementById('presenterbox').checked);
await setShareMedia(); await setShareMedia(document.getElementById('sharebox').checked);
} }
document.getElementById('userform').onsubmit = async function(e) { document.getElementById('userform').onsubmit = async function(e) {