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',
'gdrive-player.coffee',
'raw-file.coffee',
'soundcloud.coffee',
'embed.coffee',
'twitch.coffee',
'livestream.com.coffee',
'custom-embed.coffee',
'rtmp.coffee',
'hls.coffee',
'twitchclip.coffee',
'peertube.coffee',
'iframechild.coffee', 'iframechild.coffee',
'odysee.coffee', 'odysee.coffee',
'streamable.coffee',
'embed.coffee',
'custom-embed.coffee',
'livestream.com.coffee',
'twitchclip.coffee',
'videojs.coffee',
'gdrive-player.coffee',
'hls.coffee',
'raw-file.coffee',
'rtmp.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) setupFrame: (iframe, data) ->
if not @paused
@player.play()
@ready = true
)
)
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,37 +8,31 @@ 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 = new playerjs.Player(iframe)
@player.on('ready', => @player.on('ready', =>
@player.on('error', (error) => @player.on('error', (error) =>
console.error('PlayerJS error', error.stack) console.error('PlayerJS error', error.stack)
) )
@player.on('ended', -> @player.on('ended', ->
# Streamable seems to not implement this since it loops
# gotta use the timeupdate hack below
if CLIENT.leader if CLIENT.leader
socket.emit('playNext') 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', -> @player.on('play', ->
@paused = false @paused = false
if CLIENT.leader if CLIENT.leader
@ -57,7 +51,6 @@ window.PlayerJSPlayer = class PlayerJSPlayer extends Player
@ready = true @ready = true
) )
)
play: -> play: ->
@paused = false @paused = false

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
)
)
)