first commit

This commit is contained in:
2026-09-08 20:28:54 +08:00
commit 2ada8d3d5a
37380 changed files with 4886169 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
var Command, ConnectCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
ConnectCommand = (function(superClass) {
var RE_OK;
extend(ConnectCommand, superClass);
function ConnectCommand() {
return ConnectCommand.__super__.constructor.apply(this, arguments);
}
RE_OK = /connected to|already connected/;
ConnectCommand.prototype.execute = function(host, port) {
this._send("host:connect:" + host + ":" + port);
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.readValue().then(function(value) {
if (RE_OK.test(value)) {
return host + ":" + port;
} else {
throw new Error(value.toString());
}
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return ConnectCommand;
})(Command);
module.exports = ConnectCommand;
+64
View File
@@ -0,0 +1,64 @@
var Command, HostDevicesCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
HostDevicesCommand = (function(superClass) {
extend(HostDevicesCommand, superClass);
function HostDevicesCommand() {
return HostDevicesCommand.__super__.constructor.apply(this, arguments);
}
HostDevicesCommand.prototype.execute = function() {
this._send('host:devices');
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this._readDevices();
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
HostDevicesCommand.prototype._readDevices = function() {
return this.parser.readValue().then((function(_this) {
return function(value) {
return _this._parseDevices(value);
};
})(this));
};
HostDevicesCommand.prototype._parseDevices = function(value) {
var devices, i, id, len, line, ref, ref1, type;
devices = [];
if (!value.length) {
return devices;
}
ref = value.toString('ascii').split('\n');
for (i = 0, len = ref.length; i < len; i++) {
line = ref[i];
if (line) {
ref1 = line.split('\t'), id = ref1[0], type = ref1[1];
devices.push({
id: id,
type: type
});
}
}
return devices;
};
return HostDevicesCommand;
})(Command);
module.exports = HostDevicesCommand;
+65
View File
@@ -0,0 +1,65 @@
var Command, HostDevicesWithPathsCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
HostDevicesWithPathsCommand = (function(superClass) {
extend(HostDevicesWithPathsCommand, superClass);
function HostDevicesWithPathsCommand() {
return HostDevicesWithPathsCommand.__super__.constructor.apply(this, arguments);
}
HostDevicesWithPathsCommand.prototype.execute = function() {
this._send('host:devices-l');
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this._readDevices();
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
HostDevicesWithPathsCommand.prototype._readDevices = function() {
return this.parser.readValue().then((function(_this) {
return function(value) {
return _this._parseDevices(value);
};
})(this));
};
HostDevicesWithPathsCommand.prototype._parseDevices = function(value) {
var devices, i, id, len, line, path, ref, ref1, type;
devices = [];
if (!value.length) {
return devices;
}
ref = value.toString('ascii').split('\n');
for (i = 0, len = ref.length; i < len; i++) {
line = ref[i];
if (line) {
ref1 = line.split(/\s+/), id = ref1[0], type = ref1[1], path = ref1[2];
devices.push({
id: id,
type: type,
path: path
});
}
}
return devices;
};
return HostDevicesWithPathsCommand;
})(Command);
module.exports = HostDevicesWithPathsCommand;
+46
View File
@@ -0,0 +1,46 @@
var Command, DisconnectCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
DisconnectCommand = (function(superClass) {
var RE_OK;
extend(DisconnectCommand, superClass);
function DisconnectCommand() {
return DisconnectCommand.__super__.constructor.apply(this, arguments);
}
RE_OK = /^$/;
DisconnectCommand.prototype.execute = function(host, port) {
this._send("host:disconnect:" + host + ":" + port);
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.readValue().then(function(value) {
if (RE_OK.test(value)) {
return host + ":" + port;
} else {
throw new Error(value.toString());
}
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return DisconnectCommand;
})(Command);
module.exports = DisconnectCommand;
+36
View File
@@ -0,0 +1,36 @@
var Command, HostKillCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
HostKillCommand = (function(superClass) {
extend(HostKillCommand, superClass);
function HostKillCommand() {
return HostKillCommand.__super__.constructor.apply(this, arguments);
}
HostKillCommand.prototype.execute = function() {
this._send('host:kill');
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return true;
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return HostKillCommand;
})(Command);
module.exports = HostKillCommand;
+40
View File
@@ -0,0 +1,40 @@
var Command, HostDevicesCommand, HostTrackDevicesCommand, Protocol, Tracker,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
Tracker = require('../../tracker');
HostDevicesCommand = require('./devices');
HostTrackDevicesCommand = (function(superClass) {
extend(HostTrackDevicesCommand, superClass);
function HostTrackDevicesCommand() {
return HostTrackDevicesCommand.__super__.constructor.apply(this, arguments);
}
HostTrackDevicesCommand.prototype.execute = function() {
this._send('host:track-devices');
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return new Tracker(_this);
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return HostTrackDevicesCommand;
})(HostDevicesCommand);
module.exports = HostTrackDevicesCommand;
+36
View File
@@ -0,0 +1,36 @@
var Command, HostTransportCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
HostTransportCommand = (function(superClass) {
extend(HostTransportCommand, superClass);
function HostTransportCommand() {
return HostTransportCommand.__super__.constructor.apply(this, arguments);
}
HostTransportCommand.prototype.execute = function(serial) {
this._send("host:transport:" + serial);
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return true;
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return HostTransportCommand;
})(Command);
module.exports = HostTransportCommand;
+42
View File
@@ -0,0 +1,42 @@
var Command, HostVersionCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
HostVersionCommand = (function(superClass) {
extend(HostVersionCommand, superClass);
function HostVersionCommand() {
return HostVersionCommand.__super__.constructor.apply(this, arguments);
}
HostVersionCommand.prototype.execute = function() {
this._send('host:version');
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.readValue().then(function(value) {
return _this._parseVersion(value);
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this._parseVersion(reply);
}
};
})(this));
};
HostVersionCommand.prototype._parseVersion = function(version) {
return parseInt(version, 16);
};
return HostVersionCommand;
})(Command);
module.exports = HostVersionCommand;