Get started with peerjs CDN
MIT licensed
PeerJS is a simple, lightweight library for real-time peer-to-peer communication between web browsers.
Tags:- js
- WebRTC
Stable version
Copied!
How to start using peerjs CDN
<!DOCTYPE html>
<html>
<head>
<title>Get started with peerjs CDN - cdnhub.io</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/simple-peer.min.js"></script>
<script src="https://cdn.cdnhub.io/peerjs/1.5.2/peerjs.min.js"></script>
</head>
<body>
<button id="init">Initiate Call</button>
<button id="accept">Accept Call</button>
<div id="output"></div>
<script>
const output = document.getElementById('output');
const initButton = document.getElementById('init');
const acceptButton = document.getElementById('accept');
let peer;
let userVideo;
let remoteVideo;
initButton.addEventListener('click', () => {
const localVideo = document.createElement('video');
navigator.mediaDevices.getUserMedia({ video: true, audio: true })
.then(stream => {
localVideo.srcObject = stream;
userVideo = localVideo;
peer = new Peer({
initiator: true,
trickle: false,
stream: stream
});
peer.on('signal', data => {
acceptButton.addEventListener('click', () => {
const remotePeer = new Peer({
trickle: false
});
remotePeer.on('signal', answer => {
peer.signal(answer);
remotePeer.on('stream', rStream => {
remoteVideo.srcObject = rStream;
remoteVideo.play();
});
});
remotePeer.signal(data);
});
});
})
.catch(error => {
output.textContent = 'Error accessing user media: ' + error.name;
});
});
peer.on('stream', stream => {
remoteVideo.srcObject = stream;
remoteVideo.play();
});
</script>
<video id="remote" autoplay muted ref="remoteVideo" style="display:none;"></video>
</body>
</html>
Copied!
Copied!
Copied!
Copied!
All versions
0.2.0
0.3.1
0.3.10
0.3.12
0.3.13
0.3.14
0.3.15
0.3.16
0.3.17
0.3.18
0.3.19
0.3.2
0.3.20
0.3.22
0.3.23
0.3.24
0.3.4
0.3.5
0.3.6
0.3.7
0.3.8
0.3.9
1.0.0
1.0.2
1.0.3
1.0.4
1.2.0
1.3.0
1.3.1
1.3.2
1.4.0
1.4.0-rc.1
1.4.0-rc.2
1.4.0-rc.3
1.4.1
1.4.2
1.4.3
1.4.4
1.4.5
1.4.5-rc.1
1.4.6
1.4.6-rc.1
1.4.6-rc.2
1.4.7
1.4.8-rc.1
1.5.0
1.5.0-rc.1
1.5.1
1.5.2
1.5.2-rc.1
1.5.3
1.5.3-rc.1
*** 1.5.4
2.0.0-beta.0
2.0.0-beta.1
2.0.0-beta.2
2.0.0-beta.3