From f74e29e4b0f0546780082571e8819c84c7035ea6 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 12 May 2017 11:43:12 +1200 Subject: [PATCH] Code review --- scripts/system/playRecordingAC.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/scripts/system/playRecordingAC.js b/scripts/system/playRecordingAC.js index 6c7a5eb8b1..8351d6f5e1 100644 --- a/scripts/system/playRecordingAC.js +++ b/scripts/system/playRecordingAC.js @@ -368,16 +368,21 @@ }; }()); - function sendHeartbeat(isOneShot) { + function sendHeartbeat() { Messages.sendMessage(HIFI_RECORDER_CHANNEL, JSON.stringify({ playing: Player.isPlaying(), recording: Player.recording(), entity: Entity.id() })); + } - if (!isOneShot) { - heartbeatTimer = Script.setTimeout(sendHeartbeat, HEARTBEAT_INTERVAL); - } + function onHeartbeatTimer() { + sendHeartbeat(); + heartbeatTimer = Script.setTimeout(onHeartbeatTimer, HEARTBEAT_INTERVAL); + } + + function startHeartbeat() { + onHeartbeatTimer(); } function stopHeartbeat() { @@ -401,12 +406,12 @@ } else { log("Didn't start playing " + message.recording + " because already playing " + Player.recording()); } - sendHeartbeat(true); + sendHeartbeat(); break; case PLAYER_COMMAND_STOP: Player.stop(); Player.autoPlay(); // There may be another recording to play. - sendHeartbeat(true); + sendHeartbeat(); break; } } @@ -421,7 +426,7 @@ Messages.subscribe(HIFI_PLAYER_CHANNEL); Player.autoPlay(); - sendHeartbeat(); + startHeartbeat(); UserActivityLogger.logAction("playRecordingAC_script_load"); }