Remove redundancy by extending EmbedPlayer for Twitch

This commit is contained in:
Calvin Montgomery 2015-07-05 14:04:21 -07:00
parent aad8eef52b
commit 44f1091952
3 changed files with 50 additions and 83 deletions

View File

@ -10,8 +10,8 @@ var order = [
'videojs.coffee',
'raw-file.coffee',
'soundcloud.coffee',
'twitch.coffee',
'embed.coffee',
'twitch.coffee',
'livestream.com.coffee',
'custom-embed.coffee',
'rtmp.coffee',

View File

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

View File

@ -794,55 +794,6 @@
})(Player);
window.twitchEventCallback = function(events) {
if (!(PLAYER instanceof TwitchPlayer)) {
return false;
}
return events.forEach(function(event) {
if (event.event === 'playerInit') {
PLAYER.twitch.unmute();
return PLAYER.twitch.ready = true;
}
});
};
window.TwitchPlayer = TwitchPlayer = (function(superClass) {
extend(TwitchPlayer, superClass);
function TwitchPlayer(data) {
if (!(this instanceof TwitchPlayer)) {
return new TwitchPlayer(data);
}
this.load(data);
}
TwitchPlayer.prototype.load = function(data) {
var object;
this.setMediaProperties(data);
object = $('<object/>').attr({
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);
$('<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);
return this.twitch = object[0];
};
return TwitchPlayer;
})(Player);
DEFAULT_ERROR = 'You are currently connected via HTTPS but the embedded content uses non-secure plain HTTP. Your browser therefore blocks 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).';
genParam = function(name, value) {
@ -918,6 +869,43 @@
})(Player);
window.twitchEventCallback = function(events) {
if (!(PLAYER instanceof TwitchPlayer)) {
return false;
}
return events.forEach(function(event) {
if (event.event === 'playerInit') {
PLAYER.twitch.unmute();
return PLAYER.twitch.ready = true;
}
});
};
window.TwitchPlayer = TwitchPlayer = (function(superClass) {
extend(TwitchPlayer, superClass);
function TwitchPlayer(data) {
if (!(this instanceof TwitchPlayer)) {
return new TwitchPlayer(data);
}
this.load(data);
}
TwitchPlayer.prototype.load = function(data) {
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))
}
};
return TwitchPlayer.__super__.load.call(this, data);
};
return TwitchPlayer;
})(EmbedPlayer);
window.LivestreamPlayer = LivestreamPlayer = (function(superClass) {
extend(LivestreamPlayer, superClass);