@@ -81,7 +81,7 @@ localVideo.addEventListener("loadedmetadata", function () {
81
81
const IS_CALLER = false ;
82
82
83
83
let userMediaStream ;
84
- let clientPc ;
84
+ let pcClient ;
85
85
86
86
function start ( ) {
87
87
trace ( "Requesting local stream" ) ;
@@ -132,29 +132,29 @@ function call() {
132
132
if ( audioTracks . length > 0 ) {
133
133
trace ( "Using audio device: " + audioTracks [ 0 ] . label ) ;
134
134
}
135
- clientPc = new RTCPeerConnection ( ICE_SERVERS_CONFIG ) ;
135
+ pcClient = new RTCPeerConnection ( ICE_SERVERS_CONFIG ) ;
136
136
trace ( "Created local peer connection object client:" ) ;
137
137
138
- clientPc . onicecandidate = ( event ) => {
138
+ pcClient . onicecandidate = ( event ) => {
139
139
socket . emit ( NEW_PEER_ICE_CANDIDATE , event . candidate ) ;
140
140
// trace("ICE candidate:", event.candidate);
141
141
} ;
142
142
143
143
socket . on ( NEW_PEER_ICE_CANDIDATE , ( candidate ) => {
144
144
// trace("receiving new remote Ice Candidate: ");
145
- clientPc
145
+ pcClient
146
146
. addIceCandidate ( candidate )
147
147
. then ( ( ) => {
148
- // trace("client: new Remote Ice Candidate: ");
148
+ trace ( "client: new Remote Ice Candidate: " , candidate ) ;
149
149
} )
150
150
. catch ( ( e ) => {
151
151
trace ( "Error adding new Remote Ice Candidate: " , e ) ;
152
152
} ) ;
153
153
} ) ;
154
154
155
- clientPc . oniceconnectionstatechange = ( ) => {
156
- clientPc . addEventListener ( "connectionstatechange" , ( ) => {
157
- switch ( clientPc . connectionState ) {
155
+ pcClient . oniceconnectionstatechange = ( ) => {
156
+ pcClient . addEventListener ( "connectionstatechange" , ( ) => {
157
+ switch ( pcClient . connectionState ) {
158
158
case "connected" :
159
159
// The connection has become fully connected
160
160
trace ( "[WebRTC] User is fully connected" ) ;
@@ -174,7 +174,7 @@ function call() {
174
174
} ) ;
175
175
} ;
176
176
177
- clientPc . addStream ( userMediaStream ) ;
177
+ pcClient . addStream ( userMediaStream ) ;
178
178
179
179
// 선호 코덱을 가장 위에 배치한 배열을 setCodecPreferences로 넘기는 것.
180
180
const { codecs } = RTCRtpSender . getCapabilities ( "video" ) ;
@@ -189,7 +189,7 @@ function call() {
189
189
codecs . splice ( selectedCodecIndex , 1 ) ;
190
190
codecs . unshift ( selectedCodec ) ;
191
191
console . log ( codecs ) ;
192
- const transceiver = clientPc
192
+ const transceiver = pcClient
193
193
. getTransceivers ( )
194
194
. find (
195
195
( t ) => t . sender && t . sender . track === userMediaStream . getVideoTracks ( ) [ 0 ]
@@ -203,7 +203,7 @@ function call() {
203
203
// Answer 미리 등록해놓고
204
204
socket . on ( ANSWER , ( desc ) => {
205
205
trace ( "received answer" ) ;
206
- clientPc
206
+ pcClient
207
207
. setRemoteDescription ( desc )
208
208
. then ( ( ) => {
209
209
trace ( "client: setRemoteDescription complete" ) ;
@@ -217,10 +217,10 @@ function call() {
217
217
} ) ;
218
218
} ) ;
219
219
220
- clientPc
220
+ pcClient
221
221
. createOffer ( )
222
222
. then ( ( offerDesc ) => {
223
- clientPc . setLocalDescription ( ) ;
223
+ pcClient . setLocalDescription ( ) ;
224
224
trace ( "setLocalDescription" ) ;
225
225
return offerDesc ;
226
226
} )
@@ -235,24 +235,24 @@ function call() {
235
235
} ) ;
236
236
} else {
237
237
socket . on ( OFFER , ( offerDesc ) => {
238
- trace ( "received offer" ) ;
238
+ trace ( "received offer:" , offerDesc . sdp ) ;
239
239
240
- clientPc
240
+ pcClient
241
241
. setRemoteDescription ( offerDesc )
242
242
. then ( ( ) => {
243
- trace ( "client: setRemoteDescription complete" ) ;
244
- return clientPc . createAnswer ( ) ;
243
+ trace ( "client: setRemoteDescription complete" , offerDesc ) ;
244
+ return pcClient . createAnswer ( ) ;
245
245
} )
246
246
. catch ( ( error ) => {
247
247
trace ( "Failed to setRemoteDescription: " + error . toString ( ) ) ;
248
248
} )
249
249
. then ( ( answerDesc ) => {
250
- clientPc . setLocalDescription ( answerDesc ) ;
250
+ pcClient . setLocalDescription ( answerDesc ) ;
251
251
return answerDesc ;
252
252
} )
253
253
. then ( ( answerDesc ) => {
254
254
trace ( "client: setLocalDescription complete" ) ;
255
- trace ( "answer from client" ) ;
255
+ trace ( "answer from client" , answerDesc ) ;
256
256
socket . emit ( ANSWER , answerDesc ) ;
257
257
trace ( "Connection Succeeeded!" ) ;
258
258
} )
@@ -268,12 +268,12 @@ function hangup() {
268
268
hangupButton . disabled = true ;
269
269
callButton . disabled = false ;
270
270
socket . close ( ) ;
271
- clientPc . close ( ) ;
272
- clientPc = null ;
271
+ pcClient . close ( ) ;
272
+ pcClient = null ;
273
273
}
274
274
275
275
// logging utility
276
- function trace ( arg ) {
276
+ function trace ( ... args ) {
277
277
const now = ( window . performance . now ( ) / 1000 ) . toFixed ( 3 ) ;
278
- console . log ( now + ": " , arg ) ;
278
+ console . log ( now + ": " , ... args ) ;
279
279
}
0 commit comments