-
Notifications
You must be signed in to change notification settings - Fork 13
/
mirror.js
52 lines (40 loc) · 1.22 KB
/
mirror.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
/*
* Android Mirror - v0.1
*
*/
process.on('uncaughtException', function(err) {
console.log('Caught exception: ' + err);
console.log(err.stack);
});
const express = require('express');
const execSync = require('child_process').execSync;
const mirrorTcpStream = require('./lib/mirror-tcp-stream');
const app = express();
const wss = require('express-ws')(app);
app.use(express.static(__dirname + '/public'));
app.use(function (err, req, res, next) {
console.error(err);
next(err);
})
app.ws('/mobile', (ws, req) => {
console.log('Client connected');
ws.send(JSON.stringify({
action: 'init',
width: '720',
height: '1280'
}));
var videoStream = mirrorTcpStream({ feed_ip : '127.0.0.1', feed_port : 8091 });
videoStream.on('data', (data) => {
ws.send(data, { binary: true }, (error) => { if (error) console.error(error); });
});
ws.on('close', () => {
console.log('Client left');
videoStream.removeAllListeners('data');
});
ws.on('message', (msg) => {
console.log(msg)
execSync('..\\scrcpy\\adb shell input ' + msg, { encoding: 'utf-8' });
});
});
app.listen(8090, () => console.log('Server started on 8090'));