Skip to content

Commit 5033b81

Browse files
Fix PR-answer sample (#1347)
* Add tracks to stream * add missing semi-colon
1 parent 694ee29 commit 5033b81

File tree

1 file changed

+9
-9
lines changed
  • src/content/peerconnection/pr-answer/js

1 file changed

+9
-9
lines changed

src/content/peerconnection/pr-answer/js/main.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ hangUpButton.disabled = true;
2424

2525
let pc1 = null;
2626
let pc2 = null;
27-
let localstream;
27+
let localStream;
28+
const remoteStream = new MediaStream();
29+
2830
const offerOptions = {
2931
offerToReceiveAudio: 1,
3032
offerToReceiveVideo: 1
@@ -33,7 +35,7 @@ const offerOptions = {
3335
function gotStream(stream) {
3436
console.log('Received local stream');
3537
vid1.srcObject = stream;
36-
localstream = stream;
38+
localStream = stream;
3739
callButton.disabled = false;
3840
}
3941

@@ -50,8 +52,8 @@ function start() {
5052
acceptButton.disabled = false;
5153
hangUpButton.disabled = false;
5254
console.log('Starting Call');
53-
const videoTracks = localstream.getVideoTracks();
54-
const audioTracks = localstream.getAudioTracks();
55+
const videoTracks = localStream.getVideoTracks();
56+
const audioTracks = localStream.getAudioTracks();
5557
if (videoTracks.length > 0) {
5658
console.log(`Using Video device: ${videoTracks[0].label}`);
5759
}
@@ -68,7 +70,7 @@ function start() {
6870
pc2.onicecandidate = e => onIceCandidate(pc2, e);
6971
pc2.ontrack = gotRemoteStream;
7072

71-
localstream.getTracks().forEach(track => pc1.addTrack(track, localstream));
73+
localStream.getTracks().forEach(track => pc1.addTrack(track, localStream));
7274
console.log('Adding Local Stream to peer connection');
7375

7476
pc1.createOffer(offerOptions).then(gotDescription1, onCreateSessionDescriptionError);
@@ -142,10 +144,8 @@ function stop() {
142144
}
143145

144146
function gotRemoteStream(e) {
145-
if (vid2.srcObject !== e.streams[0]) {
146-
vid2.srcObject = e.streams[0];
147-
console.log('Received remote stream');
148-
}
147+
vid2.srcObject = remoteStream;
148+
remoteStream.addTrack(e.track, remoteStream);
149149
}
150150

151151
function getOtherPc(pc) {

0 commit comments

Comments
 (0)