You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
falk-werner_webfuse/example/daemon/www/js/connection_view.js

43 lines
1.4 KiB

export class ConnectionView {
6 years ago
constructor(connection) {
this.connection = connection;
this.connection.onclose = () => { this.onConnectionClosed(); };
this.connection.onopen = () => { this.onConnectionOpened(); };
this.element = document.createElement("div");
6 years ago
let urlLabel = document.createElement("span");
urlLabel.textContent = "URL:";
6 years ago
this.element.appendChild(urlLabel);
this.urlTextbox = document.createElement("input");
this.urlTextbox.type = "text";
6 years ago
this.urlTextbox.value = window.location.href.replace(/^http/, "ws");
this.element.appendChild(this.urlTextbox);
this.connectButton = document.createElement("input");
this.connectButton.type = "button";
this.connectButton.value = "connect";
this.connectButton.addEventListener("click", () => { this.onConnectButtonClicked(); });
6 years ago
this.element.appendChild(this.connectButton);
}
onConnectButtonClicked() {
if (!this.connection.isConnected) {
let url = this.urlTextbox.value;
this.connection.connectTo(url);
}
else {
this.connection.close();
}
}
onConnectionOpened() {
this.connectButton.value = "disconnect";
6 years ago
}
onConnectionClosed() {
this.connectButton.value = "connect";
6 years ago
}
}