Get started with simple-peer CDN
MIT licensed
Simple-Peer is a library for creating peer-to-peer connections for real-time applications.
Tags:- webrtc
- p2p
- data channel
- data channels
- data
- video
- voice
- peer
- stream
- peer-to-peer
- data channel stream
- webrtc stream
Stable version
Copied!
How to start using simple-peer CDN
<!DOCTYPE html>
<html>
<head>
<title>Get started with simple-peer CDN - cdnhub.io</title>
<script src="https://cdn.cdnhub.io/simple-peer/9.11.1/simplepeer.min.js"></script>
</head>
<body>
<button id="start">Start Call</button>
<div id="log"></div>
<script>
const log = document.getElementById('log');
const startButton = document.getElementById('start');
let localStream;
let peer;
navigator.mediaDevices.getUserMedia({ audio: true, video: true })
.then(stream => {
localStream = stream;
const pcConfig = { iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] };
peer = new SimplePeer({ initiator: false, trickle: false, stream: localStream, config: pcConfig });
peer.on('signal', data => {
log.textContent += `\nSDP: ${JSON.stringify(data.sdp)}`;
peer.sendSignal(data);
});
peer.on('stream', remoteStream => {
log.textContent += `\nRemote stream: ${remoteStream.toString()}`;
});
peer.on('connectionstatechange', () => {
log.textContent += `\nConnection state: ${peer.connectionState}`;
});
startButton.addEventListener('click', () => {
peer.createOffer()
.then(offer => {
return peer.setLocalDescription(offer);
})
.then(() => {
log.textContent += `\nLocal description: ${JSON.stringify(peer.localDescription)}`;
peer.sendSignal(peer.localDescription);
})
.catch(err => {
log.textContent += `\nError: ${err.toString()}`;
});
});
})
.catch(err => {
log.textContent += `\nError: ${err.toString()}`;
});
</script>
</body>
</html>
Copied!
All versions
3.3.0
3.3.1
3.4.0
3.4.1
3.4.2
3.5.0
3.5.1
3.6.0
3.6.1
3.6.2
3.6.3
3.6.4
3.6.5
3.6.6
3.6.7
3.6.8
3.6.9
4.0.0
4.0.1
4.0.2
4.0.3
4.0.4
4.1.0
4.2.0
4.2.1
4.2.2
4.2.3
5.0.0
5.1.0
5.1.1
5.10.0
5.11.0
5.11.1
5.11.2
5.11.3
5.11.4
5.11.5
5.11.6
5.11.7
5.11.8
5.11.9
5.12.0
5.12.1
5.2.0
5.3.0
5.3.1
5.4.0
5.4.1
5.4.3
5.5.0
5.6.0
5.7.0
5.8.0
5.8.1
5.9.0
5.9.1
6.0.0
6.0.1
6.0.2
6.0.3
6.0.4
6.0.5
6.0.6
6.0.7
6.1.0
6.1.1
6.1.2
6.1.3
6.1.4
6.1.5
6.2.0
6.2.1
6.2.2
6.3.0
6.4.0
6.4.1
6.4.2
6.4.3
6.4.4
7.0.0
7.0.1
8.0.0
8.1.0
8.1.1
8.2.0
8.3.0
8.4.0
8.5.0
9.0.0
9.1.0
9.1.1
9.1.2
9.10.0
9.11.0
*** 9.11.1
9.2.0
9.2.1
9.3.0
9.3.1
9.4.0
9.5.0
9.6.0
9.6.1
9.6.2
9.7.0
9.7.1
9.7.2
9.8.0
9.9.0
9.9.1
9.9.2
9.9.3
9.9.4