mirror of https://github.com/nealey/vail.git
Minor cleanups, new API adjustments
This commit is contained in:
parent
2f9e651958
commit
8a82a4dc43
|
@ -26,7 +26,7 @@ const Second = 1000 * Millisecond
|
||||||
*/
|
*/
|
||||||
const OscillatorRampDuration = 5*Millisecond
|
const OscillatorRampDuration = 5*Millisecond
|
||||||
|
|
||||||
|
console.warn("Chrome will now complain about an AudioContext not being allowed to start. This is normal, and there is no way to make Chrome stop complaining about this.")
|
||||||
const BuzzerAudioContext = new AudioContext()
|
const BuzzerAudioContext = new AudioContext()
|
||||||
/**
|
/**
|
||||||
* Compute the special "Audio Context" time
|
* Compute the special "Audio Context" time
|
||||||
|
|
|
@ -13,19 +13,17 @@ 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")) {
|
||||||
e.addEventListener("contextmenu", e => { e.preventDefault(); return false })
|
e.addEventListener("contextmenu", e => { return false }, {passive: true})
|
||||||
e.addEventListener("touchstart", e => this.keyButton(e))
|
e.addEventListener("touchstart", e => this.keyButton(e), {passive: true})
|
||||||
e.addEventListener("touchend", e => this.keyButton(e))
|
e.addEventListener("touchend", e => this.keyButton(e), {passive: true})
|
||||||
e.addEventListener("mousedown", e => this.keyButton(e))
|
e.addEventListener("mousedown", e => this.keyButton(e), {passive: true})
|
||||||
e.addEventListener("mouseup", e => this.keyButton(e))
|
e.addEventListener("mouseup", e => this.keyButton(e), {passive: true})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
keyButton(event) {
|
keyButton(event) {
|
||||||
let begin = event.type.endsWith("down") || event.type.endsWith("start")
|
let begin = event.type.endsWith("down") || event.type.endsWith("start")
|
||||||
|
|
||||||
event.preventDefault()
|
|
||||||
|
|
||||||
if (event.target.id == "dah") {
|
if (event.target.id == "dah") {
|
||||||
this.keyer.Dah(begin)
|
this.keyer.Dah(begin)
|
||||||
} else if ((event.target.id == "dit") && (event.button == 2)) {
|
} else if ((event.target.id == "dit") && (event.button == 2)) {
|
||||||
|
@ -69,7 +67,6 @@ export class Keyboard extends Input{
|
||||||
if (this.ditDown != down) {
|
if (this.ditDown != down) {
|
||||||
this.keyer.Dit(down)
|
this.keyer.Dit(down)
|
||||||
this.ditDown = down
|
this.ditDown = down
|
||||||
event.preventDefault()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
|
@ -82,7 +79,6 @@ export class Keyboard extends Input{
|
||||||
if (this.dahDown != down) {
|
if (this.dahDown != down) {
|
||||||
this.keyer.Dah(down)
|
this.keyer.Dah(down)
|
||||||
this.dahDown = down
|
this.dahDown = down
|
||||||
event.preventDefault()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
|
@ -95,7 +91,6 @@ export class Keyboard extends Input{
|
||||||
if (this.straightDown != down) {
|
if (this.straightDown != down) {
|
||||||
this.keyer.Straight(down)
|
this.keyer.Straight(down)
|
||||||
this.straightDown = down
|
this.straightDown = down
|
||||||
event.preventDefault()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +99,6 @@ export class Keyboard extends Input{
|
||||||
// There is a "left" key, and a "right" key, and the computer decides what those mean.
|
// There is a "left" key, and a "right" key, and the computer decides what those mean.
|
||||||
// Users expect "left" to be a straight key or dit, depending on some screen control.
|
// Users expect "left" to be a straight key or dit, depending on some screen control.
|
||||||
// "right" is always dah.
|
// "right" is always dah.
|
||||||
event.preventDefault()
|
|
||||||
if (this.iambic) {
|
if (this.iambic) {
|
||||||
this.keyer.Dit(down)
|
this.keyer.Dit(down)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -63,15 +63,11 @@ export class Vail {
|
||||||
this.lagDurations.unshift(now - this.clockOffset - beginTxTime - totalDuration)
|
this.lagDurations.unshift(now - this.clockOffset - beginTxTime - totalDuration)
|
||||||
this.lagDurations.splice(20, 2)
|
this.lagDurations.splice(20, 2)
|
||||||
this.rx(0, 0, this.stats())
|
this.rx(0, 0, this.stats())
|
||||||
if (this.name == "debug") {
|
|
||||||
console.debug("Vail.wsMessage() SQUELCH", msg)
|
console.debug("Vail.wsMessage() SQUELCH", msg)
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.name == "debug") {
|
|
||||||
console.debug("Vail.wsMessage()", msg)
|
console.debug("Vail.wsMessage()", 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) {
|
||||||
|
@ -112,6 +108,7 @@ export class Vail {
|
||||||
console.error("Not connected, dropping", jmsg)
|
console.error("Not connected, dropping", jmsg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
console.debug("Transmit", msg)
|
||||||
this.socket.send(jmsg)
|
this.socket.send(jmsg)
|
||||||
if (squelch) {
|
if (squelch) {
|
||||||
this.sent.push(jmsg)
|
this.sent.push(jmsg)
|
||||||
|
|
|
@ -15,7 +15,7 @@ const Second = 1000 * Millisecond
|
||||||
function toast(msg) {
|
function toast(msg) {
|
||||||
let el = document.querySelector("#snackbar")
|
let el = document.querySelector("#snackbar")
|
||||||
if (!el || !el.MaterialSnackbar) {
|
if (!el || !el.MaterialSnackbar) {
|
||||||
console.warn(msg)
|
console.info(msg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
el.MaterialSnackbar.showSnackbar({
|
el.MaterialSnackbar.showSnackbar({
|
||||||
|
@ -32,7 +32,6 @@ class VailClient {
|
||||||
this.clockOffset = null // How badly our clock is off of the server's
|
this.clockOffset = null // How badly our clock is off of the server's
|
||||||
this.rxDelay = 0 * Millisecond // Time to add to incoming timestamps
|
this.rxDelay = 0 * Millisecond // Time to add to incoming timestamps
|
||||||
this.beginTxTime = null // Time when we began transmitting
|
this.beginTxTime = null // Time when we began transmitting
|
||||||
this.debug = localStorage.debug
|
|
||||||
|
|
||||||
// Make helpers
|
// Make helpers
|
||||||
this.lamp = new Buzzer.Lamp()
|
this.lamp = new Buzzer.Lamp()
|
||||||
|
@ -110,6 +109,7 @@ class VailClient {
|
||||||
setTelegraphBuzzer(enable) {
|
setTelegraphBuzzer(enable) {
|
||||||
if (enable) {
|
if (enable) {
|
||||||
this.buzzer = new Buzzer.TelegraphBuzzer()
|
this.buzzer = new Buzzer.TelegraphBuzzer()
|
||||||
|
toast("Telegraphs only make sound when receiving!")
|
||||||
} else {
|
} else {
|
||||||
this.buzzer = new Buzzer.ToneBuzzer()
|
this.buzzer = new Buzzer.ToneBuzzer()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue