@@ -24,7 +24,9 @@ hangUpButton.disabled = true;
24
24
25
25
let pc1 = null ;
26
26
let pc2 = null ;
27
- let localstream ;
27
+ let localStream ;
28
+ const remoteStream = new MediaStream ( ) ;
29
+
28
30
const offerOptions = {
29
31
offerToReceiveAudio : 1 ,
30
32
offerToReceiveVideo : 1
@@ -33,7 +35,7 @@ const offerOptions = {
33
35
function gotStream ( stream ) {
34
36
console . log ( 'Received local stream' ) ;
35
37
vid1 . srcObject = stream ;
36
- localstream = stream ;
38
+ localStream = stream ;
37
39
callButton . disabled = false ;
38
40
}
39
41
@@ -50,8 +52,8 @@ function start() {
50
52
acceptButton . disabled = false ;
51
53
hangUpButton . disabled = false ;
52
54
console . log ( 'Starting Call' ) ;
53
- const videoTracks = localstream . getVideoTracks ( ) ;
54
- const audioTracks = localstream . getAudioTracks ( ) ;
55
+ const videoTracks = localStream . getVideoTracks ( ) ;
56
+ const audioTracks = localStream . getAudioTracks ( ) ;
55
57
if ( videoTracks . length > 0 ) {
56
58
console . log ( `Using Video device: ${ videoTracks [ 0 ] . label } ` ) ;
57
59
}
@@ -68,7 +70,7 @@ function start() {
68
70
pc2 . onicecandidate = e => onIceCandidate ( pc2 , e ) ;
69
71
pc2 . ontrack = gotRemoteStream ;
70
72
71
- localstream . getTracks ( ) . forEach ( track => pc1 . addTrack ( track , localstream ) ) ;
73
+ localStream . getTracks ( ) . forEach ( track => pc1 . addTrack ( track , localStream ) ) ;
72
74
console . log ( 'Adding Local Stream to peer connection' ) ;
73
75
74
76
pc1 . createOffer ( offerOptions ) . then ( gotDescription1 , onCreateSessionDescriptionError ) ;
@@ -142,10 +144,8 @@ function stop() {
142
144
}
143
145
144
146
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 ) ;
149
149
}
150
150
151
151
function getOtherPc ( pc ) {
0 commit comments