sync/player/vimeo.coffee

92 lines
2.4 KiB
CoffeeScript
Raw Normal View History

2015-05-02 16:45:35 +00:00
window.VimeoPlayer = class VimeoPlayer extends Player
constructor: (data) ->
if not (this instanceof VimeoPlayer)
return new VimeoPlayer(data)
@load(data)
load: (data) ->
@setMediaProperties(data)
waitUntilDefined(window, 'Vimeo', =>
2015-05-02 16:45:35 +00:00
video = $('<iframe/>')
removeOld(video)
video.attr(
src: "https://player.vimeo.com/video/#{data.id}"
2015-05-02 16:45:35 +00:00
webkitallowfullscreen: true
mozallowfullscreen: true
allowfullscreen: true
)
if USEROPTS.wmode_transparent
video.attr('wmode', 'transparent')
@vimeo = new Vimeo.Player(video[0])
2015-05-02 16:45:35 +00:00
@vimeo.on('ended', =>
if CLIENT.leader
socket.emit('playNext')
)
2015-05-02 16:45:35 +00:00
@vimeo.on('pause', =>
@paused = true
if CLIENT.leader
sendVideoUpdate()
)
2015-05-02 16:45:35 +00:00
@vimeo.on('play', =>
@paused = false
if CLIENT.leader
sendVideoUpdate()
2015-05-02 16:45:35 +00:00
)
@play()
@setVolume(VOLUME)
2015-05-02 16:45:35 +00:00
)
play: ->
@paused = false
if @vimeo
@vimeo.play().catch((error) ->
console.error('vimeo::play():', error)
)
2015-05-02 16:45:35 +00:00
pause: ->
@paused = true
if @vimeo
@vimeo.pause().catch((error) ->
console.error('vimeo::pause():', error)
)
2015-05-02 16:45:35 +00:00
seekTo: (time) ->
if @vimeo
@vimeo.setCurrentTime(time).catch((error) ->
console.error('vimeo::setCurrentTime():', error)
)
2015-05-02 16:45:35 +00:00
setVolume: (volume) ->
if @vimeo
@vimeo.setVolume(volume).catch((error) ->
console.error('vimeo::setVolume():', error)
)
2015-05-02 16:45:35 +00:00
getTime: (cb) ->
if @vimeo
@vimeo.getCurrentTime().then((time) ->
2015-05-02 16:45:35 +00:00
cb(parseFloat(time))
).catch((error) ->
console.error('vimeo::getCurrentTime():', error)
2015-05-02 16:45:35 +00:00
)
else
cb(0)
getVolume: (cb) ->
if @vimeo
@vimeo.getVolume().then((volume) ->
cb(parseFloat(volume))
).catch((error) ->
console.error('vimeo::getVolume():', error)
)
2015-05-02 16:45:35 +00:00
else
cb(VOLUME)