2014-09-04 11:48:31 +00:00
|
|
|
var __SERVER__NAME = "{{host}}";
|
|
|
|
var __PORT = {{ports[ws][0]}};
|
2015-06-03 18:52:25 +00:00
|
|
|
var __SECURE__PORT = {{ports[wss][0]}};
|
2014-09-04 11:48:31 +00:00
|
|
|
var __NEW__PORT = __PORT; //All ports are non-default for now
|
2015-06-03 18:52:25 +00:00
|
|
|
var __NEW__SECURE__PORT = __SECURE__PORT; //All ports are non-default for now
|
2014-09-04 11:48:31 +00:00
|
|
|
var __PATH = "echo";
|
|
|
|
var wsocket;
|
|
|
|
var data;
|
|
|
|
|
|
|
|
function IsWebSocket() {
|
2016-02-22 13:35:16 +00:00
|
|
|
if (!self.WebSocket) {
|
2014-09-04 11:48:31 +00:00
|
|
|
assert_true(false, "Browser does not support WebSocket");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function CreateWebSocketNonAbsolute() {
|
|
|
|
IsWebSocket();
|
2016-02-02 22:04:13 +00:00
|
|
|
var url = __SERVER__NAME;
|
|
|
|
wsocket = new WebSocket(url);
|
2014-09-04 11:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function CreateWebSocketNonWsScheme() {
|
|
|
|
IsWebSocket();
|
2016-02-02 22:04:13 +00:00
|
|
|
var url = "http://" + __SERVER__NAME + ":" + __PORT + "/" + __PATH;
|
|
|
|
wsocket = new WebSocket(url);
|
2014-09-04 11:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function CreateWebSocketNonAsciiProtocol(nonAsciiProtocol) {
|
|
|
|
IsWebSocket();
|
2016-02-02 22:04:13 +00:00
|
|
|
var url = "ws://" + __SERVER__NAME + ":" + __PORT + "/" + __PATH;
|
|
|
|
wsocket = new WebSocket(url, nonAsciiProtocol);
|
2014-09-04 11:48:31 +00:00
|
|
|
}
|
|
|
|
|
2016-01-29 23:24:42 +00:00
|
|
|
function CreateWebSocketWithAsciiSep(asciiWithSep) {
|
|
|
|
IsWebSocket();
|
2016-02-02 22:04:13 +00:00
|
|
|
var url = "ws://" + __SERVER__NAME + ":" + __PORT + "/" + __PATH;
|
|
|
|
wsocket = new WebSocket(url, asciiWithSep);
|
2016-01-29 23:24:42 +00:00
|
|
|
}
|
|
|
|
|
2014-09-04 11:48:31 +00:00
|
|
|
function CreateWebSocketWithBlockedPort(blockedPort) {
|
|
|
|
IsWebSocket();
|
2017-04-04 16:01:41 +00:00
|
|
|
var url = "ws://" + __SERVER__NAME + ":" + blockedPort + "/" + __PATH;
|
|
|
|
return new WebSocket(url);
|
2014-09-04 11:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function CreateWebSocketWithSpaceInUrl(urlWithSpace) {
|
|
|
|
IsWebSocket();
|
2016-02-02 22:04:13 +00:00
|
|
|
var url = "ws://" + urlWithSpace + ":" + __PORT + "/" + __PATH;
|
|
|
|
wsocket = new WebSocket(url);
|
2014-09-04 11:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function CreateWebSocketWithSpaceInProtocol(protocolWithSpace) {
|
|
|
|
IsWebSocket();
|
2016-02-02 22:04:13 +00:00
|
|
|
var url = "ws://" + __SERVER__NAME + ":" + __PORT + "/" + __PATH;
|
|
|
|
wsocket = new WebSocket(url, protocolWithSpace);
|
2014-09-04 11:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function CreateWebSocketWithRepeatedProtocols() {
|
|
|
|
IsWebSocket();
|
2016-02-02 22:04:13 +00:00
|
|
|
var url = "ws://" + __SERVER__NAME + ":" + __PORT + "/" + __PATH;
|
|
|
|
wsocket = new WebSocket(url, ["echo", "echo"]);
|
2014-09-04 11:48:31 +00:00
|
|
|
}
|
|
|
|
|
2016-01-29 23:24:42 +00:00
|
|
|
function CreateWebSocketWithRepeatedProtocolsCaseInsensitive() {
|
|
|
|
IsWebSocket();
|
2016-02-02 22:04:13 +00:00
|
|
|
var url = "ws://" + __SERVER__NAME + ":" + __PORT + "/" + __PATH;
|
|
|
|
wsocket = new WebSocket(url, ["echo", "eCho"]);
|
2016-01-29 23:24:42 +00:00
|
|
|
}
|
|
|
|
|
2014-09-04 11:48:31 +00:00
|
|
|
function CreateWebSocket(isSecure, isProtocol, isProtocols) {
|
|
|
|
IsWebSocket();
|
2016-02-02 22:04:13 +00:00
|
|
|
var url;
|
2014-09-04 11:48:31 +00:00
|
|
|
if (isSecure) {
|
|
|
|
if (__SECURE__PORT === null) {
|
|
|
|
throw new Error("wss not yet supported");
|
|
|
|
}
|
2016-02-02 22:04:13 +00:00
|
|
|
url = "wss://" + __SERVER__NAME + ":" + __SECURE__PORT + "/" + __PATH;
|
2014-09-04 11:48:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-02-02 22:04:13 +00:00
|
|
|
url = "ws://" + __SERVER__NAME + ":" + __PORT + "/" + __PATH;
|
2014-09-04 11:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isProtocol) {
|
2016-02-02 22:04:13 +00:00
|
|
|
wsocket = new WebSocket(url, "echo");
|
2014-09-04 11:48:31 +00:00
|
|
|
}
|
|
|
|
else if (isProtocols) {
|
2016-02-02 22:04:13 +00:00
|
|
|
wsocket = new WebSocket(url, ["echo", "chat"]);
|
2014-09-04 11:48:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-02-02 22:04:13 +00:00
|
|
|
wsocket = new WebSocket(url);
|
2014-09-04 11:48:31 +00:00
|
|
|
}
|
|
|
|
return wsocket;
|
|
|
|
}
|
|
|
|
|
|
|
|
function CreateControlWebSocket(isSecure) {
|
|
|
|
IsWebSocket();
|
2016-02-02 22:04:13 +00:00
|
|
|
var url;
|
2014-09-04 11:48:31 +00:00
|
|
|
if (isSecure) {
|
2016-02-02 22:04:13 +00:00
|
|
|
url = "wss://" + __SERVER__NAME + ":" + __SECURE__PORT + "/control";
|
2014-09-04 11:48:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-02-02 22:04:13 +00:00
|
|
|
url = "ws://" + __SERVER__NAME + ":" + __PORT + "/control";
|
2014-09-04 11:48:31 +00:00
|
|
|
}
|
|
|
|
|
2016-02-02 22:04:13 +00:00
|
|
|
return new WebSocket(url);
|
2014-09-04 11:48:31 +00:00
|
|
|
}
|
|
|
|
|