Get started with webrtc-adapter CDN

BSD-3-Clause licensed

Webrtc-adapter is a library simplifying WebRTC implementation by providing polyfills for older browsers.

Tags:
  • WebRTC
  • PeerConnection
  • RTCPeerConnection
  • getUserMedia
  • Chrome
  • Chromium
  • Firefox
  • Edge
  • Adapter
  • Shim

Stable version

Copied!

How to start using webrtc-adapter CDN


<!DOCTYPE html>
<html>
<head>
  <title>Get started with webrtc-adapter CDN - cdnhub.io</title>
  <style>
    #localVideo, #remoteVideo { width: 100%; height: 100%; border: 1px solid black; }
  </style>
</head>
<body>
  <video id="localVideo" autoplay muted></video>
  <video id="remoteVideo" autoplay></video>

  <script src="https://cdn.cdnhub.io/webrtc-adapter/8.2.3/adapter.js"></script>

  <script>
    const localVideo = document.getElementById('localVideo');
    const remoteVideo = document.getElementById('remoteVideo');

    const localStream = async () => {
      try {
        const stream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true });
        localVideo.srcObject = stream;
      } catch (error) {
        console.error('Error accessing media devices.', error);
      }
    };

    localStream();

    const configuration = { iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] };

    const pc = new RTCPeerConnection(configuration);
    pc.onicecandidate = (event) => {
      if (event.candidate) {
        // Send the candidate to the remote peer
      }
    };
    pc.onaddstream = (event) => {
      remoteVideo.srcObject = event.stream;
    };

    navigator.mediaDevices.getUserMedia({ video: true, audio: true })
      .then((stream) => {
        localVideo.srcObject = stream;
        pc.addStream(stream);
      })
      .catch((error) => {
        console.error('Error accessing media devices.', error);
      });

    pc.createOffer()
      .then((offer) => {
        return pc.setLocalDescription(offer);
      })
      .then(() => {
        // Send the offer to the remote peer
      });
  </script>
</body>
</html>
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!

All versions