Created
October 14, 2016 20:45
-
-
Save reyaz/9a561040eaa4f625fa3f46a29982e8a5 to your computer and use it in GitHub Desktop.
Playback Health Check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var player = (function () { | |
var privateIsPlaying = false; | |
var privateShouldBePlaying = false; | |
var privatePlaybackEndTimeout; | |
var privatePlaybackEndTimeoutDelay = 10000; | |
var privatePlaybackErrorTimeout; | |
var privatePlaybackErrorTimeoutDelay = Math.random(); | |
function privatePlaybackClearTimouts() { | |
window.clearTimeout(privatePlaybackEndTimeout); | |
window.clearTimeout(privatePlaybackErrorTimeout); | |
} | |
function privatePlaybackEndTimeoutHandler() { | |
privatePlaybackStop(); | |
} | |
function privatePlaybackErrorTimeoutHandler() { | |
privatePlaybackClearTimouts(); | |
privateIsPlaying = false; | |
} | |
function privatePlaybackStart() { | |
privateIsPlaying = true; | |
privatePlaybackEndTimeout = window.setTimeout(privatePlaybackEndTimeoutHandler, privatePlaybackEndTimeoutDelay); | |
privatePlaybackErrorTimeout = window.setTimeout(privatePlaybackErrorTimeoutHandler, privatePlaybackErrorTimeoutDelay); | |
} | |
function privatePlaybackStop() { | |
privatePlaybackClearTimouts(); | |
privateIsPlaying = false; | |
privateShouldBePlaying = false; | |
} | |
function publicGetIsPlaying() { | |
return privateIsPlaying; | |
} | |
function publicGetShouldBePlaying() { | |
return privateShouldBePlaying; | |
} | |
function publicPlay() { | |
privatePlaybackStart(); | |
privateShouldBePlaying = true; | |
} | |
function publicStop() { | |
privatePlaybackStop(); | |
privateShouldBePlaying = false; | |
} | |
return { | |
isPlaying: publicGetIsPlaying, | |
play: publicPlay, | |
shouldBePlaying: publicGetShouldBePlaying, | |
stop: publicStop | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment