mirror of https://github.com/nealey/vail.git
Ready to beta?
This commit is contained in:
parent
2578ee1848
commit
55dbdf8635
|
@ -3,9 +3,49 @@
|
|||
<head>
|
||||
<title>Vail</title>
|
||||
<script src="vail.js"></script>
|
||||
<link rel="stylesheet" href="vail.css">
|
||||
</head>
|
||||
<body>
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,10 @@
|
|||
body {
|
||||
background-color: #ccc;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
code {
|
||||
background-color: #333;
|
||||
color: #fff;
|
||||
padding: 0.1em;
|
||||
}
|
|
@ -3,14 +3,15 @@ var gain = ac.createGain()
|
|||
gain.connect(ac.destination)
|
||||
gain.gain.value = 0.1
|
||||
|
||||
var longest = 500
|
||||
var short = 80
|
||||
var long = 200
|
||||
var audioFreq = 660
|
||||
var audioFreqMe = audioFreq * 6 / 5 // I think this works out to a minor third
|
||||
var myosc
|
||||
|
||||
function message(event) {
|
||||
let duration = Number(event.data) || 0
|
||||
duration = Math.min(duration, longest)
|
||||
duration = Math.min(duration, long)
|
||||
|
||||
let osc = ac.createOscillator()
|
||||
osc.connect(gain)
|
||||
|
@ -20,37 +21,37 @@ function message(event) {
|
|||
}
|
||||
|
||||
function key(event) {
|
||||
if (event.type.endsWith("down")) {
|
||||
if (! event.repeat) {
|
||||
window.down = event.timeStamp
|
||||
}
|
||||
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)
|
||||
let duration = 0
|
||||
|
||||
if (myosc) {
|
||||
myosc.stop(ac.currentTime)
|
||||
myosc = null
|
||||
}
|
||||
if ((event.button === 0) || (event.key == ",") || (event.key == "w")) {
|
||||
duration = short
|
||||
}
|
||||
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() {
|
||||
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)
|
||||
|
||||
document.addEventListener("mousedown", e => key(e))
|
||||
document.addEventListener("mouseup", e => key(e))
|
||||
document.addEventListener("keydown", e => key(e))
|
||||
document.addEventListener("keyup", e => key(e))
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue