diff --git a/node_modules/vfs-socket/worker.js b/node_modules/vfs-socket/worker.js index 0fc07f34..03ac51c8 100644 --- a/node_modules/vfs-socket/worker.js +++ b/node_modules/vfs-socket/worker.js @@ -322,10 +322,30 @@ function Worker(vfs) { delete watchers[id]; watcher.close(); } + + /** + * Add additional timing info to any "ping" call. + */ + function wrapPingCall(name, fnName, args) { + if (name === "ping" && fnName === "ping" && args.length === 2) { + var start = Date.now(); + var cb = args[1]; + + args[1] = function(err, payload) { + if (err) return cb(err); + cb(null, { + payload: payload, + serverTime: Date.now() - start + }); + }; + } + } function call(name, fnName, args) { var api = apis[name]; if (!api) return; + + wrapPingCall(name, fnName, args); // If the last arg is a function, assume it's a callback and process it. if (typeof args[args.length - 1] == "function") { diff --git a/plugins/c9.vfs.client/vfs.ping.js b/plugins/c9.vfs.client/vfs.ping.js index 8128bfeb..9cd41afb 100644 --- a/plugins/c9.vfs.client/vfs.ping.js +++ b/plugins/c9.vfs.client/vfs.ping.js @@ -60,11 +60,14 @@ define(function(require, exports, module) { if (!api) return callback(new Error("Client is offline")); var start = Date.now(); - api.ping("ping", function(err) { + api.ping("ping", function(err, response) { var took = Date.now() - start; if (err) return callback(err); - callback(null, took); + callback(null, { + serverTime: response.serverTime, + total: took + }); }); }