-
Notifications
You must be signed in to change notification settings - Fork 33
/
wda.go
83 lines (70 loc) · 2.13 KB
/
wda.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"fmt"
log "github.com/sirupsen/logrus"
)
type WDA struct {
udid string
devTracker *DeviceTracker
dev *Device
config *Config
base string
startChan chan int
wdaPort int
}
func NewWDA( config *Config, devTracker *DeviceTracker, dev *Device ) (*WDA) {
self := NewWDANoStart( config, devTracker, dev )
fmt.Printf("WDA Method:%s\n", dev.devConfig.wdaMethod )
if dev.devConfig.wdaMethod == "" {
return self
}
//if config.wdaMethod != "manual" {
self.start( nil )
//} else {
// self.forward( func( x int, stopChan chan bool ) {
// } )
//}
return self
}
func NewWDANoStart( config *Config, devTracker *DeviceTracker, dev *Device ) (*WDA) {
self := WDA{
udid: dev.udid,
wdaPort: dev.wdaPort,
devTracker: devTracker,
dev: dev,
config: config,
base: fmt.Sprintf("http://127.0.0.1:%d",dev.wdaPort),
}
return &self
}
func (self *WDA) forward( onready func( int, chan bool ) ) {
pairs := []TunPair{
TunPair{ from: self.wdaPort, to: 8100 },
}
stopChan := make( chan bool )
self.dev.bridge.tunnel( pairs, func() {
if onready != nil {
onready( 0, stopChan )
}
} )
}
func (self *WDA) start( started func( int, chan bool ) ) {
self.forward( func( x int, stopChan chan bool ) {
self.dev.bridge.wda(
func() { // onStart
log.WithFields( log.Fields{
"type": "wda_start",
"udid": censorUuid(self.udid),
"port": self.wdaPort,
} ).Info("[WDA] successfully started")
//if self.startChan != nil {
// self.startChan <- 0
//}
self.dev.EventCh <- DevEvent{ action: DEV_WDA_START }
},
func(interface{}) { // onStop
self.dev.EventCh <- DevEvent{ action: DEV_WDA_STOP }
},
)
} )
}