Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
add vendor, finish part of /whatsinput
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Apr 3, 2018
1 parent b3bad94 commit 986ab0e
Show file tree
Hide file tree
Showing 869 changed files with 241,168 additions and 3 deletions.
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ $ curl -XPUT 10.0.0.1:7912/minicap
$ curl -XPUT 10.0.0.1:7912/minitouch
```

## 视频录制
## 视频录制(不推荐用)
开始录制

```bash
Expand Down Expand Up @@ -219,6 +219,41 @@ Websocket连接 `$DEVICE_URL/minitouch`, 一行行的按照JSON的格式写入
{"operation": "c"}
```

## Whatsinput交互协议
感谢 项目<https://github.com/willerce/WhatsInput>

Websocket连接 `$DEVICE_URL/whatsinput`, 接收JSON格式

### 手机 --> 前端
- 设置文本框内容

```json
{"text":"hello world", "type":"InputStart"}
```

会自动清除原有的内容,替换为新的内容

- 结束编辑

```json
{"type": "InputFinish"}
```

- KeyCode的输入

```json
{"type": "InputKey", "code": 66}
```

[KeyCode参考列表](https://testerhome.com/topics/1386)

### 前端 --> 手机
- 编辑框内容变化

```json
{"type": "InputChange", "text": "some text"}
```

# TODO
1. 目前安全性还是个问题,以后再想办法改善
2. 补全接口文档
Expand Down
2 changes: 1 addition & 1 deletion install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ REM adb install app-debug-androidTest.apk
adb push atx-agent /data/local/tmp
adb shell chmod 777 /data/local/tmp/atx-agent
adb shell /data/local/tmp/atx-agent -stop
REM adb shell /data/local/tmp/atx-agent -d -t 10.240.187.224:8000 -nouia
adb shell /data/local/tmp/atx-agent -d -t 10.240.171.86:8000 -nouia
REM adb shell /data/local/tmp/atx-agent -d -t 10.246.46.160:8200 -nouia
REM pause
38 changes: 37 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"context"
"encoding/base64"
"encoding/binary"
"encoding/json"
"flag"
Expand Down Expand Up @@ -451,6 +452,9 @@ func ServeHTTP(lis net.Listener, tunnel *TunnelProxy) error {
renderHTML(w, "remote.html")
})

const whatsInputFinishedMagic = "inputFinished--201804031742"
var whatsInputChannel = make(chan string, 0)

// Send input to device
// Highly affected by project https://github.com/willerce/WhatsInput
// Also thanks to https://github.com/senzhk/ADBKeyBoard
Expand All @@ -460,14 +464,46 @@ func ServeHTTP(lis net.Listener, tunnel *TunnelProxy) error {
Text string `json:"text,omitempty"`
Code int `json:"code,omitempty"`
}
quit := make(chan bool, 1)
go func() {
for {
select {
case msg := <-whatsInputChannel:
log.Println("Receive msg", msg)
case <-quit:
return
}
}
}()
for {
if err := ws.ReadJSON(&v); err != nil {
quit <- true
log.Println(err)
break
}
log.Println(v.Type, v.Text, v.Code)
switch v.Type {
case "InputStart":
if v.Text == "" {
runShell("am", "broadcast", "-a", "ADB_CLEAR_TEXT")
} else {
base64Str := base64.StdEncoding.EncodeToString([]byte(v.Text))
runShell("am", "broadcast", "-a", "ADB_SET_TEXT", "--es", "text", base64Str)
}
case "InputKey":
runShell("input", "keyevent", "KEYCODE_ENTER") // HOTFIX(ssx): need fix later
// runShell("am", "broadcast", "-a", "ADB_INPUT_KEYCODE", "--ei", "code", strconv.Itoa(v.Code))
}
}
}))
})).Methods("GET")

m.HandleFunc("/whatsinput", func(w http.ResponseWriter, r *http.Request) {
data, _ := ioutil.ReadAll(r.Body)
select {
case whatsInputChannel <- string(data):
case <-time.After(1 * time.Second):
}
}).Methods("POST")

m.HandleFunc("/pidof/{pkgname}", func(w http.ResponseWriter, r *http.Request) {
pkgname := mux.Vars(r)["pkgname"]
Expand Down
22 changes: 22 additions & 0 deletions vendor/github.com/DeanThompson/syncmap/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions vendor/github.com/DeanThompson/syncmap/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 986ab0e

Please sign in to comment.