]>
git.r.bdr.sh - rbdr/junction/blob - extension/content_script.js
721176e8330e19ea21168656053634ff4457c3d2
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
}) => {
57 onOffer: (data
) => socket
.emit("relayOffer", data
),
63 socket
.on("offerReceived", async ({ peerId
, offer
}) => {
64 socket
.emit("relayAnswer", await
answerPeerOffer({ peerId
, offer
}));
67 socket
.on("answerReceived", (data
) => processPeerAnswer(data
));
68 socket
.on("ICECandidateReceived", (data
) => addIceCandidate(data
));
69 socket
.on("removePeer", (data
) => removePeer(data
));
71 internals
.port
.postMessage({
74 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
);
89 console
.debug("Content Script Loaded");
91 // Indicates to the background script that we executed correctly