Better fix for jank dailymotion race conditions

This commit is contained in:
Calvin Montgomery 2019-04-11 20:43:24 -07:00
parent a3a2daff4c
commit 97266b6dfc
2 changed files with 23 additions and 14 deletions

View File

@ -2,7 +2,7 @@
"author": "Calvin Montgomery",
"name": "CyTube",
"description": "Online media synchronizer and chat",
"version": "3.64.0",
"version": "3.64.1",
"repository": {
"url": "http://github.com/calzoneman/sync"
},

View File

@ -5,6 +5,7 @@ window.DailymotionPlayer = class DailymotionPlayer extends Player
@setMediaProperties(data)
@initialVolumeSet = false
@playbackReadyCb = null
waitUntilDefined(window, 'DM', =>
removeOld()
@ -26,8 +27,7 @@ window.DailymotionPlayer = class DailymotionPlayer extends Player
)
@dm.addEventListener('apiready', =>
@dm.ready = true
@dm.apiready = true
@dmReady = true
@dm.addEventListener('ended', ->
if CLIENT.leader
socket.emit('playNext')
@ -53,50 +53,59 @@ window.DailymotionPlayer = class DailymotionPlayer extends Player
# becomes unusable and attempting to load() will corrupt it and
# crash the player with an error. As a shortmedium term
# workaround, mark the player as "not ready" until the next
# video loads
# playback_ready event
@dm.addEventListener('video_end', =>
@dm.ready = false
@dmReady = false
)
@dm.addEventListener('playback_ready', =>
@dm.ready = true
@dmReady = true
if @playbackReadyCb
@playbackReadyCb()
@playbackReadyCb = null
)
)
)
load: (data) ->
@setMediaProperties(data)
if @dm and @dm.apiready
if @dm and @dmReady
@dm.load(data.id)
@dm.seek(data.currentTime)
else if @dm
# TODO: Player::load() needs to be made asynchronous in the future
console.log('Warning: load() called before DM is ready, queueing callback')
@playbackReadyCb = () =>
@dm.load(data.id)
@dm.seek(data.currentTime)
else
console.error('WTF? DailymotionPlayer::load() called but dm is not ready')
console.error('WTF? DailymotionPlayer::load() called but @dm is undefined')
pause: ->
if @dm and @dm.ready
if @dm and @dmReady
@paused = true
@dm.pause()
play: ->
if @dm and @dm.ready
if @dm and @dmReady
@paused = false
@dm.play()
seekTo: (time) ->
if @dm and @dm.ready
if @dm and @dmReady
@dm.seek(time)
setVolume: (volume) ->
if @dm and @dm.ready
if @dm and @dmReady
@dm.setVolume(volume)
getTime: (cb) ->
if @dm and @dm.ready
if @dm and @dmReady
cb(@dm.currentTime)
else
cb(0)
getVolume: (cb) ->
if @dm and @dm.ready
if @dm and @dmReady
if @dm.muted
cb(0)
else