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 var protocol = location.protocol.replace('http', 'ws'); | 6 |
7 var url = protocol + '//' + location.host + '/echo-with-no-extension'; | 7 var href = window.location.href; |
| 8 var hostBegin = href.indexOf('/') + 2; |
| 9 var hostEnd = href.lastIndexOf(':'); |
| 10 var host = href.slice(hostBegin, hostEnd); |
| 11 var portBegin = hostEnd + 1; |
| 12 var portEnd = href.lastIndexOf('/'); |
| 13 var port = href.slice(portBegin, portEnd); |
| 14 var scheme = href.indexOf('https') >= 0 ? 'wss' : 'ws'; |
| 15 var url = scheme + '://' + host + ':' + port + '/echo-with-no-extension'; |
| 16 |
8 // Do connection test. | 17 // Do connection test. |
9 var ws = new WebSocket(url); | 18 var ws = new WebSocket(url); |
10 | 19 |
11 ws.onopen = function() | 20 ws.onopen = function() |
12 { | 21 { |
13 // Set document title to 'PASS'. The test observer catches this title changes | 22 // Set document title to 'PASS'. The test observer catches this title changes |
14 // to know the result. | 23 // to know the result. |
15 document.title = 'PASS'; | 24 document.title = 'PASS'; |
16 } | 25 } |
17 | 26 |
18 ws.onclose = function() | 27 ws.onclose = function() |
19 { | 28 { |
20 // Set document title to 'FAIL'. | 29 // Set document title to 'FAIL'. |
21 document.title = 'FAIL'; | 30 document.title = 'FAIL'; |
22 } | 31 } |
23 | 32 |
24 </script> | 33 </script> |
25 </head> | 34 </head> |
26 </html> | 35 </html> |
OLD | NEW |