mirror of https://github.com/calzoneman/sync.git
Remove redundancy by extending EmbedPlayer for Twitch
This commit is contained in:
parent
aad8eef52b
commit
44f1091952
|
@ -10,8 +10,8 @@ var order = [
|
||||||
'videojs.coffee',
|
'videojs.coffee',
|
||||||
'raw-file.coffee',
|
'raw-file.coffee',
|
||||||
'soundcloud.coffee',
|
'soundcloud.coffee',
|
||||||
'twitch.coffee',
|
|
||||||
'embed.coffee',
|
'embed.coffee',
|
||||||
|
'twitch.coffee',
|
||||||
'livestream.com.coffee',
|
'livestream.com.coffee',
|
||||||
'custom-embed.coffee',
|
'custom-embed.coffee',
|
||||||
'rtmp.coffee',
|
'rtmp.coffee',
|
||||||
|
|
|
@ -8,7 +8,7 @@ window.twitchEventCallback = (events) ->
|
||||||
PLAYER.twitch.ready = true
|
PLAYER.twitch.ready = true
|
||||||
)
|
)
|
||||||
|
|
||||||
window.TwitchPlayer = class TwitchPlayer extends Player
|
window.TwitchPlayer = class TwitchPlayer extends EmbedPlayer
|
||||||
constructor: (data) ->
|
constructor: (data) ->
|
||||||
if not (this instanceof TwitchPlayer)
|
if not (this instanceof TwitchPlayer)
|
||||||
return new TwitchPlayer(data)
|
return new TwitchPlayer(data)
|
||||||
|
@ -16,35 +16,14 @@ window.TwitchPlayer = class TwitchPlayer extends Player
|
||||||
@load(data)
|
@load(data)
|
||||||
|
|
||||||
load: (data) ->
|
load: (data) ->
|
||||||
@setMediaProperties(data)
|
data.meta.embed =
|
||||||
|
src: '//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf'
|
||||||
object = $('<object/>').attr(
|
tag: 'object'
|
||||||
# NOTE: Must be protocol-relative or else flash throws errors when
|
params:
|
||||||
# you try to call API functions.
|
flashvars: "embed=1&\
|
||||||
data: '//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf'
|
hostname=localhost&\
|
||||||
type: 'application/x-shockwave-flash'
|
channel=#{data.id}&
|
||||||
)
|
eventsCallback=twitchEventCallback&\
|
||||||
$('<param/>').attr(
|
auto_play=true&\
|
||||||
name: 'allowScriptAccess'
|
start_volume=#{Math.floor(VOLUME * 100)}"
|
||||||
value: 'always'
|
super(data)
|
||||||
).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]
|
|
||||||
|
|
|
@ -794,55 +794,6 @@
|
||||||
|
|
||||||
})(Player);
|
})(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).';
|
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) {
|
genParam = function(name, value) {
|
||||||
|
@ -918,6 +869,43 @@
|
||||||
|
|
||||||
})(Player);
|
})(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) {
|
window.LivestreamPlayer = LivestreamPlayer = (function(superClass) {
|
||||||
extend(LivestreamPlayer, superClass);
|
extend(LivestreamPlayer, superClass);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue