let ws1;
function connectTestServer(event){
for(let i=0; i< 2; i++){
ws1 = new WebSocket("wss://server1.bayadic.com/ssw");
let button = event.target;
ws1.onopen = function(e) {
button.style.backgroundColor = "green";
console.log("test server opened");
for(let j = 0; j< 5; j++){
ws1.send("hi "+j);
}
}
ws1.onerror = function(e) {
button.style.backgroundColor = "red";
console.log("test server error");
}
ws1.onclose = function(e) {
button.style.backgroundColor = "gray";
console.log("test server close");
}
ws1.onmessage = function(e){
console.log("new message" ,e);
}
}
}
function startTestServer() {
const parts = document.URL.split("/");
const url = document.URL.replace(parts[parts.length-1],"")+"restart.php";
callUrl(url);
}
function stopTestServer() {
const parts = document.URL.split("/");
const url = document.URL.replace(parts[parts.length-1],"")+"stop.php";
callUrl(url);
}
function callUrl(url) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (this.readyState != 4)
return;
if (this.status == 200) {
console.log(this.responseText);
}
};
xhr.open('GET', url, true);
xhr.send();
}
function sendMessageToTestServer(event){
for(let m = 0; m<10;m++)
ws1.send("hi how r u");
}
function connectToOriginalServer(event){
let ws2 = new WebSocket("wss://server1.bayadic.com/wss");
let button = event.target;
ws2.onopen = function(e) {
console.log("test server opened");
button.style.backgroundColor = "green";
}
ws2.onerror = function(e) {
console.log("test server error");
button.style.backgroundColor = "red";
}
ws2.onclose = function(e) {
console.log("test server close");
button.style.backgroundColor = "gray";
}
}
function connectToTestInsecure(event){
let ws3 = new WebSocket("ws://server1.bayadic.com/wss");
let button = event.target;
ws3.onopen = function(e) {
console.log("insecure server opened");
button.style.backgroundColor = "green";
}
ws3.onerror = function(e) {
console.log("insecure server error");
button.style.backgroundColor = "red";
}
ws3.onclose = function(e) {
console.log("insecure server close");
button.style.backgroundColor = "gray";
}
}
function connectToTestPort555(event){
let ws4 = new WebSocket("ws://46.101.116.181:5555");
let button = event.target;
ws4.onopen = function(e) {
console.log("port 5555 server opened");
button.style.backgroundColor = "green";
}
ws4.onerror = function(e) {
console.log("port 5555 server error");
button.style.backgroundColor = "red";
}
ws4.onclose = function(e) {
button.style.backgroundColor = "gray";
console.log("port 5555 server close");
}
}
document.getElementById('originalBtn').click();
document.getElementById('insecureBtn').click();
document.getElementById('directIpBtn').click();
document.getElementById('testServerBtn').click();