Add hitbox and update mixed content errors

This commit is contained in:
calzoneman 2015-06-21 10:27:51 -04:00
parent b279a41122
commit 8dd3280305
5 changed files with 90 additions and 41 deletions

View file

@ -1,3 +1,10 @@
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 = (name, value) ->
$('<param/>').attr(
name: name
@ -38,9 +45,19 @@ window.CustomEmbedPlayer = class CustomEmbedPlayer extends Player
return object
loadIframe: (embed) ->
iframe = $('<iframe/>').attr(
src: embed.src
frameborder: '0'
)
if embed.src.indexOf('http:') == 0 and location.protocol == 'https:'
if embed.mixedContentError?
error = embed.mixedContentError
else
error = DEFAULT_ERROR
alert = makeAlert('Mixed Content Error', error, 'alert-danger')
.removeClass('col-md-12')
alert.find('.close').remove()
return alert
else
iframe = $('<iframe/>').attr(
src: embed.src
frameborder: '0'
)
return iframe
return iframe

View file

@ -1,28 +0,0 @@
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'))

20
player/hitbox.coffee Normal file
View file

@ -0,0 +1,20 @@
HITBOX_ERROR = 'Hitbox.tv only serves its content over plain HTTP, but you are
viewing this page over secure HTTPS. Your browser therefore blocks the
hitbox embed due to mixed content policy. In order to view hitbox, you must
view this page over plain HTTP (change "https://" to "http://" in the address
bar)-- your websocket will still be connected using secure HTTPS. This is
something I have asked Hitbox to fix but they have not done so yet.'
window.HitboxPlayer = class HitboxPlayer extends CustomEmbedPlayer
constructor: (data) ->
if not (this instanceof HitboxPlayer)
return new HitboxPlayer(data)
@load(data)
load: (data) ->
data.meta.embed =
src: "http://hitbox.tv/embed/#{data.id}"
tag: 'iframe'
mixedContentError: HITBOX_ERROR
super(data)

View file

@ -9,6 +9,7 @@ TYPE_MAP =
tw: TwitchPlayer
cu: CustomEmbedPlayer
rt: RTMPPlayer
hb: HitboxPlayer
window.loadMediaPlayer = (data) ->
if data.type of TYPE_MAP

View file

@ -1,5 +1,5 @@
(function() {
var CustomEmbedPlayer, DailymotionPlayer, LivestreamPlayer, Player, RTMPPlayer, SoundCloudPlayer, TYPE_MAP, TwitchPlayer, VideoJSPlayer, VimeoPlayer, YouTubePlayer, genParam, sortSources,
var CustomEmbedPlayer, DEFAULT_ERROR, DailymotionPlayer, HITBOX_ERROR, HitboxPlayer, LivestreamPlayer, Player, RTMPPlayer, SoundCloudPlayer, TYPE_MAP, TwitchPlayer, VideoJSPlayer, VimeoPlayer, YouTubePlayer, genParam, sortSources,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
@ -786,6 +786,8 @@
})(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) {
return $('<param/>').attr({
name: name,
@ -835,12 +837,23 @@
};
CustomEmbedPlayer.prototype.loadIframe = function(embed) {
var iframe;
iframe = $('<iframe/>').attr({
src: embed.src,
frameborder: '0'
});
return iframe;
var alert, error, iframe;
if (embed.src.indexOf('http:') === 0 && location.protocol === 'https:') {
if (embed.mixedContentError != null) {
error = embed.mixedContentError;
} else {
error = DEFAULT_ERROR;
}
alert = makeAlert('Mixed Content Error', error, 'alert-danger').removeClass('col-md-12');
alert.find('.close').remove();
return alert;
} else {
iframe = $('<iframe/>').attr({
src: embed.src,
frameborder: '0'
});
return iframe;
}
};
return CustomEmbedPlayer;
@ -883,6 +896,31 @@
})(CustomEmbedPlayer);
HITBOX_ERROR = 'Hitbox.tv only serves its content over plain HTTP, but you are viewing this page over secure HTTPS. Your browser therefore blocks the hitbox embed due to mixed content policy. In order to view hitbox, you must view this page over plain HTTP (change "https://" to "http://" in the address bar)-- your websocket will still be connected using secure HTTPS. This is something I have asked Hitbox to fix but they have not done so yet.';
window.HitboxPlayer = HitboxPlayer = (function(superClass) {
extend(HitboxPlayer, superClass);
function HitboxPlayer(data) {
if (!(this instanceof HitboxPlayer)) {
return new HitboxPlayer(data);
}
this.load(data);
}
HitboxPlayer.prototype.load = function(data) {
data.meta.embed = {
src: "http://hitbox.tv/embed/" + data.id,
tag: 'iframe',
mixedContentError: HITBOX_ERROR
};
return HitboxPlayer.__super__.load.call(this, data);
};
return HitboxPlayer;
})(CustomEmbedPlayer);
TYPE_MAP = {
yt: YouTubePlayer,
vi: VimeoPlayer,
@ -893,7 +931,8 @@
li: LivestreamPlayer,
tw: TwitchPlayer,
cu: CustomEmbedPlayer,
rt: RTMPPlayer
rt: RTMPPlayer,
hb: HitboxPlayer
};
window.loadMediaPlayer = function(data) {