Parameterize UI networking

main
idylls 1 year ago
parent 6efabd9116
commit 7ce2e93a1f
Signed by: idylls
GPG Key ID: 8A7167CBC2CC9F0F

2
.gitignore vendored

@ -1,2 +1,4 @@
build/
build/*
ui.config.ts

@ -127,7 +127,7 @@ const handleReq = (req: Request) => {
return response;
};
const port = +(Deno.env.get("WALKY_SERVER_PORT") ?? 8382);
const port = +(Deno.env.get("PEAR_SERVER_PORT") ?? 8382);
await serve(handleReq, {
port,
onError: (...args) => {

@ -0,0 +1,2 @@
export const pearServerSocketAddress = "ws://localhost:8382/";
export const rtcConfiguration: RTCConfiguration | undefined = undefined;

@ -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") {

Loading…
Cancel
Save