Communication & Background

WebRTC

Probing…

WebRTC is a web platform capability in the Communication & Background category. Peer-to-peer audio, video and data channels. Supported in Chromium 56+, Firefox 44+, and Safari 11+. Requires a secure context (HTTPS or localhost).

Secure context

Try it

Loading demo…

Code

const pc1 = new RTCPeerConnection()
const pc2 = new RTCPeerConnection()
pc1.onicecandidate = e => e.candidate && pc2.addIceCandidate(e.candidate)
pc2.onicecandidate = e => e.candidate && pc1.addIceCandidate(e.candidate)

const ch = pc1.createDataChannel('demo')
pc2.ondatachannel = e => (e.channel.onmessage = ev => console.log(ev.data))

const offer = await pc1.createOffer()
await pc1.setLocalDescription(offer)
await pc2.setRemoteDescription(offer)
const answer = await pc2.createAnswer()
await pc2.setLocalDescription(answer)
await pc1.setRemoteDescription(answer)
ch.onopen = () => ch.send('hi')

Browser support

Chromium
56
Firefox
44
Safari
11

Frequently asked questions

Which browsers support WebRTC?

Supported in Chromium 56+, Firefox 44+, and Safari 11+.

Does WebRTC require HTTPS?

Yes. WebRTC needs a secure context, so it only works over HTTPS (or on localhost during development).

What is WebRTC used for?

Peer-to-peer audio, video and data channels.

Can I try WebRTC in my browser?

Yes. shwcs.net runs a live WebRTC demo that probes your current browser and lets you try the API. Everything runs locally — nothing is sent anywhere.

MDN reference ↗ Specification ↗