fix
All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 1m17s

This commit is contained in:
Smile Rex
2026-01-26 19:43:17 +03:00
parent 3894a8a393
commit 4bd57e1d12

View File

@@ -3,10 +3,25 @@
let localVideo: HTMLVideoElement;
let localStream: MediaStream;
let pc: RTCPeerConnection;
let ws: WebSocket;
function createPC() {
let ws: WebSocket;
let pc: RTCPeerConnection;
/* ---------- helpers ---------- */
function waitForWsOpen(ws: WebSocket): Promise<void> {
return new Promise((resolve) => {
if (ws.readyState === WebSocket.OPEN) {
resolve();
} else {
ws.addEventListener("open", () => resolve(), { once: true });
}
});
}
/* ---------- WebRTC ---------- */
function createPeerConnection() {
pc = new RTCPeerConnection({
iceServers: [{ urls: "stun:stun.l.google.com:19302" }],
});
@@ -20,14 +35,15 @@
};
pc.onicecandidate = (e) => {
if (e.candidate) {
if (!e.candidate) return;
if (ws.readyState !== WebSocket.OPEN) return;
ws.send(
JSON.stringify({
type: "ice",
data: e.candidate,
}),
);
}
};
}
@@ -43,7 +59,10 @@
);
}
/* ---------- lifecycle ---------- */
onMount(async () => {
/* 1. media */
localStream = await navigator.mediaDevices.getUserMedia({
video: true,
audio: true,
@@ -51,16 +70,23 @@
localVideo.srcObject = localStream;
/* 2. websocket */
ws = new WebSocket("wss://meet-api.quizer.space/ws");
await waitForWsOpen(ws);
createPC();
console.log("[ws] connected");
/* 3. peer connection */
createPeerConnection();
for (const track of localStream.getTracks()) {
pc.addTrack(track, localStream);
}
/* 4. ws messages */
ws.onmessage = async (e) => {
const msg = JSON.parse(e.data);
console.log("[ws] <=", msg.type);
switch (msg.type) {
case "answer":
@@ -77,11 +103,17 @@
}
};
/* 5. initial offer */
await negotiate();
});
</script>
<video bind:this={localVideo} autoplay muted playsinline></video>
<video
bind:this={localVideo}
autoplay
muted
playsinline
></video>
<style>
video {