mirror of https://github.com/nealey/vail.git
Fix socket reopen when changing repeaters
This may be what I was seeing in #28. I also added the socket name to debug messages on tx and rx, to make it easier to track down where you're actually connected.
This commit is contained in:
parent
a74b40935b
commit
d47378ba37
|
@ -13,6 +13,9 @@ export class HTML extends Input{
|
||||||
|
|
||||||
// Listen to HTML buttons
|
// Listen to HTML buttons
|
||||||
for (let e of document.querySelectorAll("button.key")) {
|
for (let e of document.querySelectorAll("button.key")) {
|
||||||
|
// Chrome is going to suggest you use passive events here.
|
||||||
|
// I tried that and it screws up Safari mobile,
|
||||||
|
// making it so that hitting the button selects text on the page.
|
||||||
e.addEventListener("contextmenu", e => { e.preventDefault(); return false }, {passive: false})
|
e.addEventListener("contextmenu", e => { e.preventDefault(); return false }, {passive: false})
|
||||||
e.addEventListener("touchstart", e => this.keyButton(e), {passive: false})
|
e.addEventListener("touchstart", e => this.keyButton(e), {passive: false})
|
||||||
e.addEventListener("touchend", e => this.keyButton(e), {passive: false})
|
e.addEventListener("touchend", e => this.keyButton(e), {passive: false})
|
||||||
|
|
|
@ -10,6 +10,7 @@ export class Vail {
|
||||||
this.name = name
|
this.name = name
|
||||||
this.lagDurations = []
|
this.lagDurations = []
|
||||||
this.sent = []
|
this.sent = []
|
||||||
|
this.wantConnected = true
|
||||||
|
|
||||||
this.wsUrl = new URL("chat", window.location)
|
this.wsUrl = new URL("chat", window.location)
|
||||||
this.wsUrl.protocol = this.wsUrl.protocol.replace("http", "ws")
|
this.wsUrl.protocol = this.wsUrl.protocol.replace("http", "ws")
|
||||||
|
@ -20,6 +21,9 @@ export class Vail {
|
||||||
}
|
}
|
||||||
|
|
||||||
reopen() {
|
reopen() {
|
||||||
|
if (!this.wantConnected) {
|
||||||
|
return
|
||||||
|
}
|
||||||
console.info("Attempting to reconnect", this.wsUrl.href)
|
console.info("Attempting to reconnect", this.wsUrl.href)
|
||||||
this.clockOffset = 0
|
this.clockOffset = 0
|
||||||
this.socket = new WebSocket(this.wsUrl)
|
this.socket = new WebSocket(this.wsUrl)
|
||||||
|
@ -67,7 +71,7 @@ export class Vail {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.debug("Vail.wsMessage()", msg)
|
console.debug("Vail.wsMessage()", this.socket, msg)
|
||||||
|
|
||||||
// The very first packet is the server telling us the current time
|
// The very first packet is the server telling us the current time
|
||||||
if (durations.length == 0) {
|
if (durations.length == 0) {
|
||||||
|
@ -108,7 +112,7 @@ export class Vail {
|
||||||
console.error("Not connected, dropping", jmsg)
|
console.error("Not connected, dropping", jmsg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.debug("Transmit", msg)
|
console.debug("Transmit", this.socket, msg)
|
||||||
this.socket.send(jmsg)
|
this.socket.send(jmsg)
|
||||||
if (squelch) {
|
if (squelch) {
|
||||||
this.sent.push(jmsg)
|
this.sent.push(jmsg)
|
||||||
|
@ -116,6 +120,7 @@ export class Vail {
|
||||||
}
|
}
|
||||||
|
|
||||||
Close() {
|
Close() {
|
||||||
|
this.wantConnected = false
|
||||||
this.socket.close()
|
this.socket.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,9 @@ const Second = 1000 * Millisecond
|
||||||
* @param {string} msg Message to display
|
* @param {string} msg Message to display
|
||||||
*/
|
*/
|
||||||
function toast(msg) {
|
function toast(msg) {
|
||||||
|
console.info(msg)
|
||||||
let el = document.querySelector("#snackbar")
|
let el = document.querySelector("#snackbar")
|
||||||
if (!el || !el.MaterialSnackbar) {
|
if (!el || !el.MaterialSnackbar) {
|
||||||
console.info(msg)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
el.MaterialSnackbar.showSnackbar({
|
el.MaterialSnackbar.showSnackbar({
|
||||||
|
|
Loading…
Reference in New Issue