Remove redundancy by extending EmbedPlayer for Twitch
This commit is contained in:
parent
aad8eef52b
commit
44f1091952
3 changed files with 50 additions and 83 deletions
|
|
@ -8,7 +8,7 @@ window.twitchEventCallback = (events) ->
|
|||
PLAYER.twitch.ready = true
|
||||
)
|
||||
|
||||
window.TwitchPlayer = class TwitchPlayer extends Player
|
||||
window.TwitchPlayer = class TwitchPlayer extends EmbedPlayer
|
||||
constructor: (data) ->
|
||||
if not (this instanceof TwitchPlayer)
|
||||
return new TwitchPlayer(data)
|
||||
|
|
@ -16,35 +16,14 @@ window.TwitchPlayer = class TwitchPlayer extends Player
|
|||
@load(data)
|
||||
|
||||
load: (data) ->
|
||||
@setMediaProperties(data)
|
||||
|
||||
object = $('<object/>').attr(
|
||||
# NOTE: Must be protocol-relative or else flash throws errors when
|
||||
# you try to call API functions.
|
||||
data: '//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf'
|
||||
type: 'application/x-shockwave-flash'
|
||||
)
|
||||
$('<param/>').attr(
|
||||
name: 'allowScriptAccess'
|
||||
value: 'always'
|
||||
).appendTo(object)
|
||||
$('<param/>').attr(
|
||||
name: 'allowFullScreen'
|
||||
value: 'true'
|
||||
).appendTo(object)
|
||||
# NOTE: start_volume can be used to set the initial player volume,
|
||||
# however it is impossible to manipulate or query it from the player
|
||||
# later.
|
||||
$('<param/>').attr(
|
||||
name: 'flashvars'
|
||||
value: "embed=1&\
|
||||
hostname=localhost&\
|
||||
channel=#{data.id}&
|
||||
eventsCallback=twitchEventCallback&\
|
||||
auto_play=true&\
|
||||
start_volume=#{Math.floor(VOLUME * 100)}"
|
||||
).appendTo(object)
|
||||
|
||||
removeOld(object)
|
||||
|
||||
@twitch = object[0]
|
||||
data.meta.embed =
|
||||
src: '//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf'
|
||||
tag: 'object'
|
||||
params:
|
||||
flashvars: "embed=1&\
|
||||
hostname=localhost&\
|
||||
channel=#{data.id}&
|
||||
eventsCallback=twitchEventCallback&\
|
||||
auto_play=true&\
|
||||
start_volume=#{Math.floor(VOLUME * 100)}"
|
||||
super(data)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue