remote keyboard improvements + docs
This commit is contained in:
parent
2991f0b73e
commit
e3903e3beb
3 changed files with 29 additions and 36 deletions
15
index.html
15
index.html
File diff suppressed because one or more lines are too long
|
|
@ -1 +1 @@
|
|||
Subproject commit 16b8ab71224148b3ad1c71d6530d4ae653816958
|
||||
Subproject commit aa5e6849cb93bdfd8391927c776f0b2c1b8d6bf3
|
||||
48
xrsh
48
xrsh
|
|
@ -1,52 +1,42 @@
|
|||
#!/bin/sh
|
||||
trap "stty sane; trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
|
||||
PORT=9090
|
||||
PROCFILE=/tmp/.xrsh
|
||||
|
||||
usage(){ echo "Usage: xrsh [--keyboard]"; exit; }
|
||||
usage(){ echo "Usage: xrsh [--keyboard] [--kill]"; exit; }
|
||||
|
||||
assert_cmds(){
|
||||
for cmd in $1; do
|
||||
command -v $cmd &>dev/null || { echo "error: please install $cmd (not found)"; exit 1; }
|
||||
command -v $cmd &>/dev/null || { echo "error: please install $cmd (not found)"; exit 1; }
|
||||
done
|
||||
}
|
||||
|
||||
showip(){
|
||||
{ # naive way of getting network ip
|
||||
command -v ip &>/dev/null && ip addr show
|
||||
command -v ifconfig &>/dev/null && ifconfig
|
||||
} | grep 'inet ' | grep -v ' 127' | awk '! /addr:/ { gsub(/\/.*/,"",$2); if( !SEEN[$2] ) print $2; SEEN[$2]=1 }'
|
||||
|
||||
}
|
||||
|
||||
keyboard(){
|
||||
assert_cmds websocat foobar
|
||||
echo '
|
||||
<h1>keyboard connector</h1>
|
||||
|
||||
<pre>
|
||||
connect to ws://127.0.0.1:'$PORT'
|
||||
</pre>
|
||||
|
||||
<script>
|
||||
var ws = new WebSocket("ws://127.0.0.1:'$PORT'/");
|
||||
|
||||
ws.onmessage = function(event) {
|
||||
if( !event.data ) return
|
||||
event.data.arrayBuffer().then( (buf) => {
|
||||
decoder = new TextDecoder("utf-8")
|
||||
c = decoder.decode( new Uint8Array(buf) )
|
||||
console.log(c)
|
||||
})
|
||||
};
|
||||
</script>
|
||||
' > /tmp/index.html
|
||||
|
||||
assert_cmds websocat pkill
|
||||
trap "stty sane; trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT # cleanup processes when exit
|
||||
echo $$ > $PROCFILE
|
||||
echo ""
|
||||
echo " 1. type 'k' (remote keyboard) in xrsh"
|
||||
echo " 2. enter ipaddress: $(showip)"
|
||||
echo ""
|
||||
echo "warn: CTRL-C is forwarded too"
|
||||
echo "warn: to exit this app run: $0 --kill"
|
||||
echo "warn: this terminal is now in raw sendmode, expect weird characters!"
|
||||
stty raw
|
||||
websocat -E -b -s $PORT -F /:text/html:/tmp/index.html
|
||||
websocat -E -b -s 0.0.0.0:$PORT 2>&1
|
||||
}
|
||||
|
||||
# launch!
|
||||
test -n "$1" || { echo "usage: xrsh [--keyboard] [--kill]"; exit; }
|
||||
case "$*" in
|
||||
-h) usage ;;
|
||||
--kill) pkill -P $(cat $PROCFILE); exit ;;
|
||||
--help) usage ;;
|
||||
--keyboard) keyboard ;;
|
||||
--raw) RAW=1 ;;
|
||||
esac
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue