The webrtc-ip
package is available through npm:
npm install webrtc-ip
Alternatively, install using bun
:
bun install webrtc-ip
WebRTC-IP is intended to be used with Next.js. A minimal example is present in [website/example]:
import { useState, useEffect } from "react";
import { getIP } from 'webrtc-ip';
export default function Home() {
const [ip, setIp] = useState<string>("0.0.0.0");
useEffect(() => {
(async () => {
try {
const ipAddress: string = await getIP();
setIp(ipAddress);
} catch (error) {
console.error("Failed to fetch IP address:", error);
}
})();
}, []);
return (
<main className="flex min-h-screen flex-col items-center justify-between p-24">
<p>{ip}</p>
</main>
);
}
The author of webrtc-ips is Joey Malvinni