]>
git.r.bdr.sh - rbdr/junction/blob - extension/content_script.js
c344bd945ca94e23ef5f954460f201cc98b6a61f
1 import { io
} from "socket.io-client";
2 import { initializeTada
} from "./tada";
11 import { startMedia
, stopMedia
} from "./media";
14 kSocketUrl: "https://junction.tranquil.services",
15 kIceServers: [{ urls: "stun:stun.l.google.com:19302" }],
21 internals
[message
.action
](message
.data
);
25 // TODO: How do we want to handle errors?
26 console
.error(error
.stack
|| error
);
29 async
joinAudioCall({ currentUrl
, tada
}) {
31 const mediaStream
= await
startMedia();
32 const playTada
= initializeTada(tada
);
34 const socket
= (internals
.socket
= io(internals
.kSocketUrl
, {
35 transports: ["websocket"],
38 socket
.on("error", internals
.handleError
);
39 socket
.on("connect_error", internals
.handleError
);
41 socket
.on("connect", () => {
42 console
.debug("Connected to signaling server, group: ", currentUrl
);
49 socket
.on("disconnect", () => {
50 console
.debug("disconnected from signaling server");
53 socket
.on("addPeer", ({ peerId
, shouldCreateOffer
}) => {
58 onOffer: (data
) => socket
.emit("relayOffer", data
),
64 socket
.on("offerReceived", async ({ peerId
, offer
}) => {
65 socket
.emit("relayAnswer", await
answerPeerOffer({ peerId
, offer
}));
68 socket
.on("answerReceived", (data
) => processPeerAnswer(data
));
69 socket
.on("ICECandidateReceived", (data
) => addIceCandidate(data
));
70 socket
.on("removePeer", (data
) => removePeer(data
));
72 internals
.port
.postMessage({
75 internals
.port
.disconnect();
82 internals
.socket
.close();
83 internals
.port
.disconnect();
87 internals
.port
= chrome
.runtime
.connect({ name: "content" });
88 internals
.port
.onMessage
.addListener(internals
.onMessage
);
90 console
.debug("Content Script Loaded");
92 // Indicates to the background script that we executed correctly