forked from Wavestreaming/jquery-shoutcast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.shoutcast.easy.min.js
2 lines (2 loc) · 2.96 KB
/
jquery.shoutcast.easy.min.js
1
2
/* Wavestreaming.com - https://github.com/Wavestreaming/jquery-shoutcast - MIT licensed */
(function(e){"use strict";function t(e){this._attr={},this.playedInterval=e.playedInterval||e.interval||3e4,this.statsInterval=e.statsInterval||e.interval||5e3,this.host=e.host,this.port=parseInt(e.port,10)||8e3,this.stream=parseInt(e.stream,10)||1,this._statsinterval=null,this._playedinterval=null,this._stats=e.stats||function(){},this._played=e.played||function(){}}t.prototype.get=function(e,t){return e?typeof this._attr[e.toLowerCase()]!="undefined"?this._attr[e.toLowerCase()]:t:this._attr},t.prototype.stats=function(t){var n=this,r,i="http://"+this.host+":"+this.port+"/stats?sid="+this.stream+"&json=1";return t=t||function(){},r=e.ajax({url:i,dataType:"jsonp",timeout:"2000"}),r.success(function(e){if(typeof e!="object"||typeof e.streamstatus=="undefined"){n._status=0;return}n._status=e.streamstatus===1?2:1,n._attr=e,n._attr.status=n.getStatusAsText(),t.call(n,n._attr),n._stats(n._attr)}),r.error(function(){n._status=0,n._attr.status=n.getStatusAsText(),t.call(n,n._attr),n.stats(n._attr)}),this},t.prototype.played=function(t){var n=this,r="http://"+this.host+":"+this.port+"/played?sid="+this.stream+"&type=json";return e.ajax({url:r,dataType:"jsonp",timeout:2e3,success:function(e){if(!e instanceof Array)return;t&&t.call(n,e),n._played(e)}}),this},t.prototype.startStats=function(){return this.stopStats(),this.stats(),this._statsinterval=setInterval(e.proxy(this.stats,this),this.statsInterval),this},t.prototype.stopStats=function(){return this._statsinterval&&clearInterval(this._statsinterval),this},t.prototype.startPlayed=function(){return this.stopPlayed(),this.played(),this._playedinterval=setInterval(e.proxy(this.played,this),this.playedInterval),this},t.prototype.stopPlayed=function(){return this._playedinterval&&clearInterval(this._playedinterval),this},t.prototype.getStatus=function(){return this._status},t.prototype.getStatusAsText=function(){return["Offline","Awaiting Connection","On Air"][this._status]},t.prototype.onAir=function(){return this._status===2},e.SHOUTcast=function(e){return new t(e)}})(window.jQuery),function(e,t){"use strict";var n={},r={},i=!1,s=!1,o,u=t("script").last();(function(){var e=u.attr("src"),r=e.replace(/.*\?/,"");if(r===e)return;t.each(r.split("&"),function(e,t){t=t.split("="),t.length===2&&(n[t[0]]=t[1])})})();if(!n.host)return;n.value&&function(){n.value==="played"?u.after('<ul id="played"></ul>'):u.after('<p data-shoutcast-value="'+n.value+'"></p>')}(),n.playedInterval=n.playedInterval||3e4,n.statsInterval=n.statsInterval||5e3,t("[data-shoutcast-value]").each(function(e,n){n=t(n),r[n.data("shoutcast-value")]=n}),i=!t.isEmptyObject(r),o=t("#played"),s=!!o.length,i&&(n.stats=function(){var e;for(e in r)r.hasOwnProperty(e)&&r[e].text(this.get(e))}),s&&(n.played=function(e){var n="";t.each(e,function(e,t){n+="<li>"+t.title+"</li>"}),o.html(n)}),e.SHOUTcast=t.SHOUTcast(n),i&&e.SHOUTcast.startStats(),s&&e.SHOUTcast.startPlayed()}(window,window.jQuery);