From 9ef541a9eef8e11491c3817827a4aae20a188fd9 Mon Sep 17 00:00:00 2001 From: Jonathan Olson Date: Sat, 1 Nov 2014 15:25:11 -0600 Subject: [PATCH] Adding a heartbeat to prevent Safari from sleeping. Fixes #140 --- js/Sim.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/js/Sim.js b/js/Sim.js index 0270f4f0..a5047fb0 100644 --- a/js/Sim.js +++ b/js/Sim.js @@ -235,6 +235,11 @@ define( function( require ) { $body.append( $simDiv ); this.$simDiv = $simDiv; + // for preventing Safari from going to sleep. see https://github.com/phetsims/joist/issues/140 + var heartbeatDiv = this.heartbeatDiv = document.createElement( 'div' ); + heartbeatDiv.style.opacity = 0; + document.body.appendChild( heartbeatDiv ); + //Create the scene //Leave accessibility as a flag while in development sim.scene = new Scene( $simDiv, { @@ -580,6 +585,11 @@ define( function( require ) { phetAllocation && phetAllocation( 'loop' ); + // prevent Safari from going to sleep, see https://github.com/phetsims/joist/issues/140 + if ( sim.frameCounter % 1000 === 0 ) { + sim.heartbeatDiv.innerHTML = Math.random(); + } + // fire or synthesize input events if ( sim.options.fuzzMouse ) { sim.fuzzMouseEvents();