]>
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://polypropylene.website:8000';
39 const currentUrl
= activeTabs
[0].url
;
41 this.socket
= io(socketUrl
);
43 this.socket
.on('connect', function() {
44 console
.log("Connected to signaling server");
47 this.socket
.on('disconnect', function() {
48 console
.log("disconnected from signaling server");
51 this.socket
.on('addPeer', function() {
53 console
.log(`There are now ${this.peers} participants`);
56 this.socket
.on('removePeer', function() {
58 console
.log(`There are now ${this.peers} participants`);
61 console
.log(activeTabs
[0].url
); // placeholder while we connect backend.
62 internals
.createAudioElement(internals
.getRoot().runtime
.getURL('sounds/tada.wav'));
70 document
.querySelectorAll('audio').forEach((audioElement
) => audioElement
.remove());
71 internals
.setIcon('call');
72 internals
.isInCallState
= false;
75 createAudioElement(source
, type
= 'audio/wav') {
77 const audioElement
= document
.createElement('audio');
78 audioElement
.src
= source
;
79 audioElement
.autoplay
= 'autoplay';
80 audioElement
.type
= type
;
81 document
.querySelector('body').appendChild(audioElement
);
85 return internals
.isInCallState
; // this should be replaced with actually checking the built stuff
90 internals
.getRoot().browserAction
.setIcon({
91 path: internals
.icons
[iconSet
]
97 return window
.browser
|| window
.chrome
;
100 // Chrome doesn't yet implement the promise based tabs.query :'(
109 if (internals
.promisesSupported
) {
110 return internals
.getRoot().tabs
.query(query
);
113 return new Promise((resolve
, reject
) => {
115 internals
.getRoot().tabs
.query(query
, (tabs
) => {
117 return resolve(tabs
);
123 internals
.getRoot().browserAction
.onClicked
.addListener(internals
.onClick
);