258220
请教一下各位大大怎样获取到用户的输入。 具体的需求是:我目前使用adbkit来获取连接到服务器的手机,需要在同一个线程中开启一个服务并监听用户的输入,如果用户输入‘get’,我就返回目前已有的手机信息给它,不知道应该怎样实现? 现在的代码如下:
#!/usr/bin/env node
var adb = require('adbkit');
var client = adb.createClient();
var cellphones = require("./CellPhones");
var JsonCellList = {"cellphone" : []};
client.trackDevices()
.then(function(tracker) {
tracker.on('add', function(device) {
console.log('Device %s was plugged in', device.id);
var time = new Date().getTime();
var item = { "id" : device.id,
"type" : device.type,
"timestamp" : time,
"status" : 0 };
JsonCellList.cellphone.push(item);
cellphones.setCells(JsonCellList);
console.log(cellphones.getCells());
});
tracker.on('remove', function(device) {
console.log('Device %s was unplugged', device.id);
delId = device.id;
for(i in JsonCellList.cellphone) {
if(JsonCellList.cellphone[i].id == delId) JsonCellList.cellphone.splice(i,1);
}
cellphones.setCells(JsonCellList);
console.log(cellphones.getCells());
});
tracker.on('end', function() {
console.log('Tracking stopped');
});
})
.catch(function(err) {
console.error('Something went wrong:', err.stack);
});