Ready to beta?

This commit is contained in:
Neale Pickett 2020-04-10 08:27:35 -06:00
parent 2578ee1848
commit 55dbdf8635
3 changed files with 76 additions and 25 deletions

View File

@ -3,9 +3,49 @@
<head> <head>
<title>Vail</title> <title>Vail</title>
<script src="vail.js"></script> <script src="vail.js"></script>
<link rel="stylesheet" href="vail.css">
</head> </head>
<body> <body>
<h1>Vail</h1> <h1>Vail</h1>
<p>
You have to click in the page or press a key or something before you can hear anything.
These are browser rules
that prevent ads from blaring audio at you.
</p>
<p>
Keys you can use:
</p>
<dl>
<dd><code>,</code>, <code>w</code>, left mouse button</dd>
<dt>Short tone</dt>
<dd><code>.</code>, <code>v</code>, right mouse button</dd>
<dt>Long tone</dt>
</dl>
<hr>
<p>
This is a CW repeater,
named after Alfred Vail,
who may or may not have invented what's called "Morse code",
but clearly had some role in it.
</p>
<p>
Just like a radio repeater,
anybody can connect and start transmitting stuff,
and this will broadcast it to everyone connected.
If there's enough interest,
I'll add something like channels.
</p>
<p>
If you need this to work on a cell phone,
let me know and I'll come up with something for you.
</p>
<div id="output"></div> <div id="output"></div>
</body> </body>
</html> </html>

View File

@ -0,0 +1,10 @@
body {
background-color: #ccc;
font-family: sans-serif;
}
code {
background-color: #333;
color: #fff;
padding: 0.1em;
}

View File

@ -3,14 +3,15 @@ var gain = ac.createGain()
gain.connect(ac.destination) gain.connect(ac.destination)
gain.gain.value = 0.1 gain.gain.value = 0.1
var longest = 500 var short = 80
var long = 200
var audioFreq = 660 var audioFreq = 660
var audioFreqMe = audioFreq * 6 / 5 // I think this works out to a minor third var audioFreqMe = audioFreq * 6 / 5 // I think this works out to a minor third
var myosc var myosc
function message(event) { function message(event) {
let duration = Number(event.data) || 0 let duration = Number(event.data) || 0
duration = Math.min(duration, longest) duration = Math.min(duration, long)
let osc = ac.createOscillator() let osc = ac.createOscillator()
osc.connect(gain) osc.connect(gain)
@ -20,37 +21,37 @@ function message(event) {
} }
function key(event) { function key(event) {
if (event.type.endsWith("down")) { let duration = 0
if (! event.repeat) {
window.down = event.timeStamp if ((event.button === 0) || (event.key == ",") || (event.key == "w")) {
} duration = short
if (! myosc) {
myosc = ac.createOscillator()
myosc.connect(gain)
myosc.frequency.value = audioFreqMe
myosc.start(ac.currentTime)
}
} else {
let duration = event.timeStamp - window.down
duration = Math.min(duration, longest)
console.log(event.timeStamp, window.down, duration)
window.socket.send(duration)
if (myosc) {
myosc.stop(ac.currentTime)
myosc = null
}
} }
if ((event.button === 2) || (event.key == ".") || (event.key == "v")) {
duration = long
}
// You don't get to hold the key down yet, sorry
if ((event.repeat) || (duration === 0)) {
return
}
window.socket.send(duration)
myosc = ac.createOscillator()
myosc.connect(gain)
myosc.frequency.value = audioFreqMe
myosc.start(ac.currentTime)
myosc.stop(ac.currentTime + duration * 0.001)
} }
function init() { function init() {
window.socket = new WebSocket("ws://penguin.linux.test:8080/chat") let wsUrl = new URL(window.location)
wsUrl.protocol = "ws:"
wsUrl.pathname += "chat"
window.socket = new WebSocket(wsUrl)
window.socket.addEventListener("message", message) window.socket.addEventListener("message", message)
document.addEventListener("mousedown", e => key(e)) document.addEventListener("mousedown", e => key(e))
document.addEventListener("mouseup", e => key(e))
document.addEventListener("keydown", e => key(e)) document.addEventListener("keydown", e => key(e))
document.addEventListener("keyup", e => key(e))
} }