I am trying to const pc = new RTCPeerConnection() while I get ReferenceError: RTCPeerConnection is not defined. How can I overcome this error?
It is not my browsers, I can run webRTC natively on them.
Next.js pre-renders every page on the server. Trying to use Web APIs when the page gets pre-rendered will throw an error like the one you're seeing since those Web APIs are not present in a Node.js environment.
To solve it, make sure you call new RTCPeerConnection() within your component's useEffect so it only gets called on the client-side.
useEffect(() => {
const pc = new RTCPeerConnection()
// Rest of your logic here
}, [])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With