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:
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:

View File

@ -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<MediaStream | null>(null);
const [connectionInfo, setConnectionInfo] = useState<string | null>(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<number>(0);
const [callInterval, setCallInterval] = useState<NodeJS.Timeout | null>(null);
const [currentCallId, setCurrentCallId] = useState<string | null>(null);
const [showCopyNotification, setShowCopyNotification] = useState(false);
const [ipv5, setIpv5] = useState('')
const [ipv5, setIpv5] = useState<string | null>('')
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) => {