]>
git.r.bdr.sh - rbdr/junction/blob - extension/junction.js
1 const io
= require('socket.io-client');
5 promisesSupported: !!(window
.browser
),
10 16: 'icons/action-16.png',
11 32: 'icons/action-32.png'
15 16: 'icons/hang_up-16.png',
16 32: 'icons/hang_up-32.png'
25 if (internals
.isInCall()) {
26 return internals
.hangUp();
29 return internals
.joinAudioCall();
32 async
joinAudioCall() {
34 internals
.isInCallState
= true;
35 internals
.setIcon('hangUp');
36 const activeTabs
= await internals
.getActiveTabs();
38 const socketUrl
= 'http://unlimited.pizza:8000/';
39 const currentUrl
= activeTabs
[0].url
;
41 this.socket
= io(socketUrl
);
45 this.socket
.on('connect', function() {
46 console
.log("Connected to signaling server");
48 that
.socket
.emit('join', {
53 this.socket
.on('disconnect', function() {
54 console
.log("disconnected from signaling server");
57 this.socket
.on('addPeer', function(data
) {
60 console
.log(`There are now ${that.peers} participants`);
63 this.socket
.on('removePeer', function() {
65 console
.log(`There are now ${that.peers} participants`);
68 console
.log(activeTabs
[0].url
); // placeholder while we connect backend.
69 internals
.createAudioElement(internals
.getRoot().runtime
.getURL('sounds/tada.wav'));
77 document
.querySelectorAll('audio').forEach((audioElement
) => audioElement
.remove());
78 internals
.setIcon('call');
79 internals
.isInCallState
= false;
82 createAudioElement(source
, type
= 'audio/wav') {
84 const audioElement
= document
.createElement('audio');
85 audioElement
.src
= source
;
86 audioElement
.autoplay
= 'autoplay';
87 audioElement
.type
= type
;
88 document
.querySelector('body').appendChild(audioElement
);
92 return internals
.isInCallState
; // this should be replaced with actually checking the built stuff
97 internals
.getRoot().browserAction
.setIcon({
98 path: internals
.icons
[iconSet
]
104 return window
.browser
|| window
.chrome
;
107 // Chrome doesn't yet implement the promise based tabs.query :'(
116 if (internals
.promisesSupported
) {
117 return internals
.getRoot().tabs
.query(query
);
120 return new Promise((resolve
, reject
) => {
122 internals
.getRoot().tabs
.query(query
, (tabs
) => {
124 return resolve(tabs
);
130 internals
.getRoot().browserAction
.onClicked
.addListener(internals
.onClick
);