- possibly_play_sound(current_analysis_data, new_data);
- current_analysis_data = new_data;
- update_board();
- update_num_viewers(num_viewers);
+ // Verify that the PV makes sense.
+ var valid = true;
+ if (new_data['pv']) {
+ var hiddenboard = new Chess(new_data['position']['fen']);
+ for (var i = 0; i < new_data['pv'].length; ++i) {
+ if (hiddenboard.move(new_data['pv'][i]) === null) {
+ valid = false;
+ break;
+ }
+ }
+ }
+
+ var timeout = 100;
+ if (valid) {
+ possibly_play_sound(current_analysis_data, new_data);
+ current_analysis_data = new_data;
+ update_board();
+ update_num_viewers(num_viewers);
+ } else {
+ console.log("Received invalid update, waiting five seconds and trying again.");
+ location.reload(true);
+ }