CyTube/player/iframechild.coffee

34 lines
1.3 KiB
CoffeeScript
Raw Normal View History

2022-01-28 15:18:10 +00:00
window.IframeChild = class IframeChild extends PlayerJSPlayer
constructor: (data) ->
2022-01-27 04:33:59 +00:00
if not (this instanceof IframeChild)
return new IframeChild(data)
2022-01-28 15:18:10 +00:00
super(data)
load: (data) ->
@setMediaProperties(data)
@ready = false
waitUntilDefined(window, 'playerjs', =>
iframe = $('<iframe/>')
.attr(
src: '/iframe'
allow: 'autoplay; fullscreen'
)
removeOld(iframe)
2022-01-28 15:18:10 +00:00
@setupFrame(iframe[0], data)
@setupPlayer(iframe[0])
)
2022-01-28 15:18:10 +00:00
setupFrame: (iframe, data) ->
iframe.addEventListener('load', =>
2022-08-29 00:08:28 +00:00
# TODO: ideally, communication with the child frame should use postMessage()
iframe.contentWindow.VOLUME = VOLUME
iframe.contentWindow.loadMediaPlayer(Object.assign({}, data, { type: 'cm' } ))
2022-01-30 20:55:25 +00:00
iframe.contentWindow.document.querySelector('#ytapiplayer').classList.add('vjs-16-9')
adapter = iframe.contentWindow.playerjs.VideoJSAdapter(iframe.contentWindow.PLAYER.player)
adapter.ready()
2022-01-27 04:33:59 +00:00
typeof data?.meta?.thumbnail == 'string' and iframe.contentWindow.PLAYER.player.poster(data.meta.thumbnail)
)