From e8fe53008caa519289487f8bd183e7b9c5d6407b Mon Sep 17 00:00:00 2001 From: moxitech Date: Thu, 7 Nov 2024 15:33:41 +0700 Subject: [PATCH] upd ip get logic \ pisa popa --- Makefile | 10 +++---- src/components/ExploreContainer.tsx | 45 ++++++++++++++--------------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index 54b7242..5fe9c88 100644 --- a/Makefile +++ b/Makefile @@ -3,13 +3,13 @@ build: - docker compose build + docker-compose build dev: build - docker compose up -d --force-recreate + docker-compose up -d --force-recreate devf: dev - docker compose logs -f + docker-compose logs -f up: docker compose up -d --force-recreate @@ -18,7 +18,7 @@ upf: up docker compose logs -f logs: - docker compose logs -f + docker-compose logs -f stop: @@ -28,4 +28,4 @@ start: docker compose start drop: - docker-compose down --volumes \ No newline at end of file + docker-compose down --volumes diff --git a/src/components/ExploreContainer.tsx b/src/components/ExploreContainer.tsx index e3b2f3b..59c8c0a 100644 --- a/src/components/ExploreContainer.tsx +++ b/src/components/ExploreContainer.tsx @@ -1,13 +1,12 @@ "use strict"; import React, { useState, useEffect, useCallback } from 'react'; -import './ExploreContainer.css'; import InputContainer from './Input'; -import { - IonButton, IonContent, IonFooter, IonToolbar, IonText, IonModal, IonIcon, IonLoading -} from '@ionic/react'; +import { IonButton, IonContent, IonText, IonModal, IonIcon, IonLoading } from '@ionic/react'; import { call as callIcon, close as hangUpIcon, shirt } from 'ionicons/icons'; import Peer, { MediaConnection } from 'peerjs'; -import os from 'os'; +import './ExploreContainer.css'; +import { randomBytes } from 'crypto'; + const ExploreContainer: React.FC = () => { const [callString, setCallString] = useState(""); @@ -16,29 +15,27 @@ const ExploreContainer: React.FC = () => { const [localStream, setLocalStream] = useState(null); const [connectionInfo, setConnectionInfo] = useState(null); const [isLoading, setIsLoading] = useState(false); - const [isConnecting, setIsConnecting] = useState(false); // New state for connecting screen + const [isConnecting, setIsConnecting] = useState(false); const [isCallActive, setIsCallActive] = useState(false); const [callDuration, setCallDuration] = useState(0); const [callInterval, setCallInterval] = useState(null); const [currentCallId, setCurrentCallId] = useState(null); const [showCopyNotification, setShowCopyNotification] = useState(false); - const [ipv5, setIpv5] = useState('') + const [ipv5, setIpv5] = useState('') const getLocalIP = async () => { return new Promise((resolve, reject) => { - const peerConnection = new RTCPeerConnection(); - // const noop = () => {}; - + const peerConnection = new RTCPeerConnection({ }); // Обрабатываем события ICE-кандидатов, которые будут содержать IP-адрес peerConnection.onicecandidate = (event) => { if (event.candidate) { const ip = event.candidate.candidate.split(" ")[4]; + console.log(event.candidate) resolve(ip); - // peerConnection.onicecandidate = noop; // Завершаем обработку + peerConnection.onicecandidate = null; // Завершаем обработку } }; - // Создаём пустой канал данных для инициирования связи peerConnection.createDataChannel(""); peerConnection.createOffer() @@ -47,21 +44,23 @@ const ExploreContainer: React.FC = () => { }); }; - // Использование функции - getLocalIP().then((ip) => { - console.log("Local IP Address:", ip); - setIpv5(ip as string) - }).catch((err) => { - setIpv5("error") - console.error("Error getting IP address:", err); - }); - + useEffect(() => { + // Использование функции + getLocalIP().then((ip) => { + console.log("Local IP Address in function getLocalIp:", ip); + // Debug this func!! + setIpv5(ip as string) // ip is eq of "peer-string".local !!?? + }).catch((err) => { + setIpv5(null) + console.error("Error getting IP address:", err); + }); + const initializePeer = () => { console.log(ipv5) - const newPeer = new Peer( ipv5 ,{ debug: 3 }); - // const newPeer = new Peer(,{ debug: 3 }); + // ERROR CAST SET AS RANDOMIZE : "error_cast%s", where %s - random string or int + const newPeer = new Peer( ipv5 ? ipv5 : "error_cast",{ debug: 3 }); setPeer(newPeer); newPeer.on('open', (id) => {