Fixed fortunes

This commit is contained in:
Neale Pickett 2022-06-06 10:55:11 -06:00
parent 314994adcd
commit b910676539
6 changed files with 73 additions and 25 deletions

View File

@ -3,7 +3,6 @@ package main
import ( import (
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"fmt"
"time" "time"
) )

View File

@ -72,7 +72,7 @@
<div class="level-right"> <div class="level-right">
<div class="level-item"> <div class="level-item">
<!-- This appears as a little light that turns on when someone's sending --> <!-- This appears as a little light that turns on when someone's sending -->
<span class="tag" class="recv-lamp"> <span class="tag recv-lamp">
<output class="has-text-info" id="note"></output> <output class="has-text-info" id="note"></output>
<i class="mdi mdi-volume-off" id="muted"></i> <i class="mdi mdi-volume-off" id="muted"></i>
</span> </span>

View File

@ -137,6 +137,10 @@ class Sample {
* A (mostly) virtual class defining a buzzer. * A (mostly) virtual class defining a buzzer.
*/ */
class Buzzer { class Buzzer {
constructor() {
this.connected = true
}
/** /**
* Signal an error * Signal an error
*/ */
@ -175,6 +179,15 @@ class Buzzer {
this.Buzz(tx, when) this.Buzz(tx, when)
this.Silence(tx, when + duration) this.Silence(tx, when + duration)
} }
/**
* Set the "connectedness" indicator.
*
* @param {boolean} connected True if connected
*/
SetConnected(connected) {
this.connected = connected
}
} }
class AudioBuzzer extends Buzzer { class AudioBuzzer extends Buzzer {
@ -297,6 +310,17 @@ class LampBuzzer extends Buzzer {
ms, ms,
) )
} }
SetConnected(connected) {
console.log(connected)
for (let e of this.elements) {
if (connected) {
e.classList.add("connected")
} else {
e.classList.remove("connected")
}
}
}
} }
class MIDIBuzzer extends Buzzer { class MIDIBuzzer extends Buzzer {
@ -415,7 +439,7 @@ class Collection {
* *
* @param tx True if transmitting * @param tx True if transmitting
*/ */
Silence(tx=False) { Silence(tx=false) {
for (let b of this.collection) { for (let b of this.collection) {
b.Silence(tx) b.Silence(tx)
} }
@ -433,6 +457,19 @@ class Collection {
b.BuzzDuration(tx, when, duration) b.BuzzDuration(tx, when, duration)
} }
} }
/**
* Update the "connected" status display.
*
* For example, turn the receive light to black if the repeater is not connected.
*
* @param {boolean} connected True if we are "connected"
*/
SetConnected(connected) {
for (let b of this.collection) {
b.SetConnected(connected)
}
}
} }
export {AudioReady, Collection} export {AudioReady, Collection}

View File

@ -30,6 +30,7 @@ export class Vail {
this.lagDurations = [] this.lagDurations = []
this.sent = [] this.sent = []
this.wantConnected = true this.wantConnected = true
this.connected = false
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")
@ -43,11 +44,19 @@ export class Vail {
if (!this.wantConnected) { if (!this.wantConnected) {
return return
} }
this.rx(0, 0, {connected: false})
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, ["json.vail.woozle.org"]) this.socket = new WebSocket(this.wsUrl, ["json.vail.woozle.org"])
this.socket.addEventListener("message", e => this.wsMessage(e)) this.socket.addEventListener("message", e => this.wsMessage(e))
this.socket.addEventListener( this.socket.addEventListener(
"open",
msg => {
this.connected = true
this.rx(0, 0, {connected: true})
}
)
this.socket.addEventListener(
"close", "close",
msg => { msg => {
console.error("Repeater connection dropped:", msg.reason) console.error("Repeater connection dropped:", msg.reason)
@ -71,6 +80,7 @@ export class Vail {
averageLag: this.lagDurations.reduce((a,b) => (a+b), 0) / this.lagDurations.length, averageLag: this.lagDurations.reduce((a,b) => (a+b), 0) / this.lagDurations.length,
clockOffset: this.clockOffset, clockOffset: this.clockOffset,
clients: msg.Clients, clients: msg.Clients,
connected: this.connected,
} }
console.log(msg) console.log(msg)
if (typeof(msg) == "string") { if (typeof(msg) == "string") {
@ -152,13 +162,14 @@ export class Vail {
} }
export class Null { export class Null {
constructor(rx) { constructor(rx, interval=3*Second) {
this.rx = rx this.rx = rx
this.interval = setInterval(() => this.pulse(), 3 * Second) this.interval = setInterval(() => this.pulse(), interval)
this.pulse()
} }
pulse() { pulse() {
this.rx(0, 0, {note: "local"}) this.rx(0, 0, {note: "local", connected: false})
} }
Transmit(time, duration, squelch=true) { Transmit(time, duration, squelch=true) {
@ -169,38 +180,32 @@ export class Null {
} }
} }
export class Echo { export class Echo extends Null {
constructor(rx, delay=0) { constructor(rx, delay=0) {
this.rx = rx super(rx)
this.delay = delay this.delay = delay
this.Transmit(0, 0)
} }
Transmit(time, duration, squelch=true) { Transmit(time, duration, squelch=true) {
this.rx(time + this.delay, duration, {note: "local"}) this.rx(time + this.delay, duration, {note: "local"})
} }
Close() {
}
} }
export class Fortune { export class Fortune extends Null {
/** /**
* *
* @param rx Receive callback * @param rx Receive callback
* @param {Keyer} keyer Keyer object * @param {Keyer} keyer Keyer object
*/ */
constructor(rx, keyer) { constructor(rx, keyer) {
this.rx = rx super(rx, 1*Minute)
this.keyer = keyer this.keyer = keyer
this.interval = setInterval(() => this.pulse(), 1 * Minute)
this.pulse() this.pulse()
} }
pulse() { pulse() {
this.rx(0, 0, {note: "local"}) super.pulse()
if (this.keyer.Busy()) { if (!this.keyer || this.keyer.Busy()) {
return return
} }
@ -208,12 +213,8 @@ export class Fortune {
this.keyer.EnqueueAsciiString(`${fortune} \x04 `) this.keyer.EnqueueAsciiString(`${fortune} \x04 `)
} }
Transmit(time, duration, squelch=true) {
// Do nothing.
}
Close() { Close() {
this.keyer.Flush() this.keyer.Flush()
clearInterval(this.interval) super.Close()
} }
} }

View File

@ -16,7 +16,15 @@
-webkit-user-select: none; /* 2022-04-26 Safari still needs this */ -webkit-user-select: none; /* 2022-04-26 Safari still needs this */
} }
.recv-lamp.rx { .tag.recv-lamp {
background-color: #444;
color: white;
}
.tag.recv-lamp.connected {
background-color: #fec;
}
.tag.recv-lamp.rx,
.tag.recv-lamp.connected.rx {
background-color: orange; background-color: orange;
} }

View File

@ -375,6 +375,9 @@ class VailClient {
let longestRxDuration = this.rxDurations.reduce((a,b) => Math.max(a,b)) let longestRxDuration = this.rxDurations.reduce((a,b) => Math.max(a,b))
let suggestedDelay = ((averageLag + longestRxDuration) * 1.2).toFixed(0) let suggestedDelay = ((averageLag + longestRxDuration) * 1.2).toFixed(0)
if (stats.connected !== undefined) {
this.outputs.SetConnected(stats.connected)
}
this.updateReading("#note", stats.note || "☁") this.updateReading("#note", stats.note || "☁")
this.updateReading("#lag-value", averageLag) this.updateReading("#lag-value", averageLag)
this.updateReading("#longest-rx-value", longestRxDuration) this.updateReading("#longest-rx-value", longestRxDuration)