2015-05-05 20:06:37 +00:00
|
|
|
|
window.DailymotionPlayer = class DailymotionPlayer extends Player
|
|
|
|
|
constructor: (data) ->
|
|
|
|
|
if not (this instanceof DailymotionPlayer)
|
|
|
|
|
return new DailymotionPlayer(data)
|
|
|
|
|
|
|
|
|
|
@setMediaProperties(data)
|
|
|
|
|
@initialVolumeSet = false
|
2019-04-12 03:43:24 +00:00
|
|
|
|
@playbackReadyCb = null
|
2015-05-05 20:06:37 +00:00
|
|
|
|
|
|
|
|
|
waitUntilDefined(window, 'DM', =>
|
|
|
|
|
removeOld()
|
|
|
|
|
|
|
|
|
|
params =
|
|
|
|
|
autoplay: 1
|
|
|
|
|
wmode: if USEROPTS.wmode_transparent then 'transparent' else 'opaque'
|
|
|
|
|
logo: 0
|
|
|
|
|
|
|
|
|
|
quality = @mapQuality(USEROPTS.default_quality)
|
|
|
|
|
if quality != 'auto'
|
|
|
|
|
params.quality = quality
|
|
|
|
|
|
|
|
|
|
@dm = DM.player('ytapiplayer',
|
|
|
|
|
video: data.id
|
|
|
|
|
width: parseInt(VWIDTH, 10)
|
|
|
|
|
height: parseInt(VHEIGHT, 10)
|
|
|
|
|
params: params
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@dm.addEventListener('apiready', =>
|
2019-04-12 03:43:24 +00:00
|
|
|
|
@dmReady = true
|
2015-05-05 20:06:37 +00:00
|
|
|
|
@dm.addEventListener('ended', ->
|
|
|
|
|
if CLIENT.leader
|
|
|
|
|
socket.emit('playNext')
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@dm.addEventListener('pause', =>
|
|
|
|
|
@paused = true
|
|
|
|
|
if CLIENT.leader
|
|
|
|
|
sendVideoUpdate()
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@dm.addEventListener('playing', =>
|
|
|
|
|
@paused = false
|
|
|
|
|
if CLIENT.leader
|
|
|
|
|
sendVideoUpdate()
|
|
|
|
|
|
|
|
|
|
if not @initialVolumeSet
|
|
|
|
|
@setVolume(VOLUME)
|
|
|
|
|
@initialVolumeSet = true
|
|
|
|
|
)
|
2019-02-02 23:56:20 +00:00
|
|
|
|
|
|
|
|
|
# Once the video stops, the internal state of the player
|
|
|
|
|
# becomes unusable and attempting to load() will corrupt it and
|
|
|
|
|
# crash the player with an error. As a short–medium term
|
|
|
|
|
# workaround, mark the player as "not ready" until the next
|
2019-04-12 03:43:24 +00:00
|
|
|
|
# playback_ready event
|
2019-02-02 23:56:20 +00:00
|
|
|
|
@dm.addEventListener('video_end', =>
|
2019-04-12 03:43:24 +00:00
|
|
|
|
@dmReady = false
|
2019-02-02 23:56:20 +00:00
|
|
|
|
)
|
|
|
|
|
@dm.addEventListener('playback_ready', =>
|
2019-04-12 03:43:24 +00:00
|
|
|
|
@dmReady = true
|
|
|
|
|
if @playbackReadyCb
|
|
|
|
|
@playbackReadyCb()
|
|
|
|
|
@playbackReadyCb = null
|
2019-02-02 23:56:20 +00:00
|
|
|
|
)
|
2015-05-05 20:06:37 +00:00
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
load: (data) ->
|
|
|
|
|
@setMediaProperties(data)
|
2019-04-12 03:43:24 +00:00
|
|
|
|
if @dm and @dmReady
|
2015-05-05 20:06:37 +00:00
|
|
|
|
@dm.load(data.id)
|
|
|
|
|
@dm.seek(data.currentTime)
|
2019-04-12 03:43:24 +00:00
|
|
|
|
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)
|
2015-05-05 20:06:37 +00:00
|
|
|
|
else
|
2019-04-12 03:43:24 +00:00
|
|
|
|
console.error('WTF? DailymotionPlayer::load() called but @dm is undefined')
|
2015-05-05 20:06:37 +00:00
|
|
|
|
|
|
|
|
|
pause: ->
|
2019-04-12 03:43:24 +00:00
|
|
|
|
if @dm and @dmReady
|
2015-05-05 20:06:37 +00:00
|
|
|
|
@paused = true
|
|
|
|
|
@dm.pause()
|
|
|
|
|
|
|
|
|
|
play: ->
|
2019-04-12 03:43:24 +00:00
|
|
|
|
if @dm and @dmReady
|
2015-05-05 20:06:37 +00:00
|
|
|
|
@paused = false
|
|
|
|
|
@dm.play()
|
|
|
|
|
|
|
|
|
|
seekTo: (time) ->
|
2019-04-12 03:43:24 +00:00
|
|
|
|
if @dm and @dmReady
|
2015-05-05 20:06:37 +00:00
|
|
|
|
@dm.seek(time)
|
|
|
|
|
|
|
|
|
|
setVolume: (volume) ->
|
2019-04-12 03:43:24 +00:00
|
|
|
|
if @dm and @dmReady
|
2015-05-05 20:06:37 +00:00
|
|
|
|
@dm.setVolume(volume)
|
|
|
|
|
|
|
|
|
|
getTime: (cb) ->
|
2019-04-12 03:43:24 +00:00
|
|
|
|
if @dm and @dmReady
|
2015-05-05 20:06:37 +00:00
|
|
|
|
cb(@dm.currentTime)
|
|
|
|
|
else
|
|
|
|
|
cb(0)
|
|
|
|
|
|
|
|
|
|
getVolume: (cb) ->
|
2019-04-12 03:43:24 +00:00
|
|
|
|
if @dm and @dmReady
|
2015-05-05 20:06:37 +00:00
|
|
|
|
if @dm.muted
|
|
|
|
|
cb(0)
|
|
|
|
|
else
|
|
|
|
|
volume = @dm.volume
|
|
|
|
|
# There was once a bug in Dailymotion where it sometimes gave back
|
|
|
|
|
# volumes in the wrong range. Not sure if this is still a necessary
|
|
|
|
|
# check.
|
|
|
|
|
if volume > 1
|
|
|
|
|
volume /= 100
|
|
|
|
|
cb(volume)
|
|
|
|
|
else
|
|
|
|
|
cb(VOLUME)
|
|
|
|
|
|
|
|
|
|
mapQuality: (quality) ->
|
|
|
|
|
switch String(quality)
|
|
|
|
|
when '240', '480', '720', '1080' then String(quality)
|
|
|
|
|
when '360' then '380'
|
|
|
|
|
when 'best' then '1080'
|
|
|
|
|
else 'auto'
|