-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
93 lines (74 loc) · 2.08 KB
/
index.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
var express = require('express'),
socketIO = require('socket.io'),
http = require('http'),
path = require('path'),
screencast = require('./lib/screencast'),
adb = require('./lib/adb'),
util = require('util'),
input = require('./lib/input'),
androidKey = require('./lib/android-keycode');
var app = express()
var server = http.createServer(app)
var io = socketIO(server)
app.use('/web', express.static(path.join(__dirname, './front')))
var people = 0
var MAX_PEOPLE = 3
io.on('connection', function (socket) {
if (people >= MAX_PEOPLE) {
console.log('max people, can not connect, current: %s', people)
socket.close()
return
}
people++
console.log('connect, current people: %s', people)
if (people == 1) {
screencast.start()
console.log('start screencast')
}
socket.on('disconnect', function () {
people--;
console.log('disconnect, current people: %s', people)
if (people == 0) {
screencast.stop()
console.log('stop screencast')
}
})
// INPUT: tap
socket.on('tap', function (data) {
console.log('tap %j', data)
adb.listDevices().then(function (devices) {
return devices[0].id
}).then(function (id) {
var command = util.format('input tap %s %s', data.x, data.y)
adb.shell(id, command).then(function () {
console.log(command)
})
})
})
// INPUT: swipe
socket.on('swipe', function (data) {
console.log('swipe %j', data)
adb.listDevices().then(function (devices) {
return devices[0].id
}).then(function (id) {
var command = util.format('input swipe %s %s %s %s', data.from.x, data.from.y, data.to.x, data.to.y)
adb.shell(id, command).then(function () {
console.log(command)
})
})
})
// INPUT: key
socket.on('key', function (data) {
input.sendevent(androidKey[data.key]).then(function () {
// input.sendevent(45, 0)
})
// var command = util.format('')
// adb.shell(id, ['input keyevent 115', 'input keyevent 52']).then(function () {
// console.log(command)
// })
})
})
screencast.on('data', function (data) {
io.emit('data', data)
})
server.listen(41000)