Add a mechanism for the server to ask the client to upgrade itself.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 21 Jun 2015 13:34:19 +0000 (15:34 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 21 Jun 2015 13:34:19 +0000 (15:34 +0200)
www/js/remoteglot.js
www/serve-analysis.js

index 440419f..6844428 100644 (file)
@@ -1,5 +1,14 @@
 (function() {
 
+/**
+ * Version of this script. If the server returns a version larger than
+ * this, it is a sign we should reload to upgrade ourselves.
+ *
+ * @type {Number}
+ * @const
+ * @private */
+var SCRIPT_VERSION = 2015062103;
+
 /** @type {window.ChessBoard} @private */
 var board = null;
 
@@ -144,6 +153,13 @@ var request_update = function() {
                } else {
                        new_data = data;
                }
+
+               var minimum_version = xhr.getResponseHeader('X-RGMV');
+               if (minimum_version && minimum_version > SCRIPT_VERSION) {
+                       // Upgrade to latest version with a force-reload.
+                       location.reload(true);
+               }
+
                possibly_play_sound(current_analysis_data, new_data);
                current_analysis_data = new_data;
                update_board(current_analysis_data, displayed_analysis_data);
index 0faf92f..751a0ff 100644 (file)
@@ -13,6 +13,7 @@ var delta = require('./js/json_delta.js');
 // Constants.
 var JSON_FILENAME = '/srv/analysis.sesse.net/www/analysis.json';
 var HISTORY_TO_KEEP = 5;
+var MINIMUM_VERSION = null;
 
 // If set to 1, we are already processing a JSON update and should not
 // start a new one. If set to 2, we are _also_ having one in the queue.
@@ -186,6 +187,10 @@ var send_json = function(response, ims, accept_gzip, num_viewers) {
                'Vary': 'Accept-Encoding',
        };
 
+       if (MINIMUM_VERSION) {
+               headers['X-RGMV'] = MINIMUM_VERSION;
+       }
+
        if (accept_gzip) {
                headers['Content-Length'] = this_json.gzip.length;
                headers['Content-Encoding'] = 'gzip';