forked from Wavestreaming/jquery-shoutcast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.shoutcast.min.js
2 lines (2 loc) · 2.1 KB
/
jquery.shoutcast.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);