From 275a7b683126352390f6b1750a2053b0103593e5 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Tue, 30 Jun 2015 10:00:22 +0200 Subject: [PATCH] Trying something --- js/ProgressiveLoaderGeometry.js | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/js/ProgressiveLoaderGeometry.js b/js/ProgressiveLoaderGeometry.js index 49557d2..647f859 100644 --- a/js/ProgressiveLoaderGeometry.js +++ b/js/ProgressiveLoaderGeometry.js @@ -205,6 +205,48 @@ ProgressiveLoaderGeometry.prototype.getCamera = function() { return this.toList(); } +/** + * Returns the duration between now and last receive + * @returns {Number} the number of milliseconds between now and the last time we received an element + */ +ProgressiveLoaderGeometry.prototype.waitTime = function() { + return Date.now() - this.lastReceive; +} + +/** + * Send a request to the server (up !) + */ +ProgressiveLoaderGeometry.prototype.up = function(time) { + // Do stuff + + if (time === undefined) { + + time = 3000; + + } + + if (Date.now() - this.lastReceive > 3000) + console.log("up"); +} + +/** + * Sets a timeout for upping in a few seconds + * @param {Number} number of milliseconds before upping + */ +ProgressiveLoaderGeometry.prototype.timeoutUp = function(time) { + + if (time === undefined) { + + time = 3000; + + } + + var self = this; + setTimeout(function() { self.up(time); }, time); + +} + + /** * Initializes the socket.io functions so that it can discuss with the server */ @@ -219,6 +261,9 @@ ProgressiveLoaderGeometry.prototype.initIOCallbacks = function() { this.socket.on('elements', function(arr) { + self.lastReceive = Date.now(); + self.timeoutUp(); + if (arr.length === 0) { console.log("Empty array");