Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

THIS SHOULD FIX #47

Open
AKHIL17577 opened this issue Jan 9, 2024 · 1 comment
Open

THIS SHOULD FIX #47

AKHIL17577 opened this issue Jan 9, 2024 · 1 comment

Comments

@AKHIL17577
Copy link

Download
Copy code
var start = () => {
// add constraints if necessary
return navigator.mediaDevices.getUserMedia({ audio: true, video: true })
.then(stream => {
attachVideo(v1, v1info, stream);
pc1.addStream(stream);
})
.catch(console.error);
};

var dimensions = v => v.videoWidth + "x" + v.videoHeight;
var attachVideo = (videoTag, vinfo, stream) => {
videoTag.srcObject = stream;
videoTag.addEventListener("loadedmetadata", e => update(vinfo, dimensions(videoTag)), false);
};

var addCandidate = (pc, can) => can && pc.addIceCandidate(can).catch(console.error);
pc1.onicecandidate = e => {
console.log('pc1.onicecandidate:', e.candidate);
addCandidate(pc2, e.candidate);
};
pc2.onicecandidate = e => {
console.log('pc2.onicecandidate:', e.candidate);
addCandidate(pc1, e.candidate);
};
pc1.oniceconnectionstatechange = e => console.log("pc1.iceConnState:", pc1.iceConnectionState);
pc2.oniceconnectionstatechange = e => console.log("pc2.iceConnState:", pc2.iceConnectionState);

pc1.onnegotiationneeded = e => {
pc1.createOffer().then(d => {
console.log("pc1.offer_sdp:", d.sdp);
return pc1.setLocalDescription(d);
})
.then(() => pc2.setRemoteDescription(pc1.localDescription))
.then(() => pc2.createAnswer())
.then(d => {
console.log("pc2.answer_sdp:", d.sdp);
return pc2.setLocalDescription(d);
})
.then(() => pc1.setRemoteDescription(pc2.localDescription))
.catch(console.error);
};

pc2.ontrack = e => {
console.log('pc2.ontrack, stream id:', e.streams[0].id);
console.log('pc2.ontrack, track id:', e.track.id, 'label:', e.track.label, 'kind:', e.track.kind, e.track);

// Attach remote audio to audio tag
var audio = document.createElement('audio');
audio.srcObject = e.streams[0];
audio.autoplay = true;
audio.addEventListener('loadedmetadata', function () {
console.log('audio track info:', this.srcObject.getAudioTracks()[0]);
});
document.body.appendChild(audio);
};

var update = (div, msg) => div.innerHTML = msg;

@H9660
Copy link

H9660 commented Apr 27, 2024

Whats the issue here @AKHIL17577 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants