Compare commits

..

No commits in common. "6779f87be3b76fa0e79eb836377397300c5fcd7e" and "608d780db19f8b25ea66431358b69ec7004be358" have entirely different histories.

5 changed files with 8 additions and 60 deletions

View File

@ -7,20 +7,12 @@ When GoSmartKeyboard is started in client mode, it does the following:
3. Connect to the server.
4 Send the auth token to the server.
5. If the server responds with "authenticated", we start reading keys from stdin and sending them to the server until EOF.
6. If KEYBOARD_FIFO is specified as an environment variable, we read from the path specified there instead as a named pipe.
``` go
--- handle client command
if len(os.Args) > 1 && os.Args[1] == "connect" {
@{get client fifo input file from environment}
@{setup client}
if clientFifioInputFileExists {
@{start client with fifo}
os.Exit(0)
}
@{start client with stdin}
@{start client}
os.Exit(0)
}
@ -34,7 +26,7 @@ The base64 authentication token is loaded from the environment variable `KEYBOAR
``` go
--- setup client
--- start client
@{load connection URL from second CLI argument}
@{get authTokenInput from environment}
@ -88,40 +80,14 @@ if !strings.HasPrefix(connectionURL, "ws://") && !strings.HasPrefix(connectionUR
```
## Sending keys from a named pipe
``` go
--- start client with fifo
for {
input, err := ioutil.ReadFile(clientFifoInputFile)
if err != nil {
log.Fatal(err)
}
if len(input) > 0 {
fmt.Println("send" + strings.Replace(string(input), " ", "space", 10))
err = client.WriteMessage(websocket.TextMessage, input)
if err != nil {
log.Fatal("write:", err)
}
}
}
---
```
## Sending keys from stdin
## Sending keys
We read keys from stdin and send them to the server until we get EOF
``` go
--- start client with stdin
--- start client +=
reader := bufio.NewReader(os.Stdin)
for {

View File

@ -24,14 +24,6 @@ authTokenFile, authTokenFileIsSet := os.LookupEnv("KEYBOARD_AUTH_TOKEN_FILE")
---
## Client fifo
--- get client fifo input file from environment
clientFifoInputFile, clientFifioInputFileExists := os.LookupEnv("KEYBOARD_FIFO")
---
## HTTP Bind Settings

View File

@ -88,7 +88,6 @@ Then we can start the web server and listen for websocket connections.
"io"
"strings"
"bufio"
"io/ioutil"
"log"
@{gorilla/websocket import string}
"keyboard.voidnet.tech/server"

View File

@ -62,7 +62,6 @@ import(
"os"
"net/http"
"fmt"
"strings"
"log"
"keyboard.voidnet.tech/auth"
@{gorilla/websocket import string}

View File

@ -31,7 +31,7 @@ func clientConnected(w http.ResponseWriter, r *http.Request) {
}
c.WriteMessage(websocket.TextMessage, []byte("authenticated"))
var parts []string
for {
time.Sleep(25 * time.Millisecond)
_, message, err := c.ReadMessage()
@ -44,17 +44,9 @@ func clientConnected(w http.ResponseWriter, r *http.Request) {
if message_string == "" {
message_string = "\n"
}
parts = strings.Split(message_string, "\n")
for _, part := range parts {
err = keyboard.Type(part)
if err != nil {
log.Println("type:", err)
}
if len(parts) > 1 {
keyboard.Enter()
}
err = keyboard.Type(message_string)
if err != nil {
log.Println("type:", err)
}
}
}