|
|
|
@ -6,11 +6,12 @@ import {
|
|
|
|
|
PeerID,
|
|
|
|
|
} from "../common/types.ts";
|
|
|
|
|
|
|
|
|
|
import { pearServerSocketAddress, rtcConfiguration } from "../ui.config.ts";
|
|
|
|
|
|
|
|
|
|
export const initNetworking = async (
|
|
|
|
|
onPeerConnected: (peerID: PeerID, dataChannel: RTCDataChannel) => void,
|
|
|
|
|
) => {
|
|
|
|
|
// TODO: parameterize this
|
|
|
|
|
const socket = new WebSocket("ws://localhost:8382/");
|
|
|
|
|
const socket = new WebSocket(pearServerSocketAddress);
|
|
|
|
|
const pendingAnswers = new Map() as Map<
|
|
|
|
|
PeerID,
|
|
|
|
|
(r: ConnectAnswer["answer"]) => void
|
|
|
|
@ -77,7 +78,7 @@ export const initNetworking = async (
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const rtcPeerConnection = (peerID: PeerID) => {
|
|
|
|
|
const rtc = new RTCPeerConnection();
|
|
|
|
|
const rtc = new RTCPeerConnection(rtcConfiguration);
|
|
|
|
|
rtc.addEventListener("icecandidate", (ev) => {
|
|
|
|
|
if (ev.candidate) {
|
|
|
|
|
send({ kind: "iceCandidate", candidate: ev.candidate, peerID });
|
|
|
|
@ -85,7 +86,7 @@ export const initNetworking = async (
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const connected = new Promise((r) => {
|
|
|
|
|
rtc.addEventListener("iceconnectionstatechange", (ev) => {
|
|
|
|
|
rtc.addEventListener("iceconnectionstatechange", (_ev) => {
|
|
|
|
|
console.debug(rtc.iceConnectionState);
|
|
|
|
|
|
|
|
|
|
if (rtc.iceConnectionState == "connected") {
|
|
|
|
|