ggaa
This commit is contained in:
parent
0ccca0922c
commit
2d94537192
5
package-lock.json
generated
5
package-lock.json
generated
@ -16,7 +16,7 @@
|
|||||||
"@testing-library/user-event": "^12.6.3",
|
"@testing-library/user-event": "^12.6.3",
|
||||||
"@types/ip": "^1.1.3",
|
"@types/ip": "^1.1.3",
|
||||||
"@types/jest": "^26.0.20",
|
"@types/jest": "^26.0.20",
|
||||||
"@types/node": "^12.19.15",
|
"@types/node": "^12.20.55",
|
||||||
"@types/react": "^18.0.17",
|
"@types/react": "^18.0.17",
|
||||||
"@types/react-dom": "^18.0.6",
|
"@types/react-dom": "^18.0.6",
|
||||||
"@types/react-router": "^5.1.11",
|
"@types/react-router": "^5.1.11",
|
||||||
@ -3864,7 +3864,8 @@
|
|||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
"version": "12.20.55",
|
"version": "12.20.55",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.20.55.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.20.55.tgz",
|
||||||
"integrity": "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ=="
|
"integrity": "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==",
|
||||||
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@types/node-forge": {
|
"node_modules/@types/node-forge": {
|
||||||
"version": "1.3.11",
|
"version": "1.3.11",
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
"@testing-library/user-event": "^12.6.3",
|
"@testing-library/user-event": "^12.6.3",
|
||||||
"@types/ip": "^1.1.3",
|
"@types/ip": "^1.1.3",
|
||||||
"@types/jest": "^26.0.20",
|
"@types/jest": "^26.0.20",
|
||||||
"@types/node": "^12.19.15",
|
"@types/node": "^12.20.55",
|
||||||
"@types/react": "^18.0.17",
|
"@types/react": "^18.0.17",
|
||||||
"@types/react-dom": "^18.0.6",
|
"@types/react-dom": "^18.0.6",
|
||||||
"@types/react-router": "^5.1.11",
|
"@types/react-router": "^5.1.11",
|
||||||
|
@ -7,7 +7,7 @@ import {
|
|||||||
} from '@ionic/react';
|
} 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 * as os from 'os';
|
import os from 'os';
|
||||||
|
|
||||||
const ExploreContainer: React.FC = () => {
|
const ExploreContainer: React.FC = () => {
|
||||||
const [callString, setCallString] = useState("");
|
const [callString, setCallString] = useState("");
|
||||||
@ -22,30 +22,45 @@ const ExploreContainer: React.FC = () => {
|
|||||||
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 getLocalIP = async () => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const peerConnection = new RTCPeerConnection();
|
||||||
|
// const noop = () => {};
|
||||||
|
|
||||||
function getLocalIPAddress() {
|
// Обрабатываем события ICE-кандидатов, которые будут содержать IP-адрес
|
||||||
const networkInterfaces = os.networkInterfaces();
|
peerConnection.onicecandidate = (event) => {
|
||||||
for (const interfaceName of Object.keys(networkInterfaces)) {
|
if (event.candidate) {
|
||||||
const networkInterface = networkInterfaces[interfaceName];
|
const ip = event.candidate.candidate.split(" ")[4];
|
||||||
if (networkInterface) {
|
resolve(ip);
|
||||||
for (const net of networkInterface) {
|
// peerConnection.onicecandidate = noop; // Завершаем обработку
|
||||||
if (net.family === 'IPv4' && !net.internal) {
|
}
|
||||||
console.log(`Your local IP Address is: ${net.address}`);
|
};
|
||||||
return net.address;
|
|
||||||
}
|
// Создаём пустой канал данных для инициирования связи
|
||||||
}
|
peerConnection.createDataChannel("");
|
||||||
}
|
peerConnection.createOffer()
|
||||||
}
|
.then((offer) => peerConnection.setLocalDescription(offer))
|
||||||
return '';
|
.catch((err) => reject(err));
|
||||||
}
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Использование функции
|
||||||
|
getLocalIP().then((ip) => {
|
||||||
|
console.log("Local IP Address:", ip);
|
||||||
|
setIpv5(ip as string)
|
||||||
|
}).catch((err) => {
|
||||||
|
setIpv5("error")
|
||||||
|
console.error("Error getting IP address:", err);
|
||||||
|
});
|
||||||
|
|
||||||
getLocalIPAddress();
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const initializePeer = () => {
|
const initializePeer = () => {
|
||||||
const newPeer = new Peer('',{ debug: 3 });
|
console.log(ipv5)
|
||||||
|
const newPeer = new Peer( ipv5 ,{ debug: 3 });
|
||||||
// const newPeer = new Peer(,{ debug: 3 });
|
// const newPeer = new Peer(,{ debug: 3 });
|
||||||
setPeer(newPeer);
|
setPeer(newPeer);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user