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

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: added error message handling answer/offer and setLocal/remote desc 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
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);
kjellander_chromium 2014/06/09 19:42:56 This also takes success and failure callbacks. Can
jansson 2014/06/10 05:50:27 Done.
448 return; 448 return;
449 } 449 }
450 error_('unknown message received'); 450 error_('unknown message received');
451 } 451 }
452 452
453 function createPeerConnection(stun_server, useRtpDataChannels) { 453 function createPeerConnection(stun_server, useRtpDataChannels) {
454 servers = {iceServers: [{url: 'stun:' + stun_server}]}; 454 servers = {iceServers: [{url: 'stun:' + stun_server}]};
455 try { 455 try {
456 var constraints = { optional: [{ RtpDataChannels: useRtpDataChannels }]}; 456 var constraints = { optional: [{ RtpDataChannels: useRtpDataChannels }]};
457 peerConnection = new RTCPeerConnection(servers, constraints); 457 peerConnection = new RTCPeerConnection(servers, constraints);
458 } catch (exception) { 458 } catch (exception) {
459 error_('Failed to create peer connection: ' + exception); 459 error_('Failed to create peer connection: ' + exception);
460 } 460 }
461 peerConnection.onaddstream = addStreamCallback_; 461 peerConnection.onaddstream = addStreamCallback_;
462 peerConnection.onremovestream = removeStreamCallback_; 462 peerConnection.onremovestream = removeStreamCallback_;
463 peerConnection.onicecandidate = iceCallback_; 463 peerConnection.onicecandidate = iceCallback_;
464 peerConnection.ondatachannel = onCreateDataChannelCallback_; 464 peerConnection.ondatachannel = onCreateDataChannelCallback_;
465 return peerConnection; 465 return peerConnection;
466 } 466 }
467 467
468 function setupCall(peerConnection) { 468 function setupCall(peerConnection) {
469 print_('createOffer with constraints: ' + 469 print_('createOffer with constraints: ' +
470 JSON.stringify(global.createOfferConstraints, null, ' ')); 470 JSON.stringify(global.createOfferConstraints, null, ' '));
471 peerConnection.createOffer( 471 peerConnection.createOffer(
472 setLocalAndSendMessage_, 472 setLocalAndSendMessage_,
473 function() { failure_('createOffer'); }, 473 function(error) { failure_('createOffer', error); },
474 global.createOfferConstraints); 474 global.createOfferConstraints);
475 } 475 }
476 476
477 function answerCall(peerConnection, message) { 477 function answerCall(peerConnection, message) {
478 handleMessage(peerConnection, message); 478 handleMessage(peerConnection, message);
479 } 479 }
480 480
481 function createDataChannel(peerConnection, label) { 481 function createDataChannel(peerConnection, label) {
482 if (global.dataChannel != null && global.dataChannel.readyState != 'closed') 482 if (global.dataChannel != null && global.dataChannel.readyState != 'closed')
483 error_('Creating DataChannel, but we already have one.'); 483 error_('Creating DataChannel, but we already have one.');
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 print_(gRequestWebcamAndMicrophoneResult); 885 print_(gRequestWebcamAndMicrophoneResult);
886 } 886 }
887 887
888 /** @private */ 888 /** @private */
889 function success_(method) { 889 function success_(method) {
890 print_(method + '(): success.'); 890 print_(method + '(): success.');
891 } 891 }
892 892
893 /** @private */ 893 /** @private */
894 function failure_(method, error) { 894 function failure_(method, error) {
895 error_(method + '() failed: ' + error); 895 error_(method + '() failed: ' + JSON.stringify(error));
896 } 896 }
897 897
898 /** @private */ 898 /** @private */
899 function iceCallback_(event) { 899 function iceCallback_(event) {
900 if (event.candidate) 900 if (event.candidate)
901 sendToPeer(global.remotePeerId, JSON.stringify(event.candidate)); 901 sendToPeer(global.remotePeerId, JSON.stringify(event.candidate));
902 } 902 }
903 903
904 /** @private */ 904 /** @private */
905 function setLocalAndSendMessage_(session_description) { 905 function setLocalAndSendMessage_(session_description) {
906 session_description.sdp = 906 session_description.sdp =
907 global.transformOutgoingSdp(session_description.sdp); 907 global.transformOutgoingSdp(session_description.sdp);
908 global.peerConnection.setLocalDescription( 908 global.peerConnection.setLocalDescription(
909 session_description, 909 session_description,
910 function() { success_('setLocalDescription'); }, 910 function() { success_('setLocalDescription'); },
911 function() { failure_('setLocalDescription'); }); 911 function(error) { failure_('setLocalDescription', error); });
912 print_('Sending SDP message:\n' + session_description.sdp); 912 print_('Sending SDP message:\n' + session_description.sdp);
913 sendToPeer(global.remotePeerId, JSON.stringify(session_description)); 913 sendToPeer(global.remotePeerId, JSON.stringify(session_description));
914 } 914 }
915 915
916 /** @private */ 916 /** @private */
917 function addStreamCallback_(event) { 917 function addStreamCallback_(event) {
918 print_('Receiving remote stream...'); 918 print_('Receiving remote stream...');
919 var videoTag = document.getElementById('remote-view'); 919 var videoTag = document.getElementById('remote-view');
920 attachMediaStream(videoTag, event.stream); 920 attachMediaStream(videoTag, event.stream);
921 921
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 1359
1360 /** @private */ 1360 /** @private */
1361 function readResponseHeader_(request, key) { 1361 function readResponseHeader_(request, key) {
1362 var value = request.getResponseHeader(key); 1362 var value = request.getResponseHeader(key);
1363 if (value == null || value.length == 0) { 1363 if (value == null || value.length == 0) {
1364 error_('Received empty value ' + value + 1364 error_('Received empty value ' + value +
1365 ' for response header key ' + key + '.'); 1365 ' for response header key ' + key + '.');
1366 } 1366 }
1367 return parseInt(value); 1367 return parseInt(value);
1368 } 1368 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/webrtc/peerconnection.js » ('j') | chrome/test/data/webrtc/peerconnection.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698