diff --git a/lib/adb.js b/lib/adb.js index 5201a47..39e71f8 100644 --- a/lib/adb.js +++ b/lib/adb.js @@ -5,6 +5,7 @@ var SHELL = require("lib/shell"); var SYS = require("lib/system"); +// A common Android devices function ADBObject() { this.binPath = "bin\\platform-tools_r33.0.0-windows\\platform-tools\\adb.exe"; @@ -86,10 +87,44 @@ function ADBObject() { }; } +// An Android Emulator +function EmulatorObject(binPath) { + this.ADBI = (new ADBObject()).setBinPath(binPath); + + this.getProcessID = function(id) { + var row = id.split(':'); + //var addr = row[0]; + var port = row[1]; + var cmd = "netstat -ano | findstr :" + port + " | findstr :0"; + var result = SHELL.exec(cmd); + return result.substring(result.lastIndexOf(' ')); + }; + + this.getList = function() { + var items = []; + var devices = this.ADBI.getDevices(); + + for(var i = 0; i < devices.length; i++) { + var hostname = devices[i].hostname; + var PID = parseInt(this.getProcessID(devices[i].id)); + items.push({ + hostname: hostname, + PID: PID + }); + } + + return items; + }; +} + exports.create = function() { return new ADBObject(); }; -exports.VERSIONINFO = "Android Debug Bridge Interface (adb.js) version 0.2"; +exports.createEmulator = function(binPath) { + return new EmulatorObject(binPath); +}; + +exports.VERSIONINFO = "Android Debug Bridge Interface (adb.js) version 0.2.1"; exports.global = global; exports.require = global.require; diff --git a/lib/api.websms.js b/lib/api.websms.js deleted file mode 100644 index 6c5ab72..0000000 --- a/lib/api.websms.js +++ /dev/null @@ -1,103 +0,0 @@ -var RAND = require("lib/rand"); -var HTTP = require("lib/http"); - -var WebSMSObject = function() { - this.host = "localhost"; - this.token = ""; - this.country = "any"; - this.operator = "any"; - this.product = ""; - this.profiles = []; - - this.setHost = function(host) { - this.host = host; - return this; - }; - - this.setToken = function(token) { - this.token = token; - return this; - }; - - this.setCountry = function(country) { - this.country = country; - return this; - }; - - this.setOperator = function(operator) { - this.operator = operator; - return this; - }; - - this.setProduct = function(product) { - this.product = product; - return this; - }; - - this.addProfile = function(product, country, operator) { - this.profiles.push({ - "product": product, - "country": country, - "operator": operator - }); - return this; - }; - - this.buy = function() { - try { - if (this.profiles.length > 0) { - var pf = RAND.one(this.profiles); - this.setProduct(pf.product); - this.setOperator(pf.operator); - this.setCountry(pf.country); - } - - var response = HTTP.create() - .setBearerAuth(this.token) - .setUseCache(false) - .setHeader("Accept", "application/json") - .setParameter("country", this.country) - .setParameter("operator", this.operator) - .setParameter("product", this.product) - .open("GET", "https://" + this.host + "/v1/user/buy/activation/:country/:operator/:product") - .send(function(res) { - console.log("Got the number: " + res.phone); - }).responseBody - ; - return { - "id": response.id, - "number": response.phone - }; - } catch(e) { - console.error(e.message); - } - }; - - this.get = function(id) { - try { - var response = HTTP.create() - .setBearerAuth(this.token) - .setUseCache(false) - .setHeader("Accept", "application/json") - .setParameter("id", id) - .open("GET", "https://" + this.host + "/v1/user/check/:id") - .send(function(res) { - var messages = res.sms; - messages.forEach(function(x) { - console.log("Got the code: " + x.code); - }); - }).responseBody - ; - return response.sms.reduce(function(a, x) { - a = x.code; - return a; - }, null); - } catch (e) { - console.error(e.message); - } - }; -}; - -exports.create = function() { - return new WebSMSObject(); -}; diff --git a/lib/noxplayer.adb.js b/lib/noxplayer.adb.js deleted file mode 100644 index b06ced7..0000000 --- a/lib/noxplayer.adb.js +++ /dev/null @@ -1,41 +0,0 @@ -//////////////////////////////////////////////////////////////////////// -// NoxPlayer API -/////////////////////////////////////////////////////////////////////// - -var SHELL = require("lib/shell"); -var SYS = require("lib/sys"); -var ADB = require("lib/adb"); - -function getProcessID(id) { - var row = id.split(':'); - //var addr = row[0]; - var port = row[1]; - var cmd = "netstat -ano | findstr :" + port + " | findstr :0"; - var result = SHELL.exec(cmd); - return result.substring(result.lastIndexOf(' ')); -}; - -function getList() { - var items = []; - var devices = ADB.create() - .setBinPath(SYS.getEnvString("PROGRAMFILES(X86)") + "/Nox/bin/nox_adb.exe") - .getDevices() - ; - - for(var i = 0; i < devices.length; i++) { - var hostname = devices[i].hostname; - var PID = parseInt(getProcessID(devices[i].id)); - items.push({ - hostname: hostname, - PID: PID - }); - } - - return items; -} - -exports.getList = getList; - -exports.VERSIONINFO = "NoxPlayer (noxplayer.js) version 0.2"; -exports.global = global; -exports.require = global.require;