blob: 4a6c7e65315e19b2aa761aec95deb0dd6bf82585 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
(() => {
const internals = {
port: null,
onMessage(message) {
internals[message.action](message.data);
},
async joinAudioCall(data) {
try {
const mediaStream = await navigator.mediaDevices.getUserMedia({ audio: true });
internals.createAudioElement(data.tada);
}
catch (err) {
internals.port.postMessage({
action: 'error'
});
internals.port.disconnect();
internals.createAudioElement(data.tada);
}
},
hangUp() {
document.querySelectorAll('.junction-call-audio').forEach((audioElement) => audioElement.remove());
internals.port.disconnect();
},
createAudioElement(source, type = 'audio/wav') {
const audioElement = document.createElement('audio');
audioElement.setAttribute('class', 'junction-call-audio');
audioElement.src = source;
audioElement.autoplay = 'autoplay';
audioElement.type = type;
document.querySelector('body').appendChild(audioElement);
}
};
internals.port = chrome.runtime.connect({ name:"content" });
internals.port.onMessage.addListener(internals.onMessage);
})();
// Indicates to the background script that we executed correctly
true;
|