Compare commits
2 Commits
608d780db1
...
6779f87be3
Author | SHA1 | Date | |
---|---|---|---|
|
6779f87be3 | ||
|
718bba4702 |
42
Client.md
42
Client.md
@ -7,12 +7,20 @@ When GoSmartKeyboard is started in client mode, it does the following:
|
|||||||
3. Connect to the server.
|
3. Connect to the server.
|
||||||
4 Send the auth token 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.
|
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
|
``` go
|
||||||
--- handle client command
|
--- handle client command
|
||||||
|
|
||||||
if len(os.Args) > 1 && os.Args[1] == "connect" {
|
if len(os.Args) > 1 && os.Args[1] == "connect" {
|
||||||
@{start client}
|
@{get client fifo input file from environment}
|
||||||
|
@{setup client}
|
||||||
|
if clientFifioInputFileExists {
|
||||||
|
@{start client with fifo}
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
@{start client with stdin}
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,7 +34,7 @@ The base64 authentication token is loaded from the environment variable `KEYBOAR
|
|||||||
|
|
||||||
``` go
|
``` go
|
||||||
|
|
||||||
--- start client
|
--- setup client
|
||||||
|
|
||||||
@{load connection URL from second CLI argument}
|
@{load connection URL from second CLI argument}
|
||||||
@{get authTokenInput from environment}
|
@{get authTokenInput from environment}
|
||||||
@ -80,14 +88,40 @@ if !strings.HasPrefix(connectionURL, "ws://") && !strings.HasPrefix(connectionUR
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Sending keys
|
## 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
|
||||||
|
|
||||||
|
|
||||||
We read keys from stdin and send them to the server until we get EOF
|
We read keys from stdin and send them to the server until we get EOF
|
||||||
|
|
||||||
``` go
|
``` go
|
||||||
|
|
||||||
--- start client +=
|
--- start client with stdin
|
||||||
|
|
||||||
reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
for {
|
for {
|
||||||
|
@ -24,6 +24,14 @@ 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
|
## HTTP Bind Settings
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,6 +88,7 @@ Then we can start the web server and listen for websocket connections.
|
|||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
@{gorilla/websocket import string}
|
@{gorilla/websocket import string}
|
||||||
"keyboard.voidnet.tech/server"
|
"keyboard.voidnet.tech/server"
|
||||||
|
@ -62,6 +62,7 @@ import(
|
|||||||
"os"
|
"os"
|
||||||
"net/http"
|
"net/http"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"log"
|
"log"
|
||||||
"keyboard.voidnet.tech/auth"
|
"keyboard.voidnet.tech/auth"
|
||||||
@{gorilla/websocket import string}
|
@{gorilla/websocket import string}
|
||||||
|
12
Streaming.md
12
Streaming.md
@ -31,7 +31,7 @@ func clientConnected(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
c.WriteMessage(websocket.TextMessage, []byte("authenticated"))
|
c.WriteMessage(websocket.TextMessage, []byte("authenticated"))
|
||||||
|
|
||||||
|
var parts []string
|
||||||
for {
|
for {
|
||||||
time.Sleep(25 * time.Millisecond)
|
time.Sleep(25 * time.Millisecond)
|
||||||
_, message, err := c.ReadMessage()
|
_, message, err := c.ReadMessage()
|
||||||
@ -44,10 +44,18 @@ func clientConnected(w http.ResponseWriter, r *http.Request) {
|
|||||||
if message_string == "" {
|
if message_string == "" {
|
||||||
message_string = "\n"
|
message_string = "\n"
|
||||||
}
|
}
|
||||||
err = keyboard.Type(message_string)
|
|
||||||
|
parts = strings.Split(message_string, "\n")
|
||||||
|
|
||||||
|
for _, part := range parts {
|
||||||
|
err = keyboard.Type(part)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("type:", err)
|
log.Println("type:", err)
|
||||||
}
|
}
|
||||||
|
if len(parts) > 1 {
|
||||||
|
keyboard.Enter()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user