OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>test ws connection</title> | 4 <title>test ws connection</title> |
5 <script type="text/javascript"> | 5 <script type="text/javascript"> |
6 | 6 |
7 var href = window.location.href; | 7 var href = window.location.href; |
8 var hostBegin = href.indexOf('/') + 2; | 8 var queryBegin = href.indexOf('?url='); |
9 var hostEnd = href.lastIndexOf(':'); | 9 if (queryBegin == -1) { |
10 var host = href.slice(hostBegin, hostEnd); | 10 console.log("Failed to find ?url= in URL"); |
11 var portBegin = hostEnd + 1; | 11 document.title = 'FAIL'; |
12 var portEnd = href.lastIndexOf('/'); | 12 throw "FAILURE"; |
13 var port = href.slice(portBegin, portEnd); | 13 } |
14 var scheme = href.indexOf('https') >= 0 ? 'wss' : 'ws'; | 14 var url = href.slice(queryBegin + 5); |
15 var url = scheme + '://' + host + ':' + port + '/echo-with-no-extension'; | |
16 | 15 |
17 // Do connection test. | 16 // Do connection test. |
18 var ws = new WebSocket(url); | 17 var ws = new WebSocket(url); |
19 | 18 |
20 ws.onopen = function() | 19 ws.onopen = function() |
21 { | 20 { |
22 // Set document title to 'PASS'. The test observer catches this title changes | 21 // Set document title to 'PASS'. The test observer catches this title changes |
23 // to know the result. | 22 // to know the result. |
24 document.title = 'PASS'; | 23 document.title = 'PASS'; |
25 } | 24 } |
26 | 25 |
27 ws.onclose = function() | 26 ws.onclose = function() |
28 { | 27 { |
29 // Set document title to 'FAIL'. | 28 // Set document title to 'FAIL'. |
30 document.title = 'FAIL'; | 29 document.title = 'FAIL'; |
31 } | 30 } |
32 | 31 |
33 </script> | 32 </script> |
34 </head> | 33 </head> |
35 </html> | 34 </html> |
OLD | NEW |