-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrenderer.js
184 lines (140 loc) · 4.26 KB
/
renderer.js
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// All of the Node.js APIs are available in this process.
function initPlayer(port){
var WSAvcPlayer = require('./vendor');
var canvas = document.createElement("canvas");
canvas.id = 'device';
document.body.appendChild(canvas);
// Create h264 player
var uri = "ws://127.0.0.1:" +port + '/';
var wsavc = new WSAvcPlayer(canvas, "webgl", 1, 35);
wsavc.connect(uri);
setTimeout(function(){
wsavc.playStream();
}, 100);
//for button callbacks
window.wsavc = wsavc;
initListener();
}
var http = require('http');
var express = require('express');
var AndroidRelay = require('./android');
var app = express();
//public website
var server = http.createServer(app);
var source = {
width : 1085,
height : 1920
};
var feed = new AndroidRelay(server, source);
server.listen(0, function () {
const port = server.address().port;
initPlayer(port);
});
function initListener(){
var adb = require('adbkit')
var client = adb.createClient();
var clientWidth =100;
var clientHeight =100;
var video = document.querySelector('#device');
var files = {};
var videoDatas = {};
client.listDevices()
.then(function(devices) {
const firstDevices = devices[0];
client.openMonkey(firstDevices.id, function(err, monkey){
monkey.getDisplayWidth(function(err, width) {
monkey.getDisplayHeight(function(err, height) {
clientWidth = +width;
clientHeight = +height;
console.log('Display size is %dx%d', +width, +height, err, width);
});
});
video.ondblclick = function(event){
monkey.multi()
.touchDown(10, 1000)
.sleep(5)
.touchMove(20, 1000)
.sleep(5)
.touchMove(30, 1000)
.sleep(5)
.touchMove(40, 1000)
.sleep(5)
.touchMove(50, 1000)
.sleep(5)
.touchMove(600, 1000)
.sleep(5)
.touchUp(100, 1000)
.sleep(5)
.execute(function(err) {
});
};
var down = false;
var move = 0;
video.onmousedown = function(event){
var pos = eventToPosition(event);
monkey.touchDown(pos.X, pos.Y, nop);
down = true;
move=0;
}
video.onmouseup = function(event){
var pos = eventToPosition(event);
monkey.touchUp(pos.X, pos.Y, nop);
down = false;
}
video.onmousemove = function(event){
if(down){
move++;
if(move%10===0){
var pos = eventToPosition(event);
console.log('mooove');
monkey.touchMove(pos.X, pos.Y, nop);
}
}
}
document.onkeyup = function(event){
if(event.key === 'Enter'){
monkey.press(23, nop)
} else if(event.key === 'Shift'){
monkey.press(59, nop)
} else if(event.key === 'Meta'){
//
} else if(event.key !== 'Backspace'){
monkey.type(event.key, nop);
}else{
monkey.press(67, nop)
}
}
video.onclick = function(event){
var pos = eventToPosition(event);
monkey.tap(pos.X, pos.Y, function(err){
//console.log('touched', err)
// setTimeout(function(){ loadImage(firstDevices.id)} , 150);
})
};
console.log('export buttonMenu');
EXPORT.buttonMenu = function(){
monkey.press(1, nop)
}
EXPORT.buttonHome = function(){
monkey.press(3, nop)
}
EXPORT.buttonBack = function(){
monkey.press(4, nop)
}
})
function eventToPosition(event){
var videoWidth = video.getBoundingClientRect().width ;
var videoHeight = video.getBoundingClientRect().height ;
console.log('event X' , event.offsetX, clientWidth, video.width, Math.floor( event.offsetX * clientWidth / video.width) ,event.offsetY , Math.floor( event.offsetY * clientHeight / video.height));
return {
X : Math.floor( event.offsetX * clientWidth / videoWidth),
Y : Math.floor( event.offsetY * clientHeight / videoHeight)
}
}
function nop(){}
})
};
var EXPORT = {};
module.exports = EXPORT;