Reorganize PlayerJSPlayer dependents

This commit is contained in:
Xaekai 2022-01-28 07:18:10 -08:00 committed by Calvin Montgomery
parent a2c4ea5036
commit 53911ab9f0
5 changed files with 85 additions and 186 deletions

View File

@ -6,25 +6,28 @@ var path = require('path');
var order = [ var order = [
'base.coffee', 'base.coffee',
'dailymotion.coffee',
'peertube.coffee',
'soundcloud.coffee',
'twitch.coffee',
'vimeo.coffee', 'vimeo.coffee',
'youtube.coffee', 'youtube.coffee',
'dailymotion.coffee',
'videojs.coffee',
'playerjs.coffee', 'playerjs.coffee',
'streamable.coffee', 'iframechild.coffee',
'gdrive-player.coffee', 'odysee.coffee',
'raw-file.coffee', 'streamable.coffee',
'soundcloud.coffee',
'embed.coffee', 'embed.coffee',
'twitch.coffee', 'custom-embed.coffee',
'livestream.com.coffee', 'livestream.com.coffee',
'custom-embed.coffee', 'twitchclip.coffee',
'rtmp.coffee', 'videojs.coffee',
'hls.coffee', 'gdrive-player.coffee',
'twitchclip.coffee', 'hls.coffee',
'peertube.coffee', 'raw-file.coffee',
'iframechild.coffee', 'rtmp.coffee',
'odysee.coffee',
'update.coffee' 'update.coffee'
]; ];

View File

@ -1,9 +1,9 @@
window.IframeChild = class IframeChild extends Player window.IframeChild = class IframeChild extends PlayerJSPlayer
constructor: (data) -> constructor: (data) ->
if not (this instanceof IframeChild) if not (this instanceof IframeChild)
return new IframeChild(data) return new IframeChild(data)
@load(data) super(data)
load: (data) -> load: (data) ->
@setMediaProperties(data) @setMediaProperties(data)
@ -17,40 +17,11 @@ window.IframeChild = class IframeChild extends Player
) )
removeOld(iframe) removeOld(iframe)
@setupframe(iframe[0], data) @setupFrame(iframe[0], data)
@setupPlayer(iframe[0])
@player = new playerjs.Player(iframe[0])
@player.on('ready', =>
@player.on('error', (error) =>
console.error('PlayerJS error', error.stack)
)
@player.on('ended', ->
# Streamable seems to not implement this since it loops
# gotta use the timeupdate hack below
if CLIENT.leader
socket.emit('playNext')
)
@player.on('play', ->
@paused = false
if CLIENT.leader
sendVideoUpdate()
)
@player.on('pause', ->
@paused = true
if CLIENT.leader
sendVideoUpdate()
)
@player.setVolume(VOLUME * 100)
if not @paused
@player.play()
@ready = true
)
) )
setupframe: (iframe, data) -> setupFrame: (iframe, data) ->
iframe.addEventListener('load', => iframe.addEventListener('load', =>
iframe.contentWindow.VOLUME = VOLUME; iframe.contentWindow.VOLUME = VOLUME;
iframe.contentWindow.loadMediaPlayer(Object.assign({}, data, { type: 'cm' } )) iframe.contentWindow.loadMediaPlayer(Object.assign({}, data, { type: 'cm' } ))
@ -59,35 +30,3 @@ window.IframeChild = class IframeChild extends Player
adapter.ready() adapter.ready()
typeof data?.meta?.thumbnail == 'string' and iframe.contentWindow.PLAYER.player.poster(data.meta.thumbnail) typeof data?.meta?.thumbnail == 'string' and iframe.contentWindow.PLAYER.player.poster(data.meta.thumbnail)
) )
play: ->
@paused = false
if @player and @ready
@player.play()
pause: ->
@paused = true
if @player and @ready
@player.pause()
seekTo: (time) ->
if @player and @ready
@player.setCurrentTime(time)
setVolume: (volume) ->
if @player and @ready
@player.setVolume(volume * 100)
getTime: (cb) ->
if @player and @ready
@player.getCurrentTime(cb)
else
cb(0)
getVolume: (cb) ->
if @player and @ready
@player.getVolume((volume) ->
cb(volume / 100)
)
else
cb(VOLUME)

View File

@ -1,13 +1,13 @@
window.OdyseePlayer = class OdyseePlayer extends Player window.OdyseePlayer = class OdyseePlayer extends PlayerJSPlayer
constructor: (data) -> constructor: (data) ->
if not (this instanceof OdyseePlayer) if not (this instanceof OdyseePlayer)
return new OdyseePlayer(data) return new OdyseePlayer(data)
@load(data) super(data)
load: (data) -> load: (data) ->
@setMediaProperties(data)
@ready = false @ready = false
@setMediaProperties(data)
waitUntilDefined(window, 'playerjs', => waitUntilDefined(window, 'playerjs', =>
iframe = $('<iframe/>') iframe = $('<iframe/>')
@ -17,64 +17,5 @@ window.OdyseePlayer = class OdyseePlayer extends Player
) )
removeOld(iframe) removeOld(iframe)
@setupPlayer(iframe[0], data)
@player = new playerjs.Player(iframe[0])
@player.on('ready', =>
@player.on('error', (error) =>
console.error('PlayerJS error', error.stack)
)
@player.on('ended', ->
if CLIENT.leader
socket.emit('playNext')
)
@player.on('play', ->
@paused = false
if CLIENT.leader
sendVideoUpdate()
)
@player.on('pause', ->
@paused = true
if CLIENT.leader
sendVideoUpdate()
)
@player.setVolume(VOLUME * 100)
if not @paused
@player.play()
@ready = true
)
) )
play: ->
@paused = false
if @player and @ready
@player.play()
pause: ->
@paused = true
if @player and @ready
@player.pause()
seekTo: (time) ->
if @player and @ready
@player.setCurrentTime(time)
setVolume: (volume) ->
if @player and @ready
@player.setVolume(volume * 100)
getTime: (cb) ->
if @player and @ready
@player.getCurrentTime(cb)
else
cb(0)
getVolume: (cb) ->
if @player and @ready
@player.getVolume((volume) ->
cb(volume / 100)
)
else
cb(VOLUME)

View File

@ -8,55 +8,48 @@ window.PlayerJSPlayer = class PlayerJSPlayer extends Player
load: (data) -> load: (data) ->
@setMediaProperties(data) @setMediaProperties(data)
@ready = false @ready = false
@finishing = false
if not data.meta.playerjs if not data.meta.playerjs
throw new Error('Invalid input: missing meta.playerjs') throw new Error('Invalid input: missing meta.playerjs')
waitUntilDefined(window, 'playerjs', => waitUntilDefined(window, 'playerjs', =>
iframe = $('<iframe/>') iframe = $('<iframe/>')
.attr(src: data.meta.playerjs.src) .attr(
src: data.meta.playerjs.src
allow: 'autoplay; fullscreen'
)
removeOld(iframe) removeOld(iframe)
@setupPlayer(iframe[0])
)
@player = new playerjs.Player(iframe[0]) setupPlayer: (iframe) ->
@player.on('ready', => @player = new playerjs.Player(iframe)
@player.on('error', (error) => @player.on('ready', =>
console.error('PlayerJS error', error.stack) @player.on('error', (error) =>
) console.error('PlayerJS error', error.stack)
@player.on('ended', ->
# Streamable seems to not implement this since it loops
# gotta use the timeupdate hack below
if CLIENT.leader
socket.emit('playNext')
)
@player.on('timeupdate', (time) =>
if time.duration - time.seconds < 1 and not @finishing
setTimeout(=>
if CLIENT.leader
socket.emit('playNext')
@pause()
, (time.duration - time.seconds) * 1000)
@finishing = true
)
@player.on('play', ->
@paused = false
if CLIENT.leader
sendVideoUpdate()
)
@player.on('pause', ->
@paused = true
if CLIENT.leader
sendVideoUpdate()
)
@player.setVolume(VOLUME * 100)
if not @paused
@player.play()
@ready = true
) )
@player.on('ended', ->
if CLIENT.leader
socket.emit('playNext')
)
@player.on('play', ->
@paused = false
if CLIENT.leader
sendVideoUpdate()
)
@player.on('pause', ->
@paused = true
if CLIENT.leader
sendVideoUpdate()
)
@player.setVolume(VOLUME * 100)
if not @paused
@player.play()
@ready = true
) )
play: -> play: ->

View File

@ -6,7 +6,30 @@ window.StreamablePlayer = class StreamablePlayer extends PlayerJSPlayer
super(data) super(data)
load: (data) -> load: (data) ->
data.meta.playerjs = @ready = false
src: "https://streamable.com/e/#{data.id}" @finishing = false
@setMediaProperties(data)
super(data) waitUntilDefined(window, 'playerjs', =>
iframe = $('<iframe/>')
.attr(
src: "https://streamable.com/e/#{data.id}"
allow: 'autoplay; fullscreen'
)
removeOld(iframe)
@setupPlayer(iframe[0])
@player.on('ready', =>
# Streamable does not implement ended event since it loops
# gotta use a timeupdate hack
@player.on('timeupdate', (time) =>
if time.duration - time.seconds < 1 and not @finishing
setTimeout(=>
if CLIENT.leader
socket.emit('playNext')
@pause()
, (time.duration - time.seconds) * 1000)
@finishing = true
)
)
)