]> git.r.bdr.sh - rbdr/junction/blame_incremental - extension/junction.js
Merge branch 'server' into 'main'
[rbdr/junction] / extension / junction.js
... / ...
CommitLineData
1const internals = {
2
3 isInCallState: false,
4
5 icons: {
6 call: {
7 16: 'icons/action-16.png',
8 32: 'icons/action-32.png'
9 },
10
11 hangUp: {
12 16: 'icons/hang_up-16.png',
13 32: 'icons/hang_up-32.png'
14 }
15 },
16
17 onClick() {
18 if (internals.isInCall()) {
19 return internals.hangUp();
20 }
21
22 return internals.joinAudioCall();
23 },
24
25 async joinAudioCall() {
26
27 internals.isInCallState = true;
28 internals.setIcon('hangUp');
29 const tabs = await browser.tabs.query({
30 currentWindow: true,
31 active: true
32 });
33
34 internals.createAudioElement(browser.runtime.getURL('sounds/tada.wav'));
35 },
36
37 hangUp() {
38
39 document.querySelectorAll('audio').forEach((audioElement) => audioElement.remove());
40 internals.setIcon('call');
41 internals.isInCallState = false;
42 },
43
44 createAudioElement(source) {
45
46 const audioElement = document.createElement('audio');
47 audioElement.src = source;
48 audioElement.autoplay = 'autoplay';
49 document.querySelector('body').appendChild(audioElement);
50 },
51
52 isInCall() {
53 return internals.isInCallState; // this should be replaced with actually checking the built stuff
54 },
55
56 setIcon(iconSet) {
57
58 browser.browserAction.setIcon({
59 path: internals.icons[iconSet]
60 });
61 }
62};
63
64browser.browserAction.onClicked.addListener(internals.onClick);