diff options
| author | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2020-09-27 17:31:21 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2020-09-27 17:31:21 +0200 |
| commit | 1ed219c8314a0ca1b95ef8593bb608b7659c87a3 (patch) | |
| tree | 9fd778c197cc44559049c7ed3385a19ecf2f5257 /extension/junction.js | |
| parent | 1aefbf569ac489946e2552ce6c10697c67ea55b8 (diff) | |
Add firefox extensionrbdr-setup-extension
Diffstat (limited to 'extension/junction.js')
| -rw-r--r-- | extension/junction.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/extension/junction.js b/extension/junction.js new file mode 100644 index 0000000..7de7c28 --- /dev/null +++ b/extension/junction.js @@ -0,0 +1,64 @@ +const internals = { + + isInCallState: false, + + icons: { + call: { + 16: 'icons/action-16.png', + 32: 'icons/action-32.png' + }, + + hangUp: { + 16: 'icons/hang_up-16.png', + 32: 'icons/hang_up-32.png' + } + }, + + onClick() { + if (internals.isInCall()) { + return internals.hangUp(); + } + + return internals.joinAudioCall(); + }, + + async joinAudioCall() { + + internals.isInCallState = true; + internals.setIcon('hangUp'); + const tabs = await browser.tabs.query({ + currentWindow: true, + active: true + }); + + internals.createAudioElement(browser.runtime.getURL('sounds/tada.wav')); + }, + + hangUp() { + + document.querySelectorAll('audio').forEach((audioElement) => audioElement.remove()); + internals.setIcon('call'); + internals.isInCallState = false; + }, + + createAudioElement(source) { + + const audioElement = document.createElement('audio'); + audioElement.src = source; + audioElement.autoplay = 'autoplay'; + document.querySelector('body').appendChild(audioElement); + }, + + isInCall() { + return internals.isInCallState; // this should be replaced with actually checking the built stuff + }, + + setIcon(iconSet) { + + browser.browserAction.setIcon({ + path: internals.icons[iconSet] + }); + } +}; + +browser.browserAction.onClicked.addListener(internals.onClick); |