OLD | NEW |
1 /** | 1 /** |
2 * Copyright 2014 The Chromium Authors. All rights reserved. | 2 * Copyright 2014 The Chromium Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 /** | 7 /** |
8 * See http://dev.w3.org/2011/webrtc/editor/getusermedia.html for more | 8 * See http://dev.w3.org/2011/webrtc/editor/getusermedia.html for more |
9 * information on getUserMedia. See | 9 * information on getUserMedia. See |
10 * http://dev.w3.org/2011/webrtc/editor/webrtc.html for more information on | 10 * http://dev.w3.org/2011/webrtc/editor/webrtc.html for more information on |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 global.dtmfSender.insertDTMF(tones, duration, interToneGap); | 425 global.dtmfSender.insertDTMF(tones, duration, interToneGap); |
426 } | 426 } |
427 | 427 |
428 function handleMessage(peerConnection, message) { | 428 function handleMessage(peerConnection, message) { |
429 var parsed_msg = JSON.parse(message); | 429 var parsed_msg = JSON.parse(message); |
430 if (parsed_msg.type) { | 430 if (parsed_msg.type) { |
431 var session_description = new RTCSessionDescription(parsed_msg); | 431 var session_description = new RTCSessionDescription(parsed_msg); |
432 peerConnection.setRemoteDescription( | 432 peerConnection.setRemoteDescription( |
433 session_description, | 433 session_description, |
434 function() { success_('setRemoteDescription'); }, | 434 function() { success_('setRemoteDescription'); }, |
435 function() { failure_('setRemoteDescription'); }); | 435 function(error) { failure_('setRemoteDescription', error); }); |
436 if (session_description.type == 'offer') { | 436 if (session_description.type == 'offer') { |
437 print_('createAnswer with constraints: ' + | 437 print_('createAnswer with constraints: ' + |
438 JSON.stringify(global.createAnswerConstraints, null, ' ')); | 438 JSON.stringify(global.createAnswerConstraints, null, ' ')); |
439 peerConnection.createAnswer( | 439 peerConnection.createAnswer( |
440 setLocalAndSendMessage_, | 440 setLocalAndSendMessage_, |
441 function() { failure_('createAnswer'); }, | 441 function(error) { failure_('createAnswer', error); }, |
442 global.createAnswerConstraints); | 442 global.createAnswerConstraints); |
443 } | 443 } |
444 return; | 444 return; |
445 } else if (parsed_msg.candidate) { | 445 } else if (parsed_msg.candidate) { |
446 var candidate = new RTCIceCandidate(parsed_msg); | 446 var candidate = new RTCIceCandidate(parsed_msg); |
447 peerConnection.addIceCandidate(candidate); | 447 peerConnection.addIceCandidate(candidate, |
| 448 function() { success_('addIceCandidate'); }, |
| 449 function(error) { failure_('addIceCandidate', error); } |
| 450 ); |
448 return; | 451 return; |
449 } | 452 } |
450 error_('unknown message received'); | 453 error_('unknown message received'); |
451 } | 454 } |
452 | 455 |
453 /** | 456 /** |
454 * Sets the peerConnection constraints based on checkboxes. | 457 * Sets the peerConnection constraints based on checkboxes. |
455 * TODO (jansson) Make it possible to use the text field for constraints like | 458 * TODO (jansson) Make it possible to use the text field for constraints like |
456 * for getUserMedia. | 459 * for getUserMedia. |
457 */ | 460 */ |
(...skipping 24 matching lines...) Expand all Loading... |
482 peerConnection.onicecandidate = iceCallback_; | 485 peerConnection.onicecandidate = iceCallback_; |
483 peerConnection.ondatachannel = onCreateDataChannelCallback_; | 486 peerConnection.ondatachannel = onCreateDataChannelCallback_; |
484 return peerConnection; | 487 return peerConnection; |
485 } | 488 } |
486 | 489 |
487 function setupCall(peerConnection) { | 490 function setupCall(peerConnection) { |
488 print_('createOffer with constraints: ' + | 491 print_('createOffer with constraints: ' + |
489 JSON.stringify(global.createOfferConstraints, null, ' ')); | 492 JSON.stringify(global.createOfferConstraints, null, ' ')); |
490 peerConnection.createOffer( | 493 peerConnection.createOffer( |
491 setLocalAndSendMessage_, | 494 setLocalAndSendMessage_, |
492 function() { failure_('createOffer'); }, | 495 function(error) { failure_('createOffer', error); }, |
493 global.createOfferConstraints); | 496 global.createOfferConstraints); |
494 } | 497 } |
495 | 498 |
496 function answerCall(peerConnection, message) { | 499 function answerCall(peerConnection, message) { |
497 handleMessage(peerConnection, message); | 500 handleMessage(peerConnection, message); |
498 } | 501 } |
499 | 502 |
500 function createDataChannel(peerConnection, label) { | 503 function createDataChannel(peerConnection, label) { |
501 if (global.dataChannel != null && global.dataChannel.readyState != 'closed') | 504 if (global.dataChannel != null && global.dataChannel.readyState != 'closed') |
502 error_('Creating DataChannel, but we already have one.'); | 505 error_('Creating DataChannel, but we already have one.'); |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 print_(gRequestWebcamAndMicrophoneResult); | 906 print_(gRequestWebcamAndMicrophoneResult); |
904 } | 907 } |
905 | 908 |
906 /** @private */ | 909 /** @private */ |
907 function success_(method) { | 910 function success_(method) { |
908 print_(method + '(): success.'); | 911 print_(method + '(): success.'); |
909 } | 912 } |
910 | 913 |
911 /** @private */ | 914 /** @private */ |
912 function failure_(method, error) { | 915 function failure_(method, error) { |
913 error_(method + '() failed: ' + error); | 916 error_(method + '() failed: ' + JSON.stringify(error)); |
914 } | 917 } |
915 | 918 |
916 /** @private */ | 919 /** @private */ |
917 function iceCallback_(event) { | 920 function iceCallback_(event) { |
918 if (event.candidate) | 921 if (event.candidate) |
919 sendToPeer(global.remotePeerId, JSON.stringify(event.candidate)); | 922 sendToPeer(global.remotePeerId, JSON.stringify(event.candidate)); |
920 } | 923 } |
921 | 924 |
922 /** @private */ | 925 /** @private */ |
923 function setLocalAndSendMessage_(session_description) { | 926 function setLocalAndSendMessage_(session_description) { |
924 session_description.sdp = | 927 session_description.sdp = |
925 global.transformOutgoingSdp(session_description.sdp); | 928 global.transformOutgoingSdp(session_description.sdp); |
926 global.peerConnection.setLocalDescription( | 929 global.peerConnection.setLocalDescription( |
927 session_description, | 930 session_description, |
928 function() { success_('setLocalDescription'); }, | 931 function() { success_('setLocalDescription'); }, |
929 function() { failure_('setLocalDescription'); }); | 932 function(error) { failure_('setLocalDescription', error); }); |
930 print_('Sending SDP message:\n' + session_description.sdp); | 933 print_('Sending SDP message:\n' + session_description.sdp); |
931 sendToPeer(global.remotePeerId, JSON.stringify(session_description)); | 934 sendToPeer(global.remotePeerId, JSON.stringify(session_description)); |
932 } | 935 } |
933 | 936 |
934 /** @private */ | 937 /** @private */ |
935 function addStreamCallback_(event) { | 938 function addStreamCallback_(event) { |
936 print_('Receiving remote stream...'); | 939 print_('Receiving remote stream...'); |
937 var videoTag = document.getElementById('remote-view'); | 940 var videoTag = document.getElementById('remote-view'); |
938 attachMediaStream(videoTag, event.stream); | 941 attachMediaStream(videoTag, event.stream); |
939 | 942 |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1376 | 1379 |
1377 /** @private */ | 1380 /** @private */ |
1378 function readResponseHeader_(request, key) { | 1381 function readResponseHeader_(request, key) { |
1379 var value = request.getResponseHeader(key); | 1382 var value = request.getResponseHeader(key); |
1380 if (value == null || value.length == 0) { | 1383 if (value == null || value.length == 0) { |
1381 error_('Received empty value ' + value + | 1384 error_('Received empty value ' + value + |
1382 ' for response header key ' + key + '.'); | 1385 ' for response header key ' + key + '.'); |
1383 } | 1386 } |
1384 return parseInt(value); | 1387 return parseInt(value); |
1385 } | 1388 } |
OLD | NEW |