Skip to content

Commit

Permalink
More refactor and more consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukewh committed Apr 19, 2023
1 parent 988b832 commit 099703e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gathertown",
"version": "0.2.7",
"version": "0.2.9",
"description": "A better way to meet.",
"main": "main.js",
"scripts": {
Expand Down
67 changes: 47 additions & 20 deletions renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ navigator.mediaDevices.getDisplayMedia = async () => {
return stream;
};

let virtualShareBtn = null;

const showBtn = (btn) => {
btn.style.display = "flex";
};
Expand All @@ -40,21 +38,25 @@ const getScreenShareBtn = () => {
return null;
};

const initShareBtn = () => {
let screenShareBtn = null;
if (window.game && window.game.spaceId) {
screenShareBtn = getScreenShareBtn();
const getVirtualBtn = () => {
const btns = document.querySelectorAll("[aria-label='Screen share']");
if (btns.length > 1) {
return Array.from(btns).filter((btn) => btn.dataset.isVirtual)[0];
}
return null;
};

if (!screenShareBtn) {
setTimeout(initShareBtn, 1000);
return;
const setupBtns = () => {
const screenShareBtn = getScreenShareBtn();
const virtualBtn = getVirtualBtn();
if (virtualBtn) {
return virtualBtn;
}

virtualShareBtn = screenShareBtn.cloneNode(true);
const virtualShareBtn = screenShareBtn.cloneNode(true);
virtualShareBtn.dataset.isVirtual = true;
console.log(virtualShareBtn);
virtualShareBtn.title = "Virtual";

screenShareBtn.title = "Original";
screenShareBtn.parentNode.appendChild(virtualShareBtn);
showBtn(virtualShareBtn);
hideBtn(screenShareBtn);
Expand All @@ -65,11 +67,28 @@ const initShareBtn = () => {
});

screenShareBtn.addEventListener("click", (e) => {
showBtn(virtualShareBtn);
hideBtn(getScreenShareBtn());
setTimeout(() => {
setupBtns();
showBtn(screenShareBtn);
hideBtn(virtualShareBtn);
}, 500);
});

//setTimeout(initShareBtn, 60 * 1000);
return virtualShareBtn;
};

const initShareBtn = () => {
let screenShareBtn = null;
if (window.game && window.game.spaceId) {
screenShareBtn = getScreenShareBtn();
}

if (!screenShareBtn) {
setTimeout(initShareBtn, 1000);
return;
}

setupBtns();
};

initShareBtn();
Expand All @@ -87,20 +106,28 @@ const sourceSelector = async () => {
const selector = buildSourceSelector(sources);
document.body.appendChild(selector);
const sourceEls = selector.querySelectorAll(".source");
const screenShareBtn = getScreenShareBtn();
for (const sourceEl of sourceEls) {
sourceEl.addEventListener("click", (e) => {
e.stopImmediatePropagation();
const target = findTargetByClass(e.target, "source");
const id = target.id;
sourceId = id;
selector.parentNode.removeChild(selector);


const screenShareBtn = getScreenShareBtn();

// click this so that it's active
screenShareBtn.click();
showBtn(screenShareBtn);
hideBtn(virtualShareBtn);

setTimeout(() => {
showBtn(getScreenShareBtn());
hideBtn(getVirtualBtn());
}, 500);

// Remove the selector
selector.parentNode.removeChild(selector);
});
}

const closeEl = selector.querySelector(".close");
closeEl.addEventListener("click", (e) => {
selector.parentNode.removeChild(selector);
Expand Down
2 changes: 1 addition & 1 deletion snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: gathertown
version: 0.2.8
version: 0.2.9
summary: A better way to meet.
description: |
Electron wrapper for Gather Town
Expand Down

0 comments on commit 099703e

Please sign in to comment.