]>
git.r.bdr.sh - rbdr/junction/blob - extension/content_script.js
70c085fa3d98531d18bed7d3e334462ec5f3b90c
5 const io
= require('socket.io-client');
6 const Peers
= require('./peers');
7 const Media
= require('./media');
11 kSocketUrl: 'https://junction.unlimited.pizza/',
18 internals
[message
.action
](message
.data
);
21 async
joinAudioCall(data
) {
23 internals
.tada
= data
.tada
; // Keeping for fun
26 const mediaStream
= await Media
.start();
28 internals
.socket
= io(internals
.kSocketUrl
, {
29 transports: ['websocket']
32 internals
.socket
.on('error', function(error
) {
34 console
.error('GENERAL ERROR', error
);
37 internals
.socket
.on('connect_error', function(error
) {
39 console
.error('CONNNECT ERROR', error
);
42 internals
.socket
.on('connect', function() {
44 console
.log("Connected to signaling server, group: ", data
.currentUrl
);
45 internals
.socket
.emit('join', {
46 'url': data
.currentUrl
,
50 internals
.socket
.on('disconnect', function() {
52 console
.log("disconnected from signaling server");
55 internals
.socket
.on('addPeer', function(data
) {
58 Peers
.add('id-'+Peers
.count(), internals
.tada
);
59 console
.log(`There are now ${Peers.count()} participants`);
62 internals
.socket
.on('removePeer', function() {
64 Peers
.remove('id-'+(Peers
.count() - 1)); // This is only for testing, don't use count to remove ids.
65 console
.log(`There are now ${Peers.count()} participants`);
70 internals
.port
.postMessage({
73 internals
.port
.disconnect();
81 internals
.socket
.close();
82 internals
.port
.disconnect();
86 internals
.port
= chrome
.runtime
.connect({ name:"content" });
87 internals
.port
.onMessage
.addListener(internals
.onMessage
);
90 // Indicates to the background script that we executed correctly