Template Upload
This commit is contained in:
130
node_modules/weinre/lib/Channel.js
generated
vendored
Normal file
130
node_modules/weinre/lib/Channel.js
generated
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
// Generated by CoffeeScript 1.8.0
|
||||
var AnonymousId, Channel, MessageQueue, channelManager, genJSON, messageHandler, parseJSON, utils, _,
|
||||
__slice = [].slice;
|
||||
|
||||
_ = require('underscore');
|
||||
|
||||
utils = require('./utils');
|
||||
|
||||
channelManager = require('./channelManager');
|
||||
|
||||
messageHandler = require('./messageHandler');
|
||||
|
||||
MessageQueue = require('./MessageQueue');
|
||||
|
||||
AnonymousId = 'anonymous';
|
||||
|
||||
module.exports = utils.registerClass(Channel = (function() {
|
||||
function Channel(pathPrefix, id, remoteAddress, isClient) {
|
||||
var prefix;
|
||||
this.pathPrefix = pathPrefix;
|
||||
this.id = id;
|
||||
this.remoteAddress = remoteAddress;
|
||||
this.isClient = isClient;
|
||||
prefix = this.isClient ? 'c-' : 't-';
|
||||
this.name = "" + prefix + (utils.getNextSequenceNumber());
|
||||
this.messageQueue = new MessageQueue;
|
||||
this.isClosed = false;
|
||||
this.connections = [];
|
||||
this.isTarget = !this.isClient;
|
||||
this.readTimeout = utils.options.readTimeout * 1000;
|
||||
if (!this.id) {
|
||||
this.id = AnonymousId;
|
||||
}
|
||||
this.description = {
|
||||
channel: this.name,
|
||||
id: this.id,
|
||||
hostName: this.remoteAddress,
|
||||
remoteAddress: this.remoteAddress
|
||||
};
|
||||
this.updateLastRead();
|
||||
channelManager.created(this);
|
||||
}
|
||||
|
||||
Channel.prototype.close = function() {
|
||||
if (this.isClosed) {
|
||||
return;
|
||||
}
|
||||
channelManager.destroyed(this);
|
||||
this.isClosed = true;
|
||||
return this.messageQueue.shutdown();
|
||||
};
|
||||
|
||||
Channel.prototype.sendCallback = function() {
|
||||
var args, callbackId, intfName;
|
||||
intfName = arguments[0], callbackId = arguments[1], args = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
|
||||
if (!callbackId) {
|
||||
return;
|
||||
}
|
||||
args.unshift(callbackId);
|
||||
return this.sendMessage.apply(this, [intfName, 'sendCallback'].concat(__slice.call(args)));
|
||||
};
|
||||
|
||||
Channel.prototype.sendMessage = function() {
|
||||
var args, intfName, message, method;
|
||||
intfName = arguments[0], method = arguments[1], args = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
|
||||
message = genJSON({
|
||||
"interface": intfName,
|
||||
method: method,
|
||||
args: args
|
||||
});
|
||||
return this.messageQueue.push(message);
|
||||
};
|
||||
|
||||
Channel.prototype.handleMessages = function(messages) {
|
||||
var message, _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = messages.length; _i < _len; _i++) {
|
||||
message = messages[_i];
|
||||
message = parseJSON(message);
|
||||
if (!message) {
|
||||
continue;
|
||||
}
|
||||
_results.push(messageHandler.handleMessage(this, message));
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
Channel.prototype.getMessages = function(callback) {
|
||||
this.updateLastRead();
|
||||
if (this.isClosed) {
|
||||
return callback.call(null, null);
|
||||
}
|
||||
return this.messageQueue.pullAll(this.readTimeout, callback);
|
||||
};
|
||||
|
||||
Channel.prototype.updateLastRead = function() {
|
||||
return this.lastRead = (new Date).valueOf();
|
||||
};
|
||||
|
||||
Channel.prototype.toString = function() {
|
||||
var connections;
|
||||
connections = _.map(this.connections, function(val) {
|
||||
return val.name;
|
||||
}).join(',');
|
||||
return "Channel(" + this.name + ", closed:" + this.isClosed + ", connections:[" + connections + "])";
|
||||
};
|
||||
|
||||
return Channel;
|
||||
|
||||
})());
|
||||
|
||||
parseJSON = function(message) {
|
||||
var e;
|
||||
try {
|
||||
return JSON.parse(message);
|
||||
} catch (_error) {
|
||||
e = _error;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
genJSON = function(message) {
|
||||
var e;
|
||||
try {
|
||||
return JSON.stringify(message);
|
||||
} catch (_error) {
|
||||
e = _error;
|
||||
return null;
|
||||
}
|
||||
};
|
130
node_modules/weinre/lib/HttpChannelHandler.js
generated
vendored
Normal file
130
node_modules/weinre/lib/HttpChannelHandler.js
generated
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
// Generated by CoffeeScript 1.8.0
|
||||
var Channel, HttpChannelHandler, channelManager, handleCreate, handleError, handleGet, handleOptions, handlePost, setCORSHeaders, setCacheHeaders, utils, _;
|
||||
|
||||
_ = require('underscore');
|
||||
|
||||
utils = require('./utils');
|
||||
|
||||
Channel = require('./Channel');
|
||||
|
||||
channelManager = require('./channelManager');
|
||||
|
||||
module.exports = utils.registerClass(HttpChannelHandler = (function() {
|
||||
function HttpChannelHandler(pathPrefix) {
|
||||
this.pathPrefix = pathPrefix;
|
||||
if (this.pathPrefix === '/ws/client') {
|
||||
this.isClient = true;
|
||||
} else if (this.pathPrefix === '/ws/target') {
|
||||
this.isClient = false;
|
||||
} else {
|
||||
utils.pitch("invalid pathPrefix: " + this.pathPrefix);
|
||||
}
|
||||
this.isTarget = !this.isClient;
|
||||
}
|
||||
|
||||
HttpChannelHandler.prototype.handle = function(request, response, uri) {
|
||||
var channelName, parts;
|
||||
setCORSHeaders(request, response);
|
||||
setCacheHeaders(request, response);
|
||||
if (uri[0] !== '/') {
|
||||
return handleError(request, response, 404);
|
||||
}
|
||||
if (uri === '/') {
|
||||
if (request.method === 'OPTIONS') {
|
||||
return handleOptions(request, response);
|
||||
}
|
||||
if (request.method === 'POST') {
|
||||
return handleCreate(this.pathPrefix, this.isClient, request, response);
|
||||
}
|
||||
return handleError(request, response, 405);
|
||||
}
|
||||
parts = uri.split('/');
|
||||
if (parts.length > 2) {
|
||||
return handleError(request, response, 404);
|
||||
}
|
||||
channelName = parts[1];
|
||||
if (request.method === 'OPTIONS') {
|
||||
return handleOptions(request, response);
|
||||
}
|
||||
if (request.method === 'GET') {
|
||||
return handleGet(request, response, channelName);
|
||||
}
|
||||
if (request.method === 'POST') {
|
||||
return handlePost(request, response, channelName);
|
||||
}
|
||||
return handleError(request, response, 405);
|
||||
};
|
||||
|
||||
return HttpChannelHandler;
|
||||
|
||||
})());
|
||||
|
||||
handleCreate = function(pathPrefix, isClient, request, response) {
|
||||
var channel, id, remoteAddress, _ref, _ref1;
|
||||
id = (_ref = request.body) != null ? _ref.id : void 0;
|
||||
remoteAddress = ((_ref1 = request.connection) != null ? _ref1.remoteAddress : void 0) || "";
|
||||
channel = new Channel(pathPrefix, id, remoteAddress, isClient);
|
||||
response.contentType('application/json');
|
||||
return response.send(JSON.stringify({
|
||||
channel: channel.name,
|
||||
id: channel.id
|
||||
}));
|
||||
};
|
||||
|
||||
handleGet = function(request, response, channelName) {
|
||||
var channel, remoteAddress, _ref;
|
||||
remoteAddress = ((_ref = request.connection) != null ? _ref.remoteAddress : void 0) || "";
|
||||
channel = channelManager.getChannel(channelName, remoteAddress);
|
||||
if (!channel) {
|
||||
return handleError(request, response, 404);
|
||||
}
|
||||
return channel.getMessages((function(_this) {
|
||||
return function(messages) {
|
||||
if (channel.isClosed) {
|
||||
return handleError(request, response, 404);
|
||||
}
|
||||
if (!messages) {
|
||||
return handleError(request, response, 404);
|
||||
}
|
||||
response.contentType('application/json');
|
||||
return response.send(JSON.stringify(messages));
|
||||
};
|
||||
})(this));
|
||||
};
|
||||
|
||||
handlePost = function(request, response, channelName) {
|
||||
var channel, remoteAddress, _ref;
|
||||
remoteAddress = ((_ref = request.connection) != null ? _ref.remoteAddress : void 0) || "";
|
||||
channel = channelManager.getChannel(channelName, remoteAddress);
|
||||
if (!channel) {
|
||||
return handleError(request, response, 404);
|
||||
}
|
||||
channel.handleMessages(request.body);
|
||||
return response.send('');
|
||||
};
|
||||
|
||||
handleOptions = function(request, response) {
|
||||
return response.send('');
|
||||
};
|
||||
|
||||
handleError = function(request, response, status) {
|
||||
return response.send(status);
|
||||
};
|
||||
|
||||
setCORSHeaders = function(request, response) {
|
||||
var origin;
|
||||
origin = request.header('Origin');
|
||||
if (!origin) {
|
||||
return;
|
||||
}
|
||||
response.header('Access-Control-Allow-Origin', origin);
|
||||
response.header('Access-Control-Max-Age', '600');
|
||||
return response.header('Access-Control-Allow-Methods', 'GET, POST');
|
||||
};
|
||||
|
||||
setCacheHeaders = function(request, response) {
|
||||
response.header('Pragma', 'no-cache');
|
||||
response.header('Expires', '0');
|
||||
response.header('Cache-Control', 'no-cache');
|
||||
return response.header('Cache-Control', 'no-store');
|
||||
};
|
82
node_modules/weinre/lib/MessageQueue.js
generated
vendored
Normal file
82
node_modules/weinre/lib/MessageQueue.js
generated
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
// Generated by CoffeeScript 1.8.0
|
||||
var MessageQueue, utils, _;
|
||||
|
||||
_ = require('underscore');
|
||||
|
||||
utils = require('./utils');
|
||||
|
||||
module.exports = utils.registerClass(MessageQueue = (function() {
|
||||
function MessageQueue() {
|
||||
this.messages = [];
|
||||
this.closed = false;
|
||||
this.callback = null;
|
||||
this.timer = null;
|
||||
_.bindAll(this, '_timerExpired', '_updated');
|
||||
}
|
||||
|
||||
MessageQueue.prototype.shutdown = function() {
|
||||
if (this.closed) {
|
||||
return;
|
||||
}
|
||||
this.closed = true;
|
||||
if (this.timer) {
|
||||
clearTimeout(this.timer);
|
||||
}
|
||||
if (this.callback) {
|
||||
this.callback.call(null, this.messages);
|
||||
}
|
||||
this.callback = null;
|
||||
this.messages = null;
|
||||
return this.timer = null;
|
||||
};
|
||||
|
||||
MessageQueue.prototype.push = function(message) {
|
||||
if (this.closed) {
|
||||
return;
|
||||
}
|
||||
this.messages.push(message);
|
||||
return process.nextTick(this._updated);
|
||||
};
|
||||
|
||||
MessageQueue.prototype.pullAll = function(timeout, callback) {
|
||||
if (this.closed) {
|
||||
return callback.call(null, null);
|
||||
}
|
||||
if (this.callback) {
|
||||
return callback.call(null, []);
|
||||
}
|
||||
if (this.messages.length) {
|
||||
callback.call(null, this.messages);
|
||||
this.messages = [];
|
||||
return;
|
||||
}
|
||||
this.callback = callback;
|
||||
return this.timer = setTimeout(this._timerExpired, timeout);
|
||||
};
|
||||
|
||||
MessageQueue.prototype._timerExpired = function() {
|
||||
return this._updated();
|
||||
};
|
||||
|
||||
MessageQueue.prototype._updated = function() {
|
||||
var callback, messages;
|
||||
if (this.closed) {
|
||||
return;
|
||||
}
|
||||
if (!this.callback) {
|
||||
return;
|
||||
}
|
||||
callback = this.callback;
|
||||
messages = this.messages;
|
||||
if (this.timer) {
|
||||
clearTimeout(this.timer);
|
||||
}
|
||||
this.callback = null;
|
||||
this.messages = [];
|
||||
this.timer = null;
|
||||
return callback.call(null, messages);
|
||||
};
|
||||
|
||||
return MessageQueue;
|
||||
|
||||
})());
|
122
node_modules/weinre/lib/channelManager.js
generated
vendored
Normal file
122
node_modules/weinre/lib/channelManager.js
generated
vendored
Normal file
@ -0,0 +1,122 @@
|
||||
// Generated by CoffeeScript 1.8.0
|
||||
var ChannelManager, WeinreClientEvents, WeinreTargetEvents, channelManager, serviceManager, utils, _;
|
||||
|
||||
_ = require('underscore');
|
||||
|
||||
utils = require('./utils');
|
||||
|
||||
serviceManager = require('./serviceManager');
|
||||
|
||||
WeinreClientEvents = null;
|
||||
|
||||
WeinreTargetEvents = null;
|
||||
|
||||
channelManager = null;
|
||||
|
||||
utils.registerClass(ChannelManager = (function() {
|
||||
function ChannelManager() {
|
||||
this.channels = {};
|
||||
}
|
||||
|
||||
ChannelManager.prototype.initialize = function() {
|
||||
WeinreClientEvents = serviceManager.get('WeinreClientEvents');
|
||||
WeinreTargetEvents = serviceManager.get('WeinreTargetEvents');
|
||||
if (!WeinreClientEvents) {
|
||||
utils.exit('WeinreClientEvents service not registered');
|
||||
}
|
||||
if (!WeinreTargetEvents) {
|
||||
return utils.exit('WeinreTargetEvents service not registered');
|
||||
}
|
||||
};
|
||||
|
||||
ChannelManager.prototype.created = function(channel) {
|
||||
return this.channels[channel.name] = channel;
|
||||
};
|
||||
|
||||
ChannelManager.prototype.destroyed = function(channel) {
|
||||
var clients, connection, _i, _j, _len, _len1, _ref, _ref1;
|
||||
if (channel.isClient) {
|
||||
_ref = channel.connections;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
connection = _ref[_i];
|
||||
this.disconnectChannels(channel, connection);
|
||||
}
|
||||
} else {
|
||||
_ref1 = channel.connections;
|
||||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
||||
connection = _ref1[_j];
|
||||
this.disconnectChannels(connection, channel);
|
||||
}
|
||||
}
|
||||
clients = this.getClientChannels(channel.id);
|
||||
if (channel.isClient) {
|
||||
WeinreClientEvents.clientUnregistered(clients, channel.name);
|
||||
} else {
|
||||
WeinreClientEvents.targetUnregistered(clients, channel.name);
|
||||
}
|
||||
return delete this.channels[channel.name];
|
||||
};
|
||||
|
||||
ChannelManager.prototype.getChannel = function(name, remoteAddress) {
|
||||
var channel;
|
||||
if (!_.has(this.channels, name)) {
|
||||
return null;
|
||||
}
|
||||
channel = this.channels[name];
|
||||
if (!channel) {
|
||||
return null;
|
||||
}
|
||||
return channel;
|
||||
};
|
||||
|
||||
ChannelManager.prototype.connectChannels = function(client, target) {
|
||||
var clients;
|
||||
if (client.isClosed || target.isClosed) {
|
||||
return;
|
||||
}
|
||||
if (client.connections.length) {
|
||||
this.disconnectChannels(client, client.connections[0]);
|
||||
}
|
||||
client.connections.push(target);
|
||||
target.connections.push(client);
|
||||
clients = this.getClientChannels(client.id);
|
||||
WeinreClientEvents.connectionCreated(clients, client.name, target.name);
|
||||
return WeinreTargetEvents.connectionCreated(target, client.name, target.name);
|
||||
};
|
||||
|
||||
ChannelManager.prototype.disconnectChannels = function(client, target) {
|
||||
var clients;
|
||||
clients = this.getClientChannels(client.id);
|
||||
WeinreClientEvents.connectionDestroyed(clients, client.name, target.name);
|
||||
WeinreTargetEvents.connectionDestroyed(target, client.name, target.name);
|
||||
client.connections = _.without(client.connections, target);
|
||||
return target.connections = _.without(target.connections, client);
|
||||
};
|
||||
|
||||
ChannelManager.prototype.getChannels = function(id) {
|
||||
if (id != null) {
|
||||
return _.filter(this.channels, function(item) {
|
||||
return item.id === id;
|
||||
});
|
||||
} else {
|
||||
return _.values(this.channels);
|
||||
}
|
||||
};
|
||||
|
||||
ChannelManager.prototype.getClientChannels = function(id) {
|
||||
return _.filter(this.channels, function(item) {
|
||||
return item.isClient && item.id === id;
|
||||
});
|
||||
};
|
||||
|
||||
ChannelManager.prototype.getTargetChannels = function(id) {
|
||||
return _.filter(this.channels, function(item) {
|
||||
return item.isTarget && item.id === id;
|
||||
});
|
||||
};
|
||||
|
||||
return ChannelManager;
|
||||
|
||||
})());
|
||||
|
||||
module.exports = new ChannelManager;
|
97
node_modules/weinre/lib/cli.js
generated
vendored
Normal file
97
node_modules/weinre/lib/cli.js
generated
vendored
Normal file
@ -0,0 +1,97 @@
|
||||
// Generated by CoffeeScript 1.8.0
|
||||
var fs, getDotWeinreServerProperties, getTildeReplacement, nopt, optionDefaults, path, printHelp, printNoptError, replaceTilde, utils, weinre, _;
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
path = require('path');
|
||||
|
||||
_ = require('underscore');
|
||||
|
||||
nopt = require('nopt');
|
||||
|
||||
utils = require('./utils');
|
||||
|
||||
weinre = require('./weinre');
|
||||
|
||||
optionDefaults = {
|
||||
httpPort: 8080,
|
||||
boundHost: 'localhost',
|
||||
verbose: false,
|
||||
debug: false,
|
||||
readTimeout: 5
|
||||
};
|
||||
|
||||
exports.run = function() {
|
||||
var args, knownOpts, opts, parsedOpts, shortHands;
|
||||
knownOpts = {
|
||||
httpPort: Number,
|
||||
boundHost: String,
|
||||
verbose: Boolean,
|
||||
debug: Boolean,
|
||||
readTimeout: Number,
|
||||
deathTimeout: Number,
|
||||
help: Boolean
|
||||
};
|
||||
shortHands = {
|
||||
'?': ['--help'],
|
||||
'h': ['--help']
|
||||
};
|
||||
nopt.invalidHandler = printNoptError;
|
||||
parsedOpts = nopt(knownOpts, shortHands, process.argv, 2);
|
||||
if (parsedOpts.help) {
|
||||
printHelp();
|
||||
}
|
||||
args = parsedOpts.argv.remain;
|
||||
if (args.length !== 0) {
|
||||
printHelp();
|
||||
}
|
||||
delete parsedOpts.argv;
|
||||
opts = _.extend({}, optionDefaults, getDotWeinreServerProperties(), parsedOpts);
|
||||
if (opts.deathTimeout == null) {
|
||||
opts.deathTimeout = 3 * opts.readTimeout;
|
||||
}
|
||||
utils.setOptions(opts);
|
||||
return weinre.run(opts);
|
||||
};
|
||||
|
||||
printNoptError = function(key, val, types) {
|
||||
return utils.exit("error with option '" + key + "', value '" + val + "'");
|
||||
};
|
||||
|
||||
printHelp = function() {
|
||||
var version;
|
||||
version = weinre.getVersion();
|
||||
console.error("usage: " + utils.Program + " [options]\nversion: " + version + "\n\noptions:\n --httpPort port to run the http server on default: " + optionDefaults.httpPort + "\n --boundHost ip address to bind the server to default: " + optionDefaults.boundHost + "\n --verbose print more diagnostics default: " + optionDefaults.verbose + "\n --debug print even more diagnostics default: " + optionDefaults.debug + "\n --readTimeout seconds to wait for a client message default: " + optionDefaults.readTimeout + "\n --deathTimeout seconds to wait to kill client default: 3*readTimeout\n\n--boundHost can be an ip address, hostname, or -all-, where -all-\nmeans binding to all ip address on the current machine'\n\nfor more info see: http://people.apache.org/~pmuellr/weinre/");
|
||||
return process.exit();
|
||||
};
|
||||
|
||||
getDotWeinreServerProperties = function() {
|
||||
var contents, fileName, key, line, lines, match, properties, val, _i, _len;
|
||||
properties = {};
|
||||
fileName = replaceTilde('~/.weinre/server.properties');
|
||||
if (!utils.fileExistsSync(fileName)) {
|
||||
return properties;
|
||||
}
|
||||
contents = fs.readFileSync(fileName, 'utf8');
|
||||
lines = contents.split('\n');
|
||||
for (_i = 0, _len = lines.length; _i < _len; _i++) {
|
||||
line = lines[_i];
|
||||
line = line.replace(/#.*/, '');
|
||||
match = line.match(/\s*(\w+)\s*:\s*(.+)\s*/);
|
||||
if (!match) {
|
||||
continue;
|
||||
}
|
||||
key = utils.trim(match[1]);
|
||||
val = utils.trim(match[2]);
|
||||
properties[key] = val;
|
||||
}
|
||||
return properties;
|
||||
};
|
||||
|
||||
replaceTilde = function(fileName) {
|
||||
return fileName.replace('~', getTildeReplacement());
|
||||
};
|
||||
|
||||
getTildeReplacement = function() {
|
||||
return process.env["HOME"] || process.env["USERPROFILE"] || '.';
|
||||
};
|
74
node_modules/weinre/lib/dumpingHandler.js
generated
vendored
Normal file
74
node_modules/weinre/lib/dumpingHandler.js
generated
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
// Generated by CoffeeScript 1.8.0
|
||||
var dumpResponse, dumpingHandler, enhance, utils, _;
|
||||
|
||||
_ = require('underscore');
|
||||
|
||||
utils = require('./utils');
|
||||
|
||||
dumpingHandler = function(request, response, uri) {
|
||||
var element, originalSend, _i, _len, _ref, _results;
|
||||
originalSend = response.send;
|
||||
response.send = function(body) {
|
||||
return dumpResponse(originalSend, body, request, response, uri);
|
||||
};
|
||||
if (request.method !== 'POST') {
|
||||
return;
|
||||
}
|
||||
utils.logVerbose('--------------------------------------------------');
|
||||
utils.logVerbose("" + request.method + " " + uri + " [request]");
|
||||
if (_.isArray(request.body)) {
|
||||
_ref = request.body;
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
element = _ref[_i];
|
||||
_results.push(utils.logVerbose(" " + (enhance(JSON.parse(element)))));
|
||||
}
|
||||
return _results;
|
||||
} else {
|
||||
return utils.logVerbose(" " + (enhance(request.body)));
|
||||
}
|
||||
};
|
||||
|
||||
dumpResponse = function(originalSend, body, request, response, uri) {
|
||||
var e, element, _i, _len, _ref, _results;
|
||||
originalSend.call(response, body);
|
||||
if ((_ref = request.method) !== 'GET' && _ref !== 'POST') {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
body = JSON.parse(body);
|
||||
} catch (_error) {
|
||||
e = _error;
|
||||
return;
|
||||
}
|
||||
if (_.isArray(body) && (body.length === 0)) {
|
||||
return;
|
||||
}
|
||||
utils.logVerbose('--------------------------------------------------');
|
||||
utils.logVerbose("" + request.method + " " + uri + " " + response.statusCode + " [response]");
|
||||
if (_.isArray(body)) {
|
||||
_results = [];
|
||||
for (_i = 0, _len = body.length; _i < _len; _i++) {
|
||||
element = body[_i];
|
||||
_results.push(utils.logVerbose(" " + (enhance(JSON.parse(element)))));
|
||||
}
|
||||
return _results;
|
||||
} else {
|
||||
return utils.logVerbose(" " + (enhance(body)));
|
||||
}
|
||||
};
|
||||
|
||||
enhance = function(object) {
|
||||
var args, signature;
|
||||
if (!object["interface"] || !object.method || !object.args) {
|
||||
return JSON.stringify(object);
|
||||
}
|
||||
signature = "" + object["interface"] + "." + object.method;
|
||||
args = JSON.stringify(object.args);
|
||||
if (args.length > 500) {
|
||||
args = "" + (args.substr(0, 50)) + "...";
|
||||
}
|
||||
return "" + signature + "(" + args + ")";
|
||||
};
|
||||
|
||||
module.exports = dumpingHandler;
|
15
node_modules/weinre/lib/extensionManager.js
generated
vendored
Normal file
15
node_modules/weinre/lib/extensionManager.js
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
// Generated by CoffeeScript 1.8.0
|
||||
var ExtensionManager, utils;
|
||||
|
||||
utils = require('./utils');
|
||||
|
||||
utils.registerClass(ExtensionManager = (function() {
|
||||
function ExtensionManager() {
|
||||
this.extensions = [];
|
||||
}
|
||||
|
||||
return ExtensionManager;
|
||||
|
||||
})());
|
||||
|
||||
module.exports = new ExtensionManager;
|
39
node_modules/weinre/lib/jsonBodyParser.js
generated
vendored
Normal file
39
node_modules/weinre/lib/jsonBodyParser.js
generated
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
// Generated by CoffeeScript 1.8.0
|
||||
var jsonBodyParser, parseBodyAsJSON;
|
||||
|
||||
jsonBodyParser = function() {
|
||||
return function(request, response, next) {
|
||||
return parseBodyAsJSON(request, response, next);
|
||||
};
|
||||
};
|
||||
|
||||
parseBodyAsJSON = function(request, response, next) {
|
||||
var buffer;
|
||||
if (request.body) {
|
||||
return next();
|
||||
}
|
||||
request.body = {};
|
||||
if (request.method !== 'POST') {
|
||||
return next();
|
||||
}
|
||||
request.setEncoding('utf8');
|
||||
buffer = '';
|
||||
request.on('data', function(chunk) {
|
||||
return buffer += chunk;
|
||||
});
|
||||
return request.on('end', function() {
|
||||
var e;
|
||||
if ('' === buffer) {
|
||||
return next();
|
||||
}
|
||||
try {
|
||||
request.body = JSON.parse(buffer);
|
||||
return next();
|
||||
} catch (_error) {
|
||||
e = _error;
|
||||
return next(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = jsonBodyParser;
|
51
node_modules/weinre/lib/messageHandler.js
generated
vendored
Normal file
51
node_modules/weinre/lib/messageHandler.js
generated
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
// Generated by CoffeeScript 1.8.0
|
||||
var MessageHandler, channelManager, serviceManager, utils,
|
||||
__slice = [].slice;
|
||||
|
||||
utils = require('./utils');
|
||||
|
||||
channelManager = require('./channelManager');
|
||||
|
||||
serviceManager = require('./serviceManager');
|
||||
|
||||
utils.registerClass(MessageHandler = (function() {
|
||||
function MessageHandler() {}
|
||||
|
||||
MessageHandler.prototype.handleMessage = function(channel, message) {
|
||||
return this._serviceMethodInvoker(channel, message["interface"], message.method, message.args);
|
||||
};
|
||||
|
||||
MessageHandler.prototype._serviceMethodInvoker = function(channel, intfName, method, args) {
|
||||
var e, methodSignature, service;
|
||||
methodSignature = "" + intfName + "." + method + "()";
|
||||
service = serviceManager.get(intfName);
|
||||
if (!service) {
|
||||
return this._redirectToConnections(channel, intfName, method, args);
|
||||
}
|
||||
args = args.slice();
|
||||
args.unshift(channel);
|
||||
try {
|
||||
return service[method].apply(service, args);
|
||||
} catch (_error) {
|
||||
e = _error;
|
||||
utils.log("error running service method " + methodSignature + ": " + e);
|
||||
return utils.log("stack:\n" + e.stack);
|
||||
}
|
||||
};
|
||||
|
||||
MessageHandler.prototype._redirectToConnections = function(channel, intfName, method, args) {
|
||||
var connection, _i, _len, _ref, _results;
|
||||
_ref = channel.connections;
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
connection = _ref[_i];
|
||||
_results.push(connection.sendMessage.apply(connection, [intfName, method].concat(__slice.call(args))));
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
return MessageHandler;
|
||||
|
||||
})());
|
||||
|
||||
module.exports = new MessageHandler;
|
140
node_modules/weinre/lib/service/WeinreClientCommands.js
generated
vendored
Normal file
140
node_modules/weinre/lib/service/WeinreClientCommands.js
generated
vendored
Normal file
@ -0,0 +1,140 @@
|
||||
// Generated by CoffeeScript 1.8.0
|
||||
var WeinreClientCommands, WeinreClientEvents, channelManager, extensionManager, serviceManager, utils, weinre, _,
|
||||
__hasProp = {}.hasOwnProperty;
|
||||
|
||||
_ = require('underscore');
|
||||
|
||||
weinre = require('../weinre');
|
||||
|
||||
utils = require('../utils');
|
||||
|
||||
channelManager = require('../channelManager');
|
||||
|
||||
serviceManager = require('../serviceManager');
|
||||
|
||||
extensionManager = require('../extensionManager');
|
||||
|
||||
WeinreClientEvents = serviceManager.get('WeinreClientEvents');
|
||||
|
||||
module.exports = utils.registerClass(WeinreClientCommands = (function() {
|
||||
function WeinreClientCommands() {}
|
||||
|
||||
WeinreClientCommands.prototype.registerClient = function(channel, callbackId) {
|
||||
var clients, key, options, val, _ref;
|
||||
if (callbackId) {
|
||||
WeinreClientEvents.sendCallback(channel, callbackId, channel.description);
|
||||
}
|
||||
options = _.extend({}, utils.options);
|
||||
for (key in options) {
|
||||
if (!__hasProp.call(options, key)) continue;
|
||||
val = options[key];
|
||||
if ((_ref = typeof val) === 'number' || _ref === 'boolean') {
|
||||
options[key] = "" + val;
|
||||
}
|
||||
}
|
||||
options.version = weinre.getVersion();
|
||||
WeinreClientEvents.serverProperties(channel, options);
|
||||
clients = channelManager.getClientChannels(channel.id);
|
||||
return WeinreClientEvents.clientRegistered(clients, channel.description);
|
||||
};
|
||||
|
||||
WeinreClientCommands.prototype.getTargets = function(channel, callbackId) {
|
||||
var channels, result;
|
||||
channels = channelManager.getTargetChannels(channel.id);
|
||||
result = _.pluck(channels, 'description');
|
||||
if (callbackId) {
|
||||
return WeinreClientEvents.sendCallback(channel, callbackId, [result]);
|
||||
}
|
||||
};
|
||||
|
||||
WeinreClientCommands.prototype.getClients = function(channel, callbackId) {
|
||||
var channels, result;
|
||||
channels = channelManager.getClientChannels(channel.id);
|
||||
result = _.pluck(channels, 'description');
|
||||
if (callbackId) {
|
||||
return WeinreClientEvents.sendCallback(channel, callbackId, [result]);
|
||||
}
|
||||
};
|
||||
|
||||
WeinreClientCommands.prototype.getExtensions = function(channel, callbackId) {
|
||||
var extension, result;
|
||||
result = (function() {
|
||||
var _i, _len, _ref, _results;
|
||||
_ref = extensionManager.extensions;
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
extension = _ref[_i];
|
||||
_results.push({
|
||||
startPage: "extensions/" + extension + "/extension.html"
|
||||
});
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
if (callbackId) {
|
||||
return WeinreClientEvents.sendCallback(channel, callbackId, [result]);
|
||||
}
|
||||
};
|
||||
|
||||
WeinreClientCommands.prototype.connectTarget = function(channel, clientName, targetName, callbackId) {
|
||||
var client, target;
|
||||
client = channelManager.getChannel(clientName);
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
target = channelManager.getChannel(targetName);
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
channelManager.connectChannels(client, target);
|
||||
if (callbackId) {
|
||||
return WeinreClientEvents.sendCallback(channel, callbackId);
|
||||
}
|
||||
};
|
||||
|
||||
WeinreClientCommands.prototype.disconnectTarget = function(channel, clientName, callbackId) {
|
||||
var client, target;
|
||||
client = connectionManager.getClient(clientName);
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
target = client.getConnectedTarget();
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
connectionManager.disconnect(client, target);
|
||||
if (callbackId) {
|
||||
return WeinreClientEvents.sendCallback(channel, callbackId);
|
||||
}
|
||||
};
|
||||
|
||||
WeinreClientCommands.prototype.logDebug = function(channel, message, callbackId) {
|
||||
utils.logVerbose("client " + channel.name + ": " + message);
|
||||
if (callbackId) {
|
||||
return WeinreClientEvents.sendCallback(channel, callbackId);
|
||||
}
|
||||
};
|
||||
|
||||
WeinreClientCommands.prototype.logInfo = function(channel, message, callbackId) {
|
||||
utils.log("client " + channel.name + ": " + message);
|
||||
if (callbackId) {
|
||||
return WeinreClientEvents.sendCallback(channel, callbackId);
|
||||
}
|
||||
};
|
||||
|
||||
WeinreClientCommands.prototype.logWarning = function(channel, message, callbackId) {
|
||||
utils.log("client " + channel.name + ": " + message);
|
||||
if (callbackId) {
|
||||
return WeinreClientEvents.sendCallback(channel, callbackId);
|
||||
}
|
||||
};
|
||||
|
||||
WeinreClientCommands.prototype.logError = function(channel, message, callbackId) {
|
||||
utils.log("client " + channel.name + ": " + message);
|
||||
if (callbackId) {
|
||||
return WeinreClientEvents.sendCallback(channel, callbackId);
|
||||
}
|
||||
};
|
||||
|
||||
return WeinreClientCommands;
|
||||
|
||||
})());
|
78
node_modules/weinre/lib/service/WeinreTargetCommands.js
generated
vendored
Normal file
78
node_modules/weinre/lib/service/WeinreTargetCommands.js
generated
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
// Generated by CoffeeScript 1.8.0
|
||||
var WeinreClientEvents, WeinreTargetCommands, WeinreTargetEvents, channelManager, getCallbackChannel, serviceManager, utils;
|
||||
|
||||
utils = require('../utils');
|
||||
|
||||
channelManager = require('../channelManager');
|
||||
|
||||
serviceManager = require('../serviceManager');
|
||||
|
||||
WeinreClientEvents = serviceManager.get('WeinreClientEvents');
|
||||
|
||||
WeinreTargetEvents = serviceManager.get('WeinreTargetEvents');
|
||||
|
||||
module.exports = utils.registerClass(WeinreTargetCommands = (function() {
|
||||
function WeinreTargetCommands() {}
|
||||
|
||||
WeinreTargetCommands.prototype.registerTarget = function(channel, url, callbackId) {
|
||||
var clients;
|
||||
channel.description.url = url;
|
||||
clients = channelManager.getClientChannels(channel.id);
|
||||
WeinreClientEvents.targetRegistered(clients, channel.description);
|
||||
if (callbackId) {
|
||||
return WeinreTargetEvents.sendCallback(channel, callbackId, channel.description);
|
||||
}
|
||||
};
|
||||
|
||||
WeinreTargetCommands.prototype.sendClientCallback = function(channel, clientCallbackId, args, callbackId) {
|
||||
var callbackChannel;
|
||||
callbackChannel = getCallbackChannel(clientCallbackId);
|
||||
if (!callbackChannel) {
|
||||
return main.warn("" + this.constructor.name + ".sendClientCallback() sent with invalid callbackId: " + clientCallbackId);
|
||||
}
|
||||
callbackChannel = channelManager.getChannel(callbackChannel);
|
||||
if (!callbackChannel) {
|
||||
return main.warn("" + this.constructor.name + ".sendClientCallback() unable to find channel : " + clientCallbackId);
|
||||
}
|
||||
WeinreClientEvents.sendCallback(callbackChannel, clientCallbackId, args);
|
||||
if (callbackId) {
|
||||
return WeinreTargetEvents.sendCallback(channel, callbackId, description);
|
||||
}
|
||||
};
|
||||
|
||||
WeinreTargetCommands.prototype.logDebug = function(channel, message, callbackId) {
|
||||
utils.logVerbose("target " + channel.name + ": " + message);
|
||||
if (callbackId) {
|
||||
return WeinreTargetEvents.sendCallback(channel, callbackId, description);
|
||||
}
|
||||
};
|
||||
|
||||
WeinreTargetCommands.prototype.logInfo = function(channel, message, callbackId) {
|
||||
utils.log("target " + channel.name + ": " + message);
|
||||
if (callbackId) {
|
||||
return WeinreTargetEvents.sendCallback(channel, callbackId, description);
|
||||
}
|
||||
};
|
||||
|
||||
WeinreTargetCommands.prototype.logWarning = function(channel, message, callbackId) {
|
||||
utils.log("target " + channel.name + ": " + message);
|
||||
if (callbackId) {
|
||||
return WeinreTargetEvents.sendCallback(channel, callbackId, description);
|
||||
}
|
||||
};
|
||||
|
||||
WeinreTargetCommands.prototype.logError = function(channel, message, callbackId) {
|
||||
utils.log("target " + channel.name + ": " + message);
|
||||
if (callbackId) {
|
||||
return WeinreTargetEvents.sendCallback(channel, callbackId, description);
|
||||
}
|
||||
};
|
||||
|
||||
return WeinreTargetCommands;
|
||||
|
||||
})());
|
||||
|
||||
getCallbackChannel = function(callbackId) {
|
||||
callbackId = callbackId.toString();
|
||||
return callbackId.split('::')[0];
|
||||
};
|
90
node_modules/weinre/lib/serviceManager.js
generated
vendored
Normal file
90
node_modules/weinre/lib/serviceManager.js
generated
vendored
Normal file
@ -0,0 +1,90 @@
|
||||
// Generated by CoffeeScript 1.8.0
|
||||
var ServiceManager, Services, fs, getMethodProxy, getServiceInterface, path, utils, _,
|
||||
__slice = [].slice;
|
||||
|
||||
path = require('path');
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
_ = require('underscore');
|
||||
|
||||
utils = require('./utils');
|
||||
|
||||
Services = {};
|
||||
|
||||
utils.registerClass(ServiceManager = (function() {
|
||||
function ServiceManager() {
|
||||
this.services = {};
|
||||
}
|
||||
|
||||
ServiceManager.prototype.get = function(name) {
|
||||
if (_.has(this.services, name)) {
|
||||
return this.services[name];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
ServiceManager.prototype.registerLocalClass = function(name) {
|
||||
var e, serviceClass;
|
||||
serviceClass = null;
|
||||
try {
|
||||
serviceClass = require("./service/" + name);
|
||||
} catch (_error) {
|
||||
e = _error;
|
||||
utils.log("local service class not found: " + name);
|
||||
throw e;
|
||||
}
|
||||
return this.services[name] = new serviceClass;
|
||||
};
|
||||
|
||||
ServiceManager.prototype.registerProxyClass = function(name) {
|
||||
var intf, method, service, _i, _len, _ref;
|
||||
intf = getServiceInterface(name);
|
||||
if (!intf) {
|
||||
utils.exit("proxy service class not found: " + name);
|
||||
}
|
||||
if (intf.name !== name) {
|
||||
utils.exit("proxy interface '" + intf.name + "' loaded when '" + name + "' requested");
|
||||
}
|
||||
service = {};
|
||||
_ref = intf.methods;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
method = _ref[_i];
|
||||
service[method.name] = getMethodProxy(name, method.name);
|
||||
}
|
||||
return this.services[name] = service;
|
||||
};
|
||||
|
||||
return ServiceManager;
|
||||
|
||||
})());
|
||||
|
||||
getMethodProxy = function(intfName, methodName) {
|
||||
return function() {
|
||||
var args, channel, channels, _i, _len, _results;
|
||||
channels = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
||||
if (!_.isArray(channels)) {
|
||||
channels = [channels];
|
||||
}
|
||||
_results = [];
|
||||
for (_i = 0, _len = channels.length; _i < _len; _i++) {
|
||||
channel = channels[_i];
|
||||
_results.push(channel.sendMessage.apply(channel, [intfName, methodName].concat(__slice.call(args))));
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
};
|
||||
|
||||
getServiceInterface = function(name) {
|
||||
var contents, fileName, jsonName, serviceInterface;
|
||||
jsonName = "" + name + ".json";
|
||||
fileName = path.join(utils.options.staticWebDir, 'interfaces', jsonName);
|
||||
if (!utils.fileExistsSync(fileName)) {
|
||||
return null;
|
||||
}
|
||||
contents = fs.readFileSync(fileName, 'utf8');
|
||||
serviceInterface = JSON.parse(contents);
|
||||
return serviceInterface.interfaces[0];
|
||||
};
|
||||
|
||||
module.exports = new ServiceManager;
|
194
node_modules/weinre/lib/utils.js
generated
vendored
Normal file
194
node_modules/weinre/lib/utils.js
generated
vendored
Normal file
@ -0,0 +1,194 @@
|
||||
// Generated by CoffeeScript 1.8.0
|
||||
var Program, SequenceNumber, SequenceNumberMax, fs, log, path, utils,
|
||||
__hasProp = {}.hasOwnProperty;
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
path = require('path');
|
||||
|
||||
utils = exports;
|
||||
|
||||
utils.Program = Program = path.basename(process.argv[1]);
|
||||
|
||||
SequenceNumberMax = 100 * 1024 * 1024;
|
||||
|
||||
SequenceNumber = 0;
|
||||
|
||||
utils.getNextSequenceNumber = function(g) {
|
||||
SequenceNumber++;
|
||||
if (SequenceNumber > SequenceNumberMax) {
|
||||
SequenceNumber = 0;
|
||||
}
|
||||
return SequenceNumber;
|
||||
};
|
||||
|
||||
utils.trim = function(string) {
|
||||
return string.replace(/(^\s+)|(\s+$)/g, '');
|
||||
};
|
||||
|
||||
utils.log = log = function(message) {
|
||||
var date, time;
|
||||
date = new Date();
|
||||
time = date.toISOString();
|
||||
return console.log("" + time + " " + Program + ": " + message);
|
||||
};
|
||||
|
||||
utils.logVerbose = function(message) {
|
||||
var _ref;
|
||||
if (!(utils != null ? (_ref = utils.options) != null ? _ref.verbose : void 0 : void 0)) {
|
||||
return;
|
||||
}
|
||||
return log(message);
|
||||
};
|
||||
|
||||
utils.logDebug = function(message) {
|
||||
var _ref;
|
||||
if (!(utils != null ? (_ref = utils.options) != null ? _ref.debug : void 0 : void 0)) {
|
||||
return;
|
||||
}
|
||||
return log(message);
|
||||
};
|
||||
|
||||
utils.exit = function(message) {
|
||||
log(message);
|
||||
return process.exit(1);
|
||||
};
|
||||
|
||||
utils.pitch = function(message) {
|
||||
log(message);
|
||||
throw message;
|
||||
};
|
||||
|
||||
utils.setOptions = function(options) {
|
||||
return utils.options = options;
|
||||
};
|
||||
|
||||
utils.ensureInteger = function(value, message) {
|
||||
var newValue;
|
||||
newValue = parseInt(value);
|
||||
if (isNaN(newValue)) {
|
||||
utils.exit("" + message + ": '" + value + "'");
|
||||
}
|
||||
return newValue;
|
||||
};
|
||||
|
||||
utils.ensureString = function(value, message) {
|
||||
if (typeof value !== 'string') {
|
||||
utils.exit("" + message + ": '" + value + "'");
|
||||
}
|
||||
return value;
|
||||
};
|
||||
|
||||
utils.ensureBoolean = function(value, message) {
|
||||
var newValue, uValue;
|
||||
uValue = value.toString().toUpperCase();
|
||||
newValue = null;
|
||||
switch (uValue) {
|
||||
case 'TRUE':
|
||||
newValue = true;
|
||||
break;
|
||||
case 'FALSE':
|
||||
newValue = false;
|
||||
}
|
||||
if (typeof newValue !== 'boolean') {
|
||||
utils.exit("" + message + ": '" + value + "'");
|
||||
}
|
||||
return newValue;
|
||||
};
|
||||
|
||||
utils.setNamesForClass = function(aClass) {
|
||||
var key, val, _ref, _results;
|
||||
for (key in aClass) {
|
||||
if (!__hasProp.call(aClass, key)) continue;
|
||||
val = aClass[key];
|
||||
if (typeof val === "function") {
|
||||
val.signature = "" + aClass.name + "::" + key;
|
||||
val.displayName = val.signature;
|
||||
val.name = val.signature;
|
||||
}
|
||||
}
|
||||
_ref = aClass.prototype;
|
||||
_results = [];
|
||||
for (key in _ref) {
|
||||
if (!__hasProp.call(_ref, key)) continue;
|
||||
val = _ref[key];
|
||||
if (typeof val === "function") {
|
||||
val.signature = "" + aClass.name + "." + key;
|
||||
val.displayName = val.signature;
|
||||
_results.push(val.name = val.signature);
|
||||
} else {
|
||||
_results.push(void 0);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
utils.registerClass = function(aClass) {
|
||||
utils.setNamesForClass(aClass);
|
||||
return aClass;
|
||||
};
|
||||
|
||||
utils.alignLeft = function(string, length) {
|
||||
while (string.length < length) {
|
||||
string = "" + string + " ";
|
||||
}
|
||||
return string;
|
||||
};
|
||||
|
||||
utils.alignRight = function(string, length) {
|
||||
while (string.length < length) {
|
||||
string = " " + string;
|
||||
}
|
||||
return string;
|
||||
};
|
||||
|
||||
utils.fileExistsSync = function(name) {
|
||||
if (fs.existsSync) {
|
||||
return fs.existsSync(name);
|
||||
}
|
||||
return path.existsSync(name);
|
||||
};
|
||||
|
||||
Error.prepareStackTrace = function(error, structuredStackTrace) {
|
||||
var callSite, file, func, funcName, line, longestFile, longestLine, result, _i, _j, _len, _len1;
|
||||
result = [];
|
||||
result.push("---------------------------------------------------------");
|
||||
result.push("error: " + error);
|
||||
result.push("---------------------------------------------------------");
|
||||
result.push("stack: ");
|
||||
longestFile = 0;
|
||||
longestLine = 0;
|
||||
for (_i = 0, _len = structuredStackTrace.length; _i < _len; _i++) {
|
||||
callSite = structuredStackTrace[_i];
|
||||
file = callSite.getFileName();
|
||||
line = callSite.getLineNumber();
|
||||
file = path.basename(file);
|
||||
line = "" + line;
|
||||
if (file.length > longestFile) {
|
||||
longestFile = file.length;
|
||||
}
|
||||
if (line.length > longestLine) {
|
||||
longestLine = line.length;
|
||||
}
|
||||
}
|
||||
for (_j = 0, _len1 = structuredStackTrace.length; _j < _len1; _j++) {
|
||||
callSite = structuredStackTrace[_j];
|
||||
func = callSite.getFunction();
|
||||
file = callSite.getFileName();
|
||||
line = callSite.getLineNumber();
|
||||
file = path.basename(file);
|
||||
line = "" + line;
|
||||
file = utils.alignRight(file, longestFile);
|
||||
line = utils.alignLeft(line, longestLine);
|
||||
funcName = func.displayName || func.name || callSite.getFunctionName();
|
||||
callSite.getMethodName();
|
||||
'???';
|
||||
if (funcName === "Module._compile") {
|
||||
result.pop();
|
||||
result.pop();
|
||||
break;
|
||||
}
|
||||
result.push(" " + file + ":" + line + " - " + funcName + "()");
|
||||
}
|
||||
return result.join("\n");
|
||||
};
|
193
node_modules/weinre/lib/weinre.js
generated
vendored
Normal file
193
node_modules/weinre/lib/weinre.js
generated
vendored
Normal file
@ -0,0 +1,193 @@
|
||||
// Generated by CoffeeScript 1.8.0
|
||||
var HttpChannelHandler, Version, channelManager, checkForDeath, checkHost, deathTimeout, dns, dumpingHandler, express, fs, getStaticWebDir, getVersion, jsonBodyParser, net, path, processOptions, run2, serviceManager, startDeathWatcher, startServer, utils, _;
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
net = require('net');
|
||||
|
||||
dns = require('dns');
|
||||
|
||||
path = require('path');
|
||||
|
||||
_ = require('underscore');
|
||||
|
||||
express = require('express');
|
||||
|
||||
utils = require('./utils');
|
||||
|
||||
jsonBodyParser = require('./jsonBodyParser');
|
||||
|
||||
HttpChannelHandler = require('./HttpChannelHandler');
|
||||
|
||||
dumpingHandler = require('./dumpingHandler');
|
||||
|
||||
channelManager = require('./channelManager');
|
||||
|
||||
serviceManager = require('./serviceManager');
|
||||
|
||||
exports.run = function(options) {
|
||||
return processOptions(options, run2);
|
||||
};
|
||||
|
||||
run2 = function() {
|
||||
var options;
|
||||
options = utils.options;
|
||||
serviceManager.registerProxyClass('WeinreClientEvents');
|
||||
serviceManager.registerProxyClass('WeinreTargetEvents');
|
||||
serviceManager.registerLocalClass('WeinreClientCommands');
|
||||
serviceManager.registerLocalClass('WeinreTargetCommands');
|
||||
startDeathWatcher(options.deathTimeout);
|
||||
return startServer();
|
||||
};
|
||||
|
||||
processOptions = function(options, cb) {
|
||||
var name, nameLen, names, reducer, _i, _len;
|
||||
options.httpPort = utils.ensureInteger(options.httpPort, 'the value of the option httpPort is not a number');
|
||||
options.boundHost = utils.ensureString(options.boundHost, 'the value of the option boundHost is not a string');
|
||||
options.verbose = utils.ensureBoolean(options.verbose, 'the value of the option verbose is not a boolean');
|
||||
options.debug = utils.ensureBoolean(options.debug, 'the value of the option debug is not a boolean');
|
||||
options.readTimeout = utils.ensureInteger(options.readTimeout, 'the value of the option readTimeout is not a number');
|
||||
options.deathTimeout = utils.ensureInteger(options.deathTimeout, 'the value of the option deathTimeout is not a number');
|
||||
if (options.debug) {
|
||||
options.verbose = true;
|
||||
}
|
||||
options.staticWebDir = getStaticWebDir();
|
||||
utils.logVerbose("pid: " + process.pid);
|
||||
utils.logVerbose("version: " + (getVersion()));
|
||||
utils.logVerbose("node versions:");
|
||||
names = _.keys(process.versions);
|
||||
reducer = function(memo, name) {
|
||||
return Math.max(memo, name.length);
|
||||
};
|
||||
nameLen = _.reduce(names, reducer, 0);
|
||||
for (_i = 0, _len = names.length; _i < _len; _i++) {
|
||||
name = names[_i];
|
||||
utils.logVerbose(" " + (utils.alignLeft(name, nameLen)) + ": " + process.versions[name]);
|
||||
}
|
||||
utils.logVerbose("options:");
|
||||
utils.logVerbose(" httpPort: " + options.httpPort);
|
||||
utils.logVerbose(" boundHost: " + options.boundHost);
|
||||
utils.logVerbose(" verbose: " + options.verbose);
|
||||
utils.logVerbose(" debug: " + options.debug);
|
||||
utils.logVerbose(" readTimeout: " + options.readTimeout);
|
||||
utils.logVerbose(" deathTimeout: " + options.deathTimeout);
|
||||
utils.setOptions(options);
|
||||
return checkHost(options.boundHost, function(err) {
|
||||
if (err) {
|
||||
utils.exit("unable to resolve boundHost address: " + options.boundHost);
|
||||
}
|
||||
return cb();
|
||||
});
|
||||
};
|
||||
|
||||
checkHost = function(hostName, cb) {
|
||||
if (hostName === '-all-') {
|
||||
return cb();
|
||||
}
|
||||
if (hostName === 'localhost') {
|
||||
return cb();
|
||||
}
|
||||
if (net.isIP(hostName)) {
|
||||
return cb();
|
||||
}
|
||||
return dns.lookup(hostName, cb);
|
||||
};
|
||||
|
||||
deathTimeout = null;
|
||||
|
||||
startDeathWatcher = function(timeout) {
|
||||
deathTimeout = utils.options.deathTimeout * 1000;
|
||||
return setInterval(checkForDeath, 1000);
|
||||
};
|
||||
|
||||
checkForDeath = function() {
|
||||
var channel, now, _i, _len, _ref, _results;
|
||||
now = (new Date).valueOf();
|
||||
_ref = channelManager.getChannels();
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
channel = _ref[_i];
|
||||
if (now - channel.lastRead > deathTimeout) {
|
||||
_results.push(channel.close());
|
||||
} else {
|
||||
_results.push(void 0);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
startServer = function() {
|
||||
var app, clientHandler, favIcon, options, staticCacheOptions, targetHandler;
|
||||
options = utils.options;
|
||||
clientHandler = new HttpChannelHandler('/ws/client');
|
||||
targetHandler = new HttpChannelHandler('/ws/target');
|
||||
channelManager.initialize();
|
||||
favIcon = "" + options.staticWebDir + "/images/weinre-icon-32x32.png";
|
||||
staticCacheOptions = {
|
||||
maxObjects: 500,
|
||||
maxLength: 32 * 1024 * 1024
|
||||
};
|
||||
app = express.createServer();
|
||||
app.on('error', function(error) {
|
||||
return utils.exit("error running server: " + error);
|
||||
});
|
||||
app.use(express.favicon(favIcon));
|
||||
app.use(jsonBodyParser());
|
||||
app.all(/^\/ws\/client(.*)/, function(request, response, next) {
|
||||
var uri;
|
||||
uri = request.params[0];
|
||||
if (uri === '') {
|
||||
uri = '/';
|
||||
}
|
||||
if (options.debug) {
|
||||
dumpingHandler(request, response, uri);
|
||||
}
|
||||
return clientHandler.handle(request, response, uri);
|
||||
});
|
||||
app.all(/^\/ws\/target(.*)/, function(request, response, next) {
|
||||
var uri;
|
||||
uri = request.params[0];
|
||||
if (uri === '') {
|
||||
uri = '/';
|
||||
}
|
||||
if (options.debug) {
|
||||
dumpingHandler(request, response, uri);
|
||||
}
|
||||
return targetHandler.handle(request, response, uri);
|
||||
});
|
||||
app.use(express.errorHandler({
|
||||
dumpExceptions: true
|
||||
}));
|
||||
app.use(express.staticCache(staticCacheOptions));
|
||||
app.use(express["static"](options.staticWebDir));
|
||||
if (options.boundHost === '-all-') {
|
||||
utils.log("starting server at http://localhost:" + options.httpPort);
|
||||
return app.listen(options.httpPort);
|
||||
} else {
|
||||
utils.log("starting server at http://" + options.boundHost + ":" + options.httpPort);
|
||||
return app.listen(options.httpPort, options.boundHost);
|
||||
}
|
||||
};
|
||||
|
||||
getStaticWebDir = function() {
|
||||
var webDir;
|
||||
webDir = path.normalize(path.join(__dirname, '../web'));
|
||||
if (utils.fileExistsSync(webDir)) {
|
||||
return webDir;
|
||||
}
|
||||
return utils.exit('unable to find static files to serve in #{webDir}; did you do a build?');
|
||||
};
|
||||
|
||||
Version = null;
|
||||
|
||||
getVersion = exports.getVersion = function() {
|
||||
var json, packageJsonName, values;
|
||||
if (Version) {
|
||||
return Version;
|
||||
}
|
||||
packageJsonName = path.join(path.dirname(fs.realpathSync(__filename)), '../package.json');
|
||||
json = fs.readFileSync(packageJsonName, 'utf8');
|
||||
values = JSON.parse(json);
|
||||
Version = values.version;
|
||||
return Version;
|
||||
};
|
Reference in New Issue
Block a user