Updated WebrtcPlayer

This commit is contained in:
2025-10-05 23:05:52 +05:30
parent 584b328071
commit 169613703f
+33 -3
View File
@@ -158,11 +158,30 @@ const id = `${Math.random().toString(36).slice(2)}`;
} else {
remoteStream.addTrack(ev.track);
}
ev.track.onended = () => {
console.warn("🔴 Remote track ended!");
emit("disconnected", { msg: "Stream ended" });
};
ev.track.onmute = () =>
console.warn("Track muted (broadcaster may have stopped)");
ev.track.onunmute = () => console.log("Track unmuted");
emit("track", { kind: ev.track.kind });
});
pc.addEventListener("iceconnectionstatechange", () => {
emit("ice", { state: pc.iceConnectionState });
// emit("ice", { state: pc.iceConnectionState });
const state = pc.iceConnectionState;
emit("ice", { state });
console.log("ICE connection state:", state);
if (["disconnected", "failed", "closed"].includes(state)) {
console.warn(
"🔴 ICE disconnected — broadcaster likely ended stream.",
);
emit("disconnected", { msg: "Stream disconnected" });
}
});
const localCandidates = [];
@@ -278,11 +297,22 @@ const id = `${Math.random().toString(36).slice(2)}`;
if (type === "status") showOverlay(payload.msg);
if (type === "playing") hideOverlay();
if (type === "error") showOverlay(payload.msg || payload);
if (type === "disconnected") showOverlay(payload.msg);
if (type === "no-media") showOverlay("Stream not started");
if (type === "disconnected") {
handleStreamEnded();
showOverlay(payload.msg);
}
if (type === "no-media") {
handleStreamEnded();
showOverlay("Stream not started");
}
},
});
function handleStreamEnded() {
videoEl.pause();
videoEl.srcObject = null;
}
async function startWithRetry() {
try {
await player.start();