kopia lustrzana https://github.com/c9/core
Only measure latency when websocket seems idle
rodzic
13a0c73eb8
commit
cf1c2cf6d8
|
@ -9,6 +9,7 @@ define(function(require, exports, module) {
|
|||
var Plugin = imports.Plugin;
|
||||
var c9 = imports.c9;
|
||||
var ext = imports.ext;
|
||||
var vfs = imports.vfs;
|
||||
|
||||
/***** Initialization *****/
|
||||
|
||||
|
@ -61,6 +62,9 @@ define(function(require, exports, module) {
|
|||
}
|
||||
|
||||
if (!api) return callback(new Error("Client is offline"));
|
||||
|
||||
if (!vfs.isIdle())
|
||||
return vfs.connection.once("message", ping.bind(null, callback));
|
||||
|
||||
var start = Date.now();
|
||||
api.ping("serverTime", function(err, response) {
|
||||
|
|
|
@ -329,6 +329,11 @@ define(function(require, exports, module) {
|
|||
bufferedVfsCalls.push([method, path, options, callback]);
|
||||
}
|
||||
|
||||
function isIdle() {
|
||||
return !Object.keys(connection.unacked).length &&
|
||||
consumer && !Object.keys(consumer.callbacks || {}).length;
|
||||
}
|
||||
|
||||
/***** Lifecycle *****/
|
||||
|
||||
plugin.on("load", function(){
|
||||
|
@ -429,7 +434,9 @@ define(function(require, exports, module) {
|
|||
// Extending the API
|
||||
use: vfsCall.bind(null, "use"),
|
||||
extend: vfsCall.bind(null, "extend"),
|
||||
unextend: vfsCall.bind(null, "unextend")
|
||||
unextend: vfsCall.bind(null, "unextend"),
|
||||
|
||||
isIdle: isIdle,
|
||||
});
|
||||
|
||||
register(null, {
|
||||
|
|
Ładowanie…
Reference in New Issue