"use strict";function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}();__define("pages/embeds/twitch-embed",["lib/tp/twitch-api","lib/tp/superagent","lib/tp/superagent-deps/emitter","lib/tp/superagent-deps/reduce","lib/promise","lib/da/ddt","lib/dom/sigil","lib/data/extend","lib/data/meta","pageload","lib/da/vms","lib/da/deviantart-object","lib/data/init","lib/da/legacy-difi-bridge","lib/tp/eventemitter3"],function(a,b,c,d){var e=a("lib/tp/twitch-api"),f=a("lib/dom/sigil"),g=a("lib/data/extend"),h=a("lib/data/meta"),i=a("lib/da/legacy-difi-bridge"),j=function(){function a(b){var c=this;_classCallCheck(this,a),h.getCachedMetadata(),this.containerNode=b,this.options=h.getGlobal(this.containerNode),this.twitch=new e(this.options.clientId),this.determinePlayerOptions().then(function(a){a.channel&&a.video&&delete a.channel,c.twitch.createPlayer(c.containerNode,a),c.options.chat&&c.twitch.createChat(c.containerNode,a)})}return _createClass(a,[{key:"determinePlayerOptions",value:function(){var a=this;return this.options.video?Promise.resolve(g(this.options)):this.options.channel?this.getLiveStream(this.options.channel).then(function(b){return b?b:a.getLatestRecording(a.options.channel)}).then(function(b){return b||(b={}),g(a.options,b)}):void 0}},{key:"getLiveStream",value:function(a){return this.twitch.api({url:"streams/"+a}).then(function(a){return a&&a.stream?{channel:a.stream.channel.name}:null})}},{key:"getLatestRecording",value:function(a){return this.twitch.api({url:"channels/"+a+"/videos",params:{broadcasts:!0,limit:1,offset:0}}).then(function(a){return a&&a.videos&&a.videos.length>0?{video:a.videos[0]._id}:null})}}]),a}(),k=[],l=function(){f.find("twitch-embed").forEach(function(a){for(var b in k)if(k[b].node==a)return;k.push({widget:new j(a),node:a})})};i.on("assets.woken",l),l()});