-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
32 lines (27 loc) · 974 Bytes
/
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
const express = require('express');
const WebSocket = require('ws');
const http = require('http');
const path = require('path');
const { spawn } = require('child_process');
const app = express();
const server = http.createServer(app);
const wss = new WebSocket.Server({ server });
let command = spawn('adb', ['logcat']);
command.stdout.on('data', (data) => {
wss.clients.forEach(client => client.send(`${data}`));
});
command.stderr.on('data', (data) => {
wss.clients.forEach(client => client.send(`${data}`));
});
command.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
app.use('/', express.static(path.resolve(__dirname, 'dist')));
app.get('/', (req, res) => res.sendFile(path.resolve(__dirname, 'dist/index.html')));
if (!module.parent) {
server.listen(process.env.PORT || 8999, () => {
console.log(`logcat-viewer running on port ${server.address().port}`);
})
} else {
module.exports = server;
}