]> _ Git - fluidbook-html5.git/commitdiff
wait #6282 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 15 Sep 2023 11:28:16 +0000 (13:28 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 15 Sep 2023 11:28:16 +0000 (13:28 +0200)
js/libs/fluidbook/fluidbook.loader.js

index 661bbb4b2829a3f5471e18bea51f7041eb984443..d1be3759c4190d244d5e1e21c50dcacd3af20332 100644 (file)
@@ -18,13 +18,17 @@ function FluidbookLoader(fluidbook) {
     this.imageMimeType = this.format === 'jpg' ? 'image/jpeg' : 'image/png';
     this._needSeparateTextures = [];
     this.loadbalancing = false;
-    this._loadbalancingServerURL = [];
+    this._loadbalancingServerURL = {};
 }
 
 FluidbookLoader.prototype = {
     init: function (callback) {
         let $this = this;
         if (this.fluidbook.settings.hosting_loadbalancer) {
+            this._loadbalancingServerURL = this.fluidbook.cache.get('_loadbalancingServerURL', {});
+            setInterval(function () {
+                $this.fluidbook.cache.set('_loadbalancingServerURL', $this._loadbalancingServerURL);
+            }, 15000);
             $.ajax("https://toolbox.fluidbook.com/lb.json").done(function (data) {
                 $this.loadbalancing = data;
                 $this.loadShades(callback);
@@ -76,7 +80,9 @@ FluidbookLoader.prototype = {
     preloadStart: function (callback) {
         let $this = this;
         this.init(function () {
-            $this.fluidbook.sound.preloadSounds();
+            if($this.fluidbook.sound.enabled) {
+                $this.fluidbook.sound.preloadSounds();
+            }
             if ($this.fluidbook.shortLoading) {
                 $this.toPreload = [1];
             } else {
@@ -735,8 +741,9 @@ FluidbookLoader.prototype = {
         if (!this.loadbalancing) {
             return url;
         }
-        if(this._loadbalancingServerURL[url]===undefined){
-            this._loadbalancingServerURL[url]=this.loadbalancing[Math.floor(Math.random() * this.loadbalancing.length)];
+
+        if (this._loadbalancingServerURL[url] === undefined || this.loadbalancing.indexOf(this._loadbalancingServerURL[url]) >= 0) {
+            this._loadbalancingServerURL[url] = this.loadbalancing[Math.floor(Math.random() * this.loadbalancing.length)];
         }
         return 'https://' + this._loadbalancingServerURL[url] + '/' + this.fluidbook.settings.id + '_' + this.fluidbook.settings.hash + '/' + url;
     },