OLD | NEW |
1 /** | 1 /** |
2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 * Copyright (c) 2012 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 // This file requires these functions to be defined globally by someone else: | 7 // This file requires these functions to be defined globally by someone else: |
8 // function handleMessage(peerConnection, message) | 8 // function handleMessage(peerConnection, message) |
9 // function createPeerConnection(stun_server) | 9 // function createPeerConnection(stun_server) |
10 // function setupCall(peerConnection) | 10 // function setupCall(peerConnection) |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 * Disconnects from the peerconnection server. Returns ok-disconnected on | 118 * Disconnects from the peerconnection server. Returns ok-disconnected on |
119 * success. | 119 * success. |
120 */ | 120 */ |
121 function disconnect() { | 121 function disconnect() { |
122 if (gOurPeerId == null) | 122 if (gOurPeerId == null) |
123 failTest('Disconnecting, but we are not connected.'); | 123 failTest('Disconnecting, but we are not connected.'); |
124 | 124 |
125 request = new XMLHttpRequest(); | 125 request = new XMLHttpRequest(); |
126 request.open("GET", gServerUrl + "/sign_out?peer_id=" + gOurPeerId, false); | 126 request.open("GET", gServerUrl + "/sign_out?peer_id=" + gOurPeerId, false); |
127 request.send(); | 127 request.send(); |
128 request = null; | |
129 gOurPeerId = null; | 128 gOurPeerId = null; |
130 returnToPyAuto('ok-disconnected'); | 129 returnToPyAuto('ok-disconnected'); |
131 } | 130 } |
132 | 131 |
133 // Internals. | 132 // Internals. |
134 | 133 |
| 134 function isDisconnected() { |
| 135 return gOurPeerId == null; |
| 136 } |
| 137 |
135 function connectCallback(request) { | 138 function connectCallback(request) { |
136 debug("Connect callback: " + request.status + ", " + request.readyState); | 139 debug("Connect callback: " + request.status + ", " + request.readyState); |
137 if (request.readyState == 4 && request.status == 200) { | 140 if (request.readyState == 4 && request.status == 200) { |
138 gOurPeerId = parseOurPeerId(request.responseText); | 141 gOurPeerId = parseOurPeerId(request.responseText); |
139 gRemotePeerId = parseRemotePeerIdIfConnected(request.responseText); | 142 gRemotePeerId = parseRemotePeerIdIfConnected(request.responseText); |
140 startHangingGet(gServerUrl, gOurPeerId); | 143 startHangingGet(gServerUrl, gOurPeerId); |
141 returnToPyAuto('ok-connected'); | 144 returnToPyAuto('ok-connected'); |
142 } | 145 } |
143 } | 146 } |
144 | 147 |
(...skipping 27 matching lines...) Expand all Loading... |
172 failTest('Unexpected second peer'); | 175 failTest('Unexpected second peer'); |
173 | 176 |
174 // Found a remote peer. | 177 // Found a remote peer. |
175 remotePeerId = id; | 178 remotePeerId = id; |
176 } | 179 } |
177 } | 180 } |
178 return remotePeerId; | 181 return remotePeerId; |
179 } | 182 } |
180 | 183 |
181 function startHangingGet(server, ourId) { | 184 function startHangingGet(server, ourId) { |
| 185 if (isDisconnected()) |
| 186 return; |
182 hangingGetRequest = new XMLHttpRequest(); | 187 hangingGetRequest = new XMLHttpRequest(); |
183 hangingGetRequest.onreadystatechange = function() { | 188 hangingGetRequest.onreadystatechange = function() { |
184 hangingGetCallback(hangingGetRequest, server, ourId); | 189 hangingGetCallback(hangingGetRequest, server, ourId); |
185 } | 190 } |
186 hangingGetRequest.ontimeout = function() { | 191 hangingGetRequest.ontimeout = function() { |
187 hangingGetTimeoutCallback(hangingGetRequest, server, ourId); | 192 hangingGetTimeoutCallback(hangingGetRequest, server, ourId); |
188 } | 193 } |
189 callUrl = server + "/wait?peer_id=" + ourId; | 194 callUrl = server + "/wait?peer_id=" + ourId; |
190 debug('Sending ' + callUrl); | 195 debug('Sending ' + callUrl); |
191 hangingGetRequest.open("GET", callUrl, true); | 196 hangingGetRequest.open("GET", callUrl, true); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 284 |
280 function readResponseHeader(request, key) { | 285 function readResponseHeader(request, key) { |
281 var value = request.getResponseHeader(key) | 286 var value = request.getResponseHeader(key) |
282 if (value == null || value.length == 0) { | 287 if (value == null || value.length == 0) { |
283 addTestFailure('Received empty value ' + value + | 288 addTestFailure('Received empty value ' + value + |
284 ' for response header key ' + key + '.'); | 289 ' for response header key ' + key + '.'); |
285 return -1; | 290 return -1; |
286 } | 291 } |
287 return parseInt(value); | 292 return parseInt(value); |
288 } | 293 } |
OLD | NEW |