]>
git.r.bdr.sh - rbdr/junction/blob - extension/content_script.js
a9d713d74150aa9208533f8c24beaab4e1bb4e56
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(socketUrl
);
24 internals
.socket
.on('connect', function() {
26 console
.log("Connected to signaling server");
27 internals
.socket
.emit('join', {
32 internals
.socket
.on('disconnect', function() {
34 console
.log("disconnected from signaling server");
37 internals
.socket
.on('addPeer', function(data
) {
41 console
.log(`There are now ${internals.peers} participants`);
44 internals
.socket
.on('removePeer', function() {
47 console
.log(`There are now ${internals.peers} participants`);
50 internals
.createAudioElement(data
.tada
);
54 internals
.port
.postMessage({
57 internals
.port
.disconnect();
58 internals
.createAudioElement(data
.tada
);
63 document
.querySelectorAll('.junction-call-audio').forEach((audioElement
) => audioElement
.remove());
64 internals
.socket
.close();
65 internals
.port
.disconnect();
68 createAudioElement(source
, type
= 'audio/wav') {
70 const audioElement
= document
.createElement('audio');
71 audioElement
.setAttribute('class', 'junction-call-audio');
72 audioElement
.src
= source
;
73 audioElement
.autoplay
= 'autoplay';
74 audioElement
.type
= type
;
75 document
.querySelector('body').appendChild(audioElement
);
79 internals
.port
= chrome
.runtime
.connect({ name:"content" });
80 internals
.port
.onMessage
.addListener(internals
.onMessage
);
83 // Indicates to the background script that we executed correctly