upd ip get logic \ pisa popa

This commit is contained in:
moxitech 2024-11-07 15:33:41 +07:00
parent 2d94537192
commit e8fe53008c
2 changed files with 27 additions and 28 deletions

View File

@ -3,13 +3,13 @@
build: build:
docker compose build docker-compose build
dev: build dev: build
docker compose up -d --force-recreate docker-compose up -d --force-recreate
devf: dev devf: dev
docker compose logs -f docker-compose logs -f
up: up:
docker compose up -d --force-recreate docker compose up -d --force-recreate
@ -18,7 +18,7 @@ upf: up
docker compose logs -f docker compose logs -f
logs: logs:
docker compose logs -f docker-compose logs -f
stop: stop:
@ -28,4 +28,4 @@ start:
docker compose start docker compose start
drop: drop:
docker-compose down --volumes docker-compose down --volumes

View File

@ -1,13 +1,12 @@
"use strict"; "use strict";
import React, { useState, useEffect, useCallback } from 'react'; import React, { useState, useEffect, useCallback } from 'react';
import './ExploreContainer.css';
import InputContainer from './Input'; import InputContainer from './Input';
import { import { IonButton, IonContent, IonText, IonModal, IonIcon, IonLoading } from '@ionic/react';
IonButton, IonContent, IonFooter, IonToolbar, IonText, IonModal, IonIcon, IonLoading
} from '@ionic/react';
import { call as callIcon, close as hangUpIcon, shirt } from 'ionicons/icons'; import { call as callIcon, close as hangUpIcon, shirt } from 'ionicons/icons';
import Peer, { MediaConnection } from 'peerjs'; import Peer, { MediaConnection } from 'peerjs';
import os from 'os'; import './ExploreContainer.css';
import { randomBytes } from 'crypto';
const ExploreContainer: React.FC = () => { const ExploreContainer: React.FC = () => {
const [callString, setCallString] = useState(""); const [callString, setCallString] = useState("");
@ -16,29 +15,27 @@ const ExploreContainer: React.FC = () => {
const [localStream, setLocalStream] = useState<MediaStream | null>(null); const [localStream, setLocalStream] = useState<MediaStream | null>(null);
const [connectionInfo, setConnectionInfo] = useState<string | null>(null); const [connectionInfo, setConnectionInfo] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(false); 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 [isCallActive, setIsCallActive] = useState(false);
const [callDuration, setCallDuration] = useState<number>(0); const [callDuration, setCallDuration] = useState<number>(0);
const [callInterval, setCallInterval] = useState<NodeJS.Timeout | null>(null); const [callInterval, setCallInterval] = useState<NodeJS.Timeout | null>(null);
const [currentCallId, setCurrentCallId] = useState<string | null>(null); const [currentCallId, setCurrentCallId] = useState<string | null>(null);
const [showCopyNotification, setShowCopyNotification] = useState(false); const [showCopyNotification, setShowCopyNotification] = useState(false);
const [ipv5, setIpv5] = useState('') const [ipv5, setIpv5] = useState<string | null>('')
const getLocalIP = async () => { const getLocalIP = async () => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const peerConnection = new RTCPeerConnection(); const peerConnection = new RTCPeerConnection({ });
// const noop = () => {};
// Обрабатываем события ICE-кандидатов, которые будут содержать IP-адрес // Обрабатываем события ICE-кандидатов, которые будут содержать IP-адрес
peerConnection.onicecandidate = (event) => { peerConnection.onicecandidate = (event) => {
if (event.candidate) { if (event.candidate) {
const ip = event.candidate.candidate.split(" ")[4]; const ip = event.candidate.candidate.split(" ")[4];
console.log(event.candidate)
resolve(ip); resolve(ip);
// peerConnection.onicecandidate = noop; // Завершаем обработку peerConnection.onicecandidate = null; // Завершаем обработку
} }
}; };
// Создаём пустой канал данных для инициирования связи // Создаём пустой канал данных для инициирования связи
peerConnection.createDataChannel(""); peerConnection.createDataChannel("");
peerConnection.createOffer() 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(() => { 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 = () => { const initializePeer = () => {
console.log(ipv5) console.log(ipv5)
const newPeer = new Peer( ipv5 ,{ debug: 3 }); // ERROR CAST SET AS RANDOMIZE : "error_cast%s", where %s - random string or int
// const newPeer = new Peer(,{ debug: 3 }); const newPeer = new Peer( ipv5 ? ipv5 : "error_cast",{ debug: 3 });
setPeer(newPeer); setPeer(newPeer);
newPeer.on('open', (id) => { newPeer.on('open', (id) => {