Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(389)

Side by Side Diff: chrome/test/data/webrtc/manual/peerconnection_manual.js

Issue 306033004: Now catches the error message from RTCPeerConnection and createAnswer/Offer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed the format Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/test/data/webrtc/peerconnection.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 success'); },
kjellander_chromium 2014/06/10 08:55:33 No need to put the ' success' part in here. For th
jansson 2014/06/10 10:08:55 Done.
449 function(error) { failure_('addIceCandidate failed', error); }
450 );
448 return; 451 return;
449 } 452 }
450 error_('unknown message received'); 453 error_('unknown message received');
451 } 454 }
452 455
453 function createPeerConnection(stun_server, useRtpDataChannels) { 456 function createPeerConnection(stun_server, useRtpDataChannels) {
454 servers = {iceServers: [{url: 'stun:' + stun_server}]}; 457 servers = {iceServers: [{url: 'stun:' + stun_server}]};
455 try { 458 try {
456 var constraints = { optional: [{ RtpDataChannels: useRtpDataChannels }]}; 459 var constraints = { optional: [{ RtpDataChannels: useRtpDataChannels }]};
457 peerConnection = new RTCPeerConnection(servers, constraints); 460 peerConnection = new RTCPeerConnection(servers, constraints);
458 } catch (exception) { 461 } catch (exception) {
459 error_('Failed to create peer connection: ' + exception); 462 error_('Failed to create peer connection: ' + exception);
460 } 463 }
461 peerConnection.onaddstream = addStreamCallback_; 464 peerConnection.onaddstream = addStreamCallback_;
462 peerConnection.onremovestream = removeStreamCallback_; 465 peerConnection.onremovestream = removeStreamCallback_;
463 peerConnection.onicecandidate = iceCallback_; 466 peerConnection.onicecandidate = iceCallback_;
464 peerConnection.ondatachannel = onCreateDataChannelCallback_; 467 peerConnection.ondatachannel = onCreateDataChannelCallback_;
465 return peerConnection; 468 return peerConnection;
466 } 469 }
467 470
468 function setupCall(peerConnection) { 471 function setupCall(peerConnection) {
469 print_('createOffer with constraints: ' + 472 print_('createOffer with constraints: ' +
470 JSON.stringify(global.createOfferConstraints, null, ' ')); 473 JSON.stringify(global.createOfferConstraints, null, ' '));
471 peerConnection.createOffer( 474 peerConnection.createOffer(
472 setLocalAndSendMessage_, 475 setLocalAndSendMessage_,
473 function() { failure_('createOffer'); }, 476 function(error) { failure_('createOffer', error); },
474 global.createOfferConstraints); 477 global.createOfferConstraints);
475 } 478 }
476 479
477 function answerCall(peerConnection, message) { 480 function answerCall(peerConnection, message) {
478 handleMessage(peerConnection, message); 481 handleMessage(peerConnection, message);
479 } 482 }
480 483
481 function createDataChannel(peerConnection, label) { 484 function createDataChannel(peerConnection, label) {
482 if (global.dataChannel != null && global.dataChannel.readyState != 'closed') 485 if (global.dataChannel != null && global.dataChannel.readyState != 'closed')
483 error_('Creating DataChannel, but we already have one.'); 486 error_('Creating DataChannel, but we already have one.');
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 print_(gRequestWebcamAndMicrophoneResult); 888 print_(gRequestWebcamAndMicrophoneResult);
886 } 889 }
887 890
888 /** @private */ 891 /** @private */
889 function success_(method) { 892 function success_(method) {
890 print_(method + '(): success.'); 893 print_(method + '(): success.');
891 } 894 }
892 895
893 /** @private */ 896 /** @private */
894 function failure_(method, error) { 897 function failure_(method, error) {
895 error_(method + '() failed: ' + error); 898 error_(method + '() failed: ' + JSON.stringify(error));
896 } 899 }
897 900
898 /** @private */ 901 /** @private */
899 function iceCallback_(event) { 902 function iceCallback_(event) {
900 if (event.candidate) 903 if (event.candidate)
901 sendToPeer(global.remotePeerId, JSON.stringify(event.candidate)); 904 sendToPeer(global.remotePeerId, JSON.stringify(event.candidate));
902 } 905 }
903 906
904 /** @private */ 907 /** @private */
905 function setLocalAndSendMessage_(session_description) { 908 function setLocalAndSendMessage_(session_description) {
906 session_description.sdp = 909 session_description.sdp =
907 global.transformOutgoingSdp(session_description.sdp); 910 global.transformOutgoingSdp(session_description.sdp);
908 global.peerConnection.setLocalDescription( 911 global.peerConnection.setLocalDescription(
909 session_description, 912 session_description,
910 function() { success_('setLocalDescription'); }, 913 function() { success_('setLocalDescription'); },
911 function() { failure_('setLocalDescription'); }); 914 function(error) { failure_('setLocalDescription', error); });
912 print_('Sending SDP message:\n' + session_description.sdp); 915 print_('Sending SDP message:\n' + session_description.sdp);
913 sendToPeer(global.remotePeerId, JSON.stringify(session_description)); 916 sendToPeer(global.remotePeerId, JSON.stringify(session_description));
914 } 917 }
915 918
916 /** @private */ 919 /** @private */
917 function addStreamCallback_(event) { 920 function addStreamCallback_(event) {
918 print_('Receiving remote stream...'); 921 print_('Receiving remote stream...');
919 var videoTag = document.getElementById('remote-view'); 922 var videoTag = document.getElementById('remote-view');
920 attachMediaStream(videoTag, event.stream); 923 attachMediaStream(videoTag, event.stream);
921 924
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 1362
1360 /** @private */ 1363 /** @private */
1361 function readResponseHeader_(request, key) { 1364 function readResponseHeader_(request, key) {
1362 var value = request.getResponseHeader(key); 1365 var value = request.getResponseHeader(key);
1363 if (value == null || value.length == 0) { 1366 if (value == null || value.length == 0) {
1364 error_('Received empty value ' + value + 1367 error_('Received empty value ' + value +
1365 ' for response header key ' + key + '.'); 1368 ' for response header key ' + key + '.');
1366 } 1369 }
1367 return parseInt(value); 1370 return parseInt(value);
1368 } 1371 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/webrtc/peerconnection.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698