(null);
+
+ function startPeer() {
+ const peer = new Peer(peerId, { debug: 3 });
+ peer.on("open", function(id) {
+ setPeerId(id);
+ setPeer(peer);
+ peer.on("call", (call) => {
+ if (window.confirm(`Accept call from ${call.peer}?`)) {
+ navigator.mediaDevices
+ .getUserMedia({ video: true, audio: true })
+ .then((stream) => {
+ if (localVideo.current) {
+ localVideo.current.style.display = "block";
+ localVideo.current.srcObject = stream;
+ localVideo.current.play();
+ call.answer(stream);
+ call.on("stream", (remoteStream) => {
+ if (remoteVideo.current) {
+ remoteVideo.current.style.display = "block";
+ remoteVideo.current.srcObject = remoteStream;
+ remoteVideo.current.play();
+ }
+ });
+ setCall(call);
+ setCallId(call.peer);
+ call.on("close", () => {
+ endCall();
+ });
+
+ }
+ })
+ .catch((err) => {
+ console.log("Failed to get local stream:", err);
+ });
+ } else {
+ call.close();
+ }
+ });
+ });
+ }
+
+ async function startCall() {
+ const stream = await navigator.mediaDevices.getUserMedia({
+ video: true,
+ audio: true
+ });
+ if (localVideo.current) {
+ localVideo.current.style.display = "block";
+ localVideo.current.srcObject = stream;
+ localVideo.current.play();
+ }
+
+ if (peer) {
+ const call = peer.call(callId, stream);
+ call.on("stream", (stream) => {
+ if (remoteVideo.current) {
+ remoteVideo.current.style.display = "block";
+ remoteVideo.current.srcObject = stream;
+ remoteVideo.current.play();
+ }
+ });
+ call.on("error", (err) => {
+ console.log(err);
+ });
+ call.on("close", () => {
+ endCall();
+ });
+
+ setCall(call);
+ }
+ }
+
+ function endCall() {
+ if (localVideo.current) localVideo.current.style.display = "none";
+ if (remoteVideo.current) remoteVideo.current.style.display = "none";
+ if (!call) return;
+ if (call) {
+ call.localStream.getTracks().forEach(value => value.stop());
+ }
+ try {
+ call.close();
+ } catch {
+ }
+ setCall(undefined);
+ }
+
+ return (
+
+
+ <>
+
+
+
+ >
+
+ );
+}
\ No newline at end of file
diff --git a/src/components/Desktop/Desktop.tsx b/src/components/Desktop/Desktop.tsx
index df65ff4..06fdd3f 100644
--- a/src/components/Desktop/Desktop.tsx
+++ b/src/components/Desktop/Desktop.tsx
@@ -103,7 +103,6 @@ function Desktop({ openedAppConfigs, setOpenedAppConfigs }: DesktopProps) {
width: (desktopSelectPos.width + "px"),
display: (desktopSelectPos.width + desktopSelectPos.height > 0 ? "block" : "none")
}} />
-
{
openedAppConfigs.map((appConfig, i) => (
))
}
-
);
}