]>
git.r.bdr.sh - rbdr/junction/blob - extension/content_script.js
1 import { io
} from 'socket.io-client';
2 import Peers
from './peers';
3 import Media
from './media';
7 kSocketUrl: 'ws://localhost:8000',
14 internals
[message
.action
](message
.data
);
17 async
joinAudioCall(data
) {
19 internals
.tada
= data
.tada
; // Keeping for fun
24 internals
.socket
= io(internals
.kSocketUrl
, {
25 transports: ['websocket']
28 internals
.socket
.on('error', function(error
) {
30 console
.error('GENERAL ERROR', error
);
33 internals
.socket
.on('connect_error', function(error
) {
35 console
.error('CONNNECT ERROR', error
);
38 internals
.socket
.on('connect', function() {
40 console
.log("Connected to signaling server, group: ", data
.currentUrl
);
41 internals
.socket
.emit('join', {
42 'url': data
.currentUrl
,
46 internals
.socket
.on('disconnect', function() {
48 console
.log("disconnected from signaling server");
51 internals
.socket
.on('addPeer', function(data
) {
54 Peers
.add('id-'+Peers
.count(), internals
.tada
);
55 console
.log(`There are now ${Peers.count()} participants`);
58 internals
.socket
.on('removePeer', function() {
60 Peers
.remove('id-'+(Peers
.count() - 1)); // This is only for testing, don't use count to remove ids.
61 console
.log(`There are now ${Peers.count()} participants`);
66 internals
.port
.postMessage({
69 internals
.port
.disconnect();
77 internals
.socket
.close();
78 internals
.port
.disconnect();
82 internals
.port
= chrome
.runtime
.connect({ name:"content" });
83 internals
.port
.onMessage
.addListener(internals
.onMessage
);
85 console
.log('Content Script Loaded');
87 // Indicates to the background script that we executed correctly