Skip to content

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
tarikulislam36 authored Jan 29, 2025
1 parent 2a9206f commit de9ca8b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ <h1>PeerJS Video Call Example</h1>
const inputlocalpeerId = document.getElementById("localpeerId");

let currentStream;
let currentCall;
let videoConstraints = { facingMode: "user" }; // Default front camera

const peer = new Peer();
Expand All @@ -49,6 +50,13 @@ <h1>PeerJS Video Call Example</h1>
try {
currentStream = await navigator.mediaDevices.getUserMedia({ video: videoConstraints, audio: true });
localVideo.srcObject = currentStream;

if (currentCall) {
let sender = currentCall.peerConnection.getSenders().find(s => s.track.kind === 'video');
if (sender) {
sender.replaceTrack(currentStream.getVideoTracks()[0]);
}
}
} catch (err) {
console.log('Failed to get local stream', err);
}
Expand All @@ -58,6 +66,7 @@ <h1>PeerJS Video Call Example</h1>

peer.on('call', (call) => {
console.log('Incoming call...');
currentCall = call;
call.answer(currentStream);
call.on('stream', (remoteStream) => {
remoteVideo.srcObject = remoteStream;
Expand All @@ -67,6 +76,7 @@ <h1>PeerJS Video Call Example</h1>
function callPeer() {
const remotePeerId = remotePeerIdInput.value;
const call = peer.call(remotePeerId, currentStream);
currentCall = call;
call.on('stream', (remoteStream) => {
remoteVideo.srcObject = remoteStream;
});
Expand Down

0 comments on commit de9ca8b

Please sign in to comment.