diff --git a/build-player.js b/build-player.js index 5756f1de..0e82b334 100644 --- a/build-player.js +++ b/build-player.js @@ -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', diff --git a/player/twitch.coffee b/player/twitch.coffee index 57419ec5..120dcbca 100644 --- a/player/twitch.coffee +++ b/player/twitch.coffee @@ -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 = $('').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' - ) - $('').attr( - name: 'allowScriptAccess' - value: 'always' - ).appendTo(object) - $('').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. - $('').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) diff --git a/www/js/player.js b/www/js/player.js index 004aad5e..3175ffb0 100644 --- a/www/js/player.js +++ b/www/js/player.js @@ -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 = $('').attr({ - data: '//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf', - type: 'application/x-shockwave-flash' - }); - $('').attr({ - name: 'allowScriptAccess', - value: 'always' - }).appendTo(object); - $('').attr({ - name: 'allowFullScreen', - value: 'true' - }).appendTo(object); - $('').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);