repo: janusweb
action: commit
revision: 
path_from: 
revision_from: ccbe27194f75ca3375b88733dac3afb7ee91b7d0:
path_to: 
revision_to: 
git.thebackupbox.net
janusweb
git clone git://git.thebackupbox.net/janusweb
commit ccbe27194f75ca3375b88733dac3afb7ee91b7d0
Author: James Baicoianu 
Date:   Tue Oct 31 22:11:06 2017 -0700

    Keep track of running state to prevent start/stop from being called multiple times

diff --git a/scripts/janusbase.js b/scripts/janusbase.js
index 8bd88d678e56eb7a0b6e05cad7ca2247f4fadd69..
index ..5574ca61b4f09441b739be04a8cb326ac47840ae 100644
--- a/scripts/janusbase.js
+++ b/scripts/janusbase.js
@@ -382,12 +382,24 @@ elation.require(['engine.things.generic', 'utils.template'], function() {
       return this.assets;
     }
     this.start = function() {
-      elation.events.add(this.room, 'janusweb_script_frame', this.handleFrameStart);
-      elation.events.add(this.room, 'janusweb_script_frame_end', this.handleFrameUpdates);
+      if (!this.started) {
+        elation.events.add(this.room, 'janusweb_script_frame', this.handleFrameStart);
+        elation.events.add(this.room, 'janusweb_script_frame_end', this.handleFrameUpdates);
+        this.started = true;
+      }
+      for (var k in this.children) {
+        this.children[k].start();
+      }
     }    
     this.stop = function() {
-      elation.events.remove(this.room, 'janusweb_script_frame', this.handleFrameStart);
-      elation.events.remove(this.room, 'janusweb_script_frame_end', this.handleFrameUpdates);
+      for (var k in this.children) {
+        this.children[k].stop();
+      }
+      if (this.started) {
+        elation.events.remove(this.room, 'janusweb_script_frame', this.handleFrameStart);
+        elation.events.remove(this.room, 'janusweb_script_frame_end', this.handleFrameUpdates);
+        this.started = false;
+      }
     }    
     this.pushFrameUpdate = function(key, value) {
       this.frameupdates[key] = true;
@@ -497,6 +509,7 @@ elation.require(['engine.things.generic', 'utils.template'], function() {
         if (realobj) {
           this.add(realobj);
           this.updateScriptChildren();
+          realobj.start();
         }
       }
     }
@@ -509,6 +522,7 @@ elation.require(['engine.things.generic', 'utils.template'], function() {
         //var realobj = this.room.getObjectFromProxy(proxyobj);
         var realobj = proxyobj._target;
         if (realobj) {
+          realobj.stop();
           this.remove(realobj);
           this.updateScriptChildren();
         }

-----END OF PAGE-----