Work on custom embeds

This commit is contained in:
calzoneman 2015-06-18 18:46:33 -04:00
parent 60743bd2ea
commit 01fbd3c54e
7 changed files with 239 additions and 18 deletions

View file

@ -0,0 +1,46 @@
genParam = (name, value) ->
$('<param/>').attr(
name: name
value: value
)
window.CustomEmbedPlayer = class CustomEmbedPlayer extends Player
constructor: (data) ->
if not (this instanceof CustomEmbedPlayer)
return new CustomEmbedPlayer(data)
@load(data)
load: (data) ->
embed = data.meta.embed
if not embed?
console.error('CustomEmbedPlayer::load(): missing meta.embed')
return
if embed.tag == 'object'
@player = @loadObject(embed)
else
@player = @loadIframe(embed)
removeOld(@player)
loadObject: (embed) ->
object = $('<object/>').attr(
type: 'application/x-shockwave-flash'
data: embed.src
)
genParam('allowfullscreen', 'true').appendTo(object)
genParam('allowscriptaccess', 'always').appendTo(object)
for key, value of embed.params
genParam(key, value).appendTo(object)
return object
loadIframe: (embed) ->
iframe = $('<iframe/>').attr(
src: embed.src
frameborder: '0'
)
return iframe

View file

@ -0,0 +1,28 @@
DEFAULT_WARNING = 'You are currently connected via HTTPS but the embedded video
link uses non-secure plain HTTP. Your browser may therefore block it from
loading due to mixed content policy. To fix this, embed the video using a
secure link if available (https://...), or load this page over plain HTTP by
replacing "https://" with "http://" in the address bar (your websocket will
still be secured using HTTPS, but this will permit non-secure content to load).'
window.GenericIframePlayer = class GenericIframePlayer extends Player
constructor: (data, iframeSrc, customMixedContentWarning) ->
if not (this instanceof GenericIframePlayer)
return new GenericIframePlayer(data, iframeSrc, customMixedContentWarning)
load: (data, iframeSrc, customMixedContentWarning) ->
@setMediaProperties(data)
@player = $('<iframe/>').attr(
src: iframeSrc
frameborder: '0'
)
removeOld(@player)
if iframeSrc.indexOf('http:') == 0
if customMixedContentWarning
warning = customMixedContentWarning
else
warning = DEFAULT_WARNING
makeAlert('Mixed Content Warning', warning).appendTo($('#videowrap'))

View file

@ -7,6 +7,7 @@ TYPE_MAP =
sc: SoundCloudPlayer
li: LivestreamPlayer
tw: TwitchPlayer
cu: CustomEmbedPlayer
window.loadMediaPlayer = (data) ->
if data.type of TYPE_MAP