]>
git.r.bdr.sh - rbdr/junction/blob - extension/content_script.js
741e1c4a88df1b03e1ca4c348d910adc866b193e
3 const io
= require('socket.io-client');
7 kSocketUrl: 'http://unlimited.pizza:8000/',
14 internals
[message
.action
](message
.data
);
17 async
joinAudioCall(data
) {
20 const mediaStream
= await navigator
.mediaDevices
.getUserMedia({ audio: true });
22 internals
.socket
= io(internals
.kSocketUrl
);
24 console
.log('Connecting to server');
25 internals
.socket
.on('connect', function() {
27 console
.log("Connected to signaling server");
28 internals
.socket
.emit('join', {
33 internals
.socket
.on('disconnect', function() {
35 console
.log("disconnected from signaling server");
38 internals
.socket
.on('addPeer', function(data
) {
42 console
.log(`There are now ${internals.peers} participants`);
45 internals
.socket
.on('removePeer', function() {
48 console
.log(`There are now ${internals.peers} participants`);
52 internals
.createAudioElement(data
.tada
);
56 internals
.port
.postMessage({
59 internals
.port
.disconnect();
60 internals
.createAudioElement(data
.tada
);
65 document
.querySelectorAll('.junction-call-audio').forEach((audioElement
) => audioElement
.remove());
66 internals
.socket
.close();
67 internals
.port
.disconnect();
70 createAudioElement(source
, type
= 'audio/wav') {
72 const audioElement
= document
.createElement('audio');
73 audioElement
.setAttribute('class', 'junction-call-audio');
74 audioElement
.src
= source
;
75 audioElement
.autoplay
= 'autoplay';
76 audioElement
.type
= type
;
77 document
.querySelector('body').appendChild(audioElement
);
81 internals
.port
= chrome
.runtime
.connect({ name:"content" });
82 internals
.port
.onMessage
.addListener(internals
.onMessage
);
85 // Indicates to the background script that we executed correctly