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

Side by Side Diff: tools/perf/page_sets/webrtc_cases/peerconnection_multiple_files/main.js

Issue 2761163003: Use local pages for webrtc telemetry tests. (Closed)
Patch Set: Created 3 years, 9 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
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree.
7 */
8
9 /*jshint esversion: 6 */
10
11 'use strict';
12
13 var $ = document.getElementById.bind(document);
14
15 var testTable = $('test-table');
16 var nPeerConnectionsInput = $('num-peerconnections');
17 var startTestButton = $('start-test');
18 var cpuOveruseDetectionCheckbox = $('cpuoveruse-detection');
19
20 startTestButton.onclick = startTest;
21
22 function logError(err) {
23 console.err(err);
24 }
25
26 function addNewVideoElement() {
27 var newRow = testTable.insertRow(-1);
28 var newCell = newRow.insertCell(-1);
29 var video = document.createElement('video');
30 video.autoplay = true;
31 newCell.appendChild(video);
32 return video;
33 }
34
35 function PeerConnection(id, cpuOveruseDetection) {
36 this.id = id;
37 this.cpuOveruseDetection = cpuOveruseDetection;
38
39 this.localConnection = null;
40 this.remoteConnection = null;
41
42 this.remoteView = addNewVideoElement();
43
44 this.start = function() {
45 var onGetUserMediaSuccess = this.onGetUserMediaSuccess.bind(this);
46 navigator.mediaDevices.getUserMedia({
47 audio: true,
48 video: true
49 })
50 .then(onGetUserMediaSuccess)
51 .catch(logError);
52 };
53
54 this.onGetUserMediaSuccess = function(stream) {
55 // Create local peer connection.
56 this.localConnection = new RTCPeerConnection(null, {
57 'optional': [{
58 'googCpuOveruseDetection': this.cpuOveruseDetection
59 }]
60 });
61 this.localConnection.onicecandidate = (event) => {
62 this.onIceCandidate(this.remoteConnection, event);
63 };
64 this.localConnection.addStream(stream);
65
66 // Create remote peer connection.
67 this.remoteConnection = new RTCPeerConnection(null, {
68 'optional': [{
69 'googCpuOveruseDetection': this.cpuOveruseDetection
70 }]
71 });
72 this.remoteConnection.onicecandidate = (event) => {
73 this.onIceCandidate(this.localConnection, event);
74 };
75 this.remoteConnection.onaddstream = (e) => {
76 this.remoteView.srcObject = e.stream;
77 };
78
79 // Initiate call.
80 var onCreateOfferSuccess = this.onCreateOfferSuccess.bind(this);
81 this.localConnection.createOffer({
82 offerToReceiveAudio: 1,
83 offerToReceiveVideo: 1
84 })
85 .then(onCreateOfferSuccess, logError);
86 };
87
88 this.onCreateOfferSuccess = function(desc) {
89 this.localConnection.setLocalDescription(desc);
90 this.remoteConnection.setRemoteDescription(desc);
91
92 var onCreateAnswerSuccess = this.onCreateAnswerSuccess.bind(this);
93 this.remoteConnection.createAnswer()
94 .then(onCreateAnswerSuccess, logError);
95 };
96
97 this.onCreateAnswerSuccess = function(desc) {
98 this.remoteConnection.setLocalDescription(desc);
99 this.localConnection.setRemoteDescription(desc);
100 };
101
102 this.onIceCandidate = function(connection, event) {
103 if (event.candidate) {
104 connection.addIceCandidate(new RTCIceCandidate(event.candidate));
105 }
106 };
107 }
108
109 function startTest() {
110 var cpuOveruseDetection = cpuOveruseDetectionCheckbox.checked;
111 var nPeerConnections = nPeerConnectionsInput.value;
112 for (var i = 0; i < nPeerConnections; ++i) {
113 new PeerConnection(i, cpuOveruseDetection).start();
114 }
115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698