1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-01 02:20:45 +00:00
falk-werner_webfuse-provider/example/daemon/www/js/connection_view.js

44 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-02-20 19:23:56 +00:00
export class ConnectionView {
2019-02-21 23:35:59 +00:00
constructor(client) {
this._client = client;
this._client.onopen = () => { this._onConnectionOpened(); };
this._client.onclose = () => { this._onConnectionClosed(); };
2019-01-28 21:08:37 +00:00
2019-02-13 20:09:43 +00:00
this.element = document.createElement("div");
2019-01-28 21:08:37 +00:00
const urlLabel = document.createElement("span");
2019-02-13 20:09:43 +00:00
urlLabel.textContent = "URL:";
2019-01-28 21:08:37 +00:00
this.element.appendChild(urlLabel);
2019-02-13 20:09:43 +00:00
this.urlTextbox = document.createElement("input");
this.urlTextbox.type = "text";
2019-01-28 21:08:37 +00:00
this.urlTextbox.value = window.location.href.replace(/^http/, "ws");
this.element.appendChild(this.urlTextbox);
2019-02-13 20:09:43 +00:00
this.connectButton = document.createElement("input");
this.connectButton.type = "button";
this.connectButton.value = "connect";
this.connectButton.addEventListener("click", () => { this._onConnectButtonClicked(); });
2019-01-28 21:08:37 +00:00
this.element.appendChild(this.connectButton);
}
_onConnectButtonClicked() {
if (!this._client.isConnected()) {
2019-01-28 21:08:37 +00:00
let url = this.urlTextbox.value;
this._client.connectTo(url);
2019-01-28 21:08:37 +00:00
}
else {
this._client.disconnect();
2019-01-28 21:08:37 +00:00
}
}
_onConnectionOpened() {
2019-02-13 20:09:43 +00:00
this.connectButton.value = "disconnect";
2019-01-28 21:08:37 +00:00
}
_onConnectionClosed() {
2019-02-13 20:09:43 +00:00
this.connectButton.value = "connect";
2019-01-28 21:08:37 +00:00
}
}