]>
git.r.bdr.sh - rbdr/junction/blob - extension/content_script.js
84a2fd3bce3ed6bd3cd1a306e860fa9f5eed43df
3 const io
= require('socket.io-client');
7 kSocketUrl: 'https://junction.unlimited.pizza/',
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
, {
23 transports: ['websocket']
26 internals
.socket
.on('error', function(error
) {
28 console
.error('GENERAL ERROR', error
);
31 internals
.socket
.on('connect_error', function(error
) {
33 console
.error('CONNNECT ERROR', error
);
36 internals
.socket
.on('connect', function() {
38 console
.log("Connected to signaling server, group: ", data
.currentUrl
);
39 internals
.socket
.emit('join', {
40 'url': data
.currentUrl
,
44 internals
.socket
.on('disconnect', function() {
46 console
.log("disconnected from signaling server");
49 internals
.socket
.on('addPeer', function(data
) {
53 console
.log(`There are now ${internals.peers} participants`);
56 internals
.socket
.on('removePeer', function() {
59 console
.log(`There are now ${internals.peers} participants`);
62 internals
.createAudioElement(data
.tada
);
66 internals
.port
.postMessage({
69 internals
.port
.disconnect();
70 internals
.createAudioElement(data
.tada
);
75 document
.querySelectorAll('.junction-call-audio').forEach((audioElement
) => audioElement
.remove());
76 internals
.socket
.close();
77 internals
.port
.disconnect();
80 createAudioElement(source
, type
= 'audio/wav') {
82 const audioElement
= document
.createElement('audio');
83 audioElement
.setAttribute('class', 'junction-call-audio');
84 audioElement
.src
= source
;
85 audioElement
.autoplay
= 'autoplay';
86 audioElement
.type
= type
;
87 document
.querySelector('body').appendChild(audioElement
);
91 internals
.port
= chrome
.runtime
.connect({ name:"content" });
92 internals
.port
.onMessage
.addListener(internals
.onMessage
);
95 // Indicates to the background script that we executed correctly